diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 61c5e2e3a51b03a05d441ce3147f18a95a14c984..62a91128103a7eb96e570dafcd6a93001db9a061 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,127 +1,162 @@ -image: registry.gitlab.e.foundation/e/os/docker-android-apps-cicd:latest - -stages: - - debug - - release - -before_script: - - export GRADLE_USER_HOME=$(pwd)/.gradle - - chmod +x ./gradlew - - -# Debug build related jobs -buildDebug: - stage: debug - script: - - ./gradlew assembleDebug - artifacts: - paths: - - app/build/outputs/apk/debug/ - -test: - allow_failure: true - stage: debug - script: - - ./gradlew test -PtestAccountName="$testAccountName" -PtestAccountPwd="$testAccountPwd" -PtestServerUrl="$testServerUrl" - artifacts: - when: always - paths: - - app/build/test-results/*/TEST-*.xml - - app/build/reports/tests/* - reports: - junit: app/build/test-results/*/TEST-*.xml - -# Default lint configuration for debug builds -# Manual as we don't want to run them generally for debug builds -.lintDebugDefault: - stage: debug - when: manual - allow_failure: true - -lintDebug: - extends: .lintDebugDefault - script: - - ./gradlew lintDebug - artifacts: - paths: - - app/build/reports/ - -ktlintDebug: - extends: .lintDebugDefault - script: - - ./gradlew app:ktlintCheck --info - artifacts: - paths: - - app/build/reports/ktlint/ - -# Release build related jobs - -# Default configuration for release builds -# Only on "master", "merge_request_event" and protected branches -buildRelease: - stage: release - allow_failure: false - rules: - - if: '$CI_PIPELINE_SOURCE == "merge_request_event"' - when: always - - if: '$CI_COMMIT_REF_PROTECTED == "true"' - when: always - - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH' - when: always - script: - - ./gradlew assembleRelease - artifacts: - paths: - - app/build/outputs/apk/release/ - -# Release jobs to generate signed artifacts -.releaseSigned: - stage: release - allow_failure: false - before_script: - - export GRADLE_USER_HOME=$(pwd)/.gradle - - chmod +x ./gradlew - - echo "${KEYSTORE}" | base64 -d > keystore/proprietary.keystore - rules: - - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH' - when: always - - if: '$CI_COMMIT_REF_PROTECTED == "true"' - when: always - -buildReleaseDev: - extends: .releaseSigned - script: - - ./gradlew assembleReleaseDev - artifacts: - paths: - - app/build/outputs/apk/releaseDev/ - -buildReleaseStable: - extends: .releaseSigned - script: - - ./gradlew assembleReleaseStable - artifacts: - paths: - - app/build/outputs/apk/releaseStable/ - -# Default lint configuration for release jobs -.lintReleaseDefault: - stage: release - when: always - allow_failure: false - -lintRelease: - extends: .lintReleaseDefault - script: - - ./gradlew lintRelease - artifacts: - paths: - - app/build/reports/ - -ktlintRelease: - extends: .lintReleaseDefault - script: - - ./gradlew app:ktlintCheck --info - artifacts: - paths: - - app/build/reports/ktlint/ +image: registry.gitlab.e.foundation/e/os/docker-android-apps-cicd:55-workshop-auto-release + +stages: + - debug + - release + - publish + +before_script: + - export GRADLE_USER_HOME=$(pwd)/.gradle + - chmod +x ./gradlew + +# Debug build related jobs +buildDebug: + stage: debug + script: + - ./gradlew assembleDebug + artifacts: + paths: + - app/build/outputs/apk/debug/ + +test: + allow_failure: true + stage: debug + script: + - ./gradlew test -PtestAccountName="$testAccountName" -PtestAccountPwd="$testAccountPwd" -PtestServerUrl="$testServerUrl" + artifacts: + when: always + paths: + - app/build/test-results/*/TEST-*.xml + - app/build/reports/tests/* + reports: + junit: app/build/test-results/*/TEST-*.xml + +# Default lint configuration for debug builds +# Manual as we don't want to run them generally for debug builds +.lintDebugDefault: + stage: debug + when: manual + allow_failure: true + +lintDebug: + extends: .lintDebugDefault + script: + - ./gradlew lintDebug + artifacts: + paths: + - app/build/reports/ + +ktlintDebug: + extends: .lintDebugDefault + script: + - ./gradlew app:ktlintCheck --info + artifacts: + paths: + - app/build/reports/ktlint/ + +# Release build related jobs + +# Default configuration for release builds +# Only on "master", "merge_request_event" and protected branches +buildRelease: + stage: release + allow_failure: false + rules: + - if: '$CI_PIPELINE_SOURCE == "merge_request_event"' + when: always + - if: '$CI_COMMIT_REF_PROTECTED == "true"' + when: always + - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH' + when: always + script: + - ./gradlew assembleRelease + artifacts: + paths: + - app/build/outputs/apk/release/ + +# Release jobs to generate signed artifacts +.releaseSigned: + stage: release + allow_failure: false + before_script: + - export GRADLE_USER_HOME=$(pwd)/.gradle + - chmod +x ./gradlew + - echo "${KEYSTORE}" | base64 -d > keystore/proprietary.keystore + rules: + - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH' + when: always + - if: '$CI_COMMIT_REF_PROTECTED == "true"' + when: always + +buildReleaseDev: + extends: .releaseSigned + script: + - ./gradlew assembleReleaseDev + artifacts: + paths: + - app/build/outputs/apk/releaseDev/ + +buildReleaseStable: + extends: .releaseSigned + script: + - ./gradlew assembleReleaseStable + artifacts: + paths: + - app/build/outputs/apk/releaseStable/ + +# Default lint configuration for release jobs +.lintReleaseDefault: + stage: release + when: always + allow_failure: false + +lintRelease: + extends: .lintReleaseDefault + script: + - ./gradlew lintRelease + artifacts: + paths: + - app/build/reports/ + +ktlintRelease: + extends: .lintReleaseDefault + script: + - ./gradlew app:ktlintCheck --info + artifacts: + paths: + - app/build/reports/ktlint/ + + +pushToPrebuilt: + stage: publish + needs: ["buildRelease"] + when: manual + variables: + NEW_APK_PATH: "app/build/outputs/apk/release/" + before_script: + - 'which ssh-agent || ( apt update -y && apt install openssh-client -y )' + - eval $(ssh-agent -s) + - echo "$SSH_E_ROBOT_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null + - mkdir -p ~/.ssh + - chmod 700 ~/.ssh + - echo "$SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts + - chmod 644 ~/.ssh/known_hosts + - git config user.email "gitlab@e.foundation" + - git config user.name "gitlab" + script: + - NEW_APK_NAME=$(basename ${NEW_APK_PATH}*-release.apk) + - NEW_APK_VERSION=$(awk -F '-' '{print $2}' <<< "$NEW_APK_NAME") + - echo $NEW_APK_NAME + - echo $NEW_APK_VERSION + - git lfs clone git@gitlab.e.foundation:e/os/android_prebuilts_prebuiltapks_lfs.git + - cd android_prebuilts_prebuiltapks_lfs + - rm Apps/*-release.apk + - mv ../${NEW_APK_PATH}/${NEW_APK_NAME} Apps/ + # todo: improve to replace sed command, by a new one based on REGEXP (instead of using line number) + - sed -i "6s/.*/LOCAL_SRC_FILES := ${NEW_APK_NAME}/" Apps/Android.mk + - git add Apps + - git status + - git commit -m "Update Apps Lounge apk to ${NEW_APK_VERSION}\nFrom ${CI_COMMIT_SHA}" + - git push + # Sometimes a single push doesn't do all the job, so we have to push twice + - git push \ No newline at end of file