.gitlab-ci.yml 4.03 KB
Newer Older
Thomas's avatar
CI  
Thomas committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
image: hatsoftwares/mastalab-ci:latest

before_script:
  - export ANDROID_HOME=/opt/android-sdk-linux
  - export PATH=$PATH:/opt/android-sdk-linux/platform-tools/
  - chmod +x gradlew

stages:
  - build-and-test
  - tag
  - toot

.no-upload: &no-upload
  stage: build-and-test
  retry: 2

assembleDebug:
  <<: *no-upload
  cache:
    key: "${CI_COMMIT_TAG}"
    paths:
Thomas's avatar
Debug  
Thomas committed
22 23
      - app/build/outputs/apk/lite/debug/app-lite-debug.apk
      - app/build/outputs/apk/fullLinks/debug/app-fullLinks-debug.apk
Thomas's avatar
CI  
Thomas committed
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
    policy: push
  script:
    - ./gradlew assembleDebug

lintDebug:
  <<: *no-upload
  script:
    - ./gradlew -Pci --console=plain :app:lint -PbuildDir=lint
  except:
    - tags

debugTests:
  <<: *no-upload
  script:
    - ./gradlew -Pci --console=plain :app:test
  except:
    - tags

Thomas's avatar
Thomas committed
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
## PROTECTED VARIABLES TO SET IN GITLAB:
# - GITLAB_API_TOKEN: token you create on Gitlab
# - NC_REMOTE_DIR:    like https://YOUR_NEXTCLOUD/remote.php/dav/files/YOUR_USER/mastalab (no trailing slash)
# - NC_SHARE_URL:     share the folder in Nextcloud with public link and put your public link here (no trailing slash)
# - NC_USER:          nextcloud user
# - NC_PASSWORD:      nextcloud password
## Protect all tags in Gitlab repo settings (do a wildcard, ie '*')
# For now, it uses the assembleDebug builds, you'll need to create a job in build-and-test to create the apks, with only: - tags and add except: - tags to assembleDebug (like in debugTests)
# In it, put something like this to get your signature key file:
# - curl -s --output signature.jsk -u "${NC_USER}:${NC_PASSWORD}" "https://YOUR_NEXTCLOUD/remote.php/dav/files/YOUR_USER/signature.jsk"
putApkOnTags:
  image: hatsoftwares/curl-jq:latest
  stage: tag
  retry: 2
  cache:
    key: "${CI_COMMIT_TAG}"
    paths:
      - app/build/outputs/apk/lite/debug/app-lite-debug.apk
      - app/build/outputs/apk/fullLinks/debug/app-fullLinks-debug.apk
    policy: pull
  script:
    - export PROJECT_API_URL="https://framagit.org/api/v4/projects/${CI_PROJECT_ID}"
    - export DESCRIPTION_URL="${PROJECT_API_URL}/repository/tags/${CI_COMMIT_TAG}"
    - export RELEASE_URL="${DESCRIPTION_URL}/release"
    - export NC_UPLOAD_URL="${NC_REMOTE_DIR}/${CI_COMMIT_TAG}"
    - export NC_DOWNLOAD_URL="${NC_SHARE_URL}/download?path=%2F${CI_COMMIT_TAG}%2F&files="
    - 'export HEADER="Private-Token: ${GITLAB_API_TOKEN}"'
    - export liteUrl="${NC_DOWNLOAD_URL}app-lite-debug.apk"
    - export fullLinksUrl="${NC_DOWNLOAD_URL}app-fullLinks-debug.apk"
    - 'curl -s -u "${NC_USER}:${NC_PASSWORD}" -X MKCOL "${NC_UPLOAD_URL}"'
    - 'curl -s -u "${NC_USER}:${NC_PASSWORD}" -T app/build/outputs/apk/lite/debug/app-lite-debug.apk       "${NC_UPLOAD_URL}/app-lite-debug.apk"'
    - 'curl -s -u "${NC_USER}:${NC_PASSWORD}" -T app/build/outputs/apk/fullLinks/debug/app-fullLinks-debug.apk "${NC_UPLOAD_URL}/app-fullLinks-debug.apk"'
    - export description=$(curl -s --header "${HEADER}" "${DESCRIPTION_URL}" | jq .release.description | sed -e 's@"@@g')
    - if [[ $description == 'null' ]]; then export METHOD="POST"; echo -e "[Get the lite version](${liteUrl})\n\n[Get the full links version](${fullLinksUrl})" > /tmp/text; fi
    - if [[ $description != 'null' ]]; then export METHOD="PUT";  echo -e "${description}\n\n[Get the lite version](${liteUrl})\n\n[Get the full links version](${fullLinksUrl})" > /tmp/text; fi
    - curl -s --request $METHOD --data-urlencode "description@/tmp/text" --header "${HEADER}" "${RELEASE_URL}"
  only:
    - tags

pouet-it:
  image: hatsoftwares/pouet-it-from-ci:latest
  stage: toot
  dependencies:
    - putApkOnTags
  script:
    - cd /opt/pouet-it-from-ci
    # Make the project name first letter uppercase
    - export NC_DOWNLOAD_URL="${NC_SHARE_URL}?path=%2F${CI_COMMIT_TAG}%2F"
    - export project="$(tr '[:lower:]' '[:upper:]' <<< ${CI_PROJECT_NAME:0:1})${CI_PROJECT_NAME:1}"
Thomas's avatar
Thomas committed
91
    - export MESSAGE=$(echo -e "A new release of "'#'"${APP_NAME} is available!""\n${CI_PROJECT_URL}/tags/${CI_COMMIT_TAG}\nYou can download the apks on ${NC_DOWNLOAD_URL}")
Thomas's avatar
Thomas committed
92 93 94
    - if [[ ! -z $HOST ]]; then carton exec ./pouet-it-from-ci.pl; fi
  only:
    - tags
Thomas's avatar
CI  
Thomas committed
95 96