From be977e844a0f5548e50afb552f3d8e4a93b23050 Mon Sep 17 00:00:00 2001 From: Felix Date: Sun, 9 Feb 2020 16:36:34 +0100 Subject: [PATCH] update to multiple jobs --- .circleci/config.yml | 236 +++++++++++++++++++++++++++++++---------- .circleci/setup_env.sh | 13 ++- 2 files changed, 188 insertions(+), 61 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 784dc485..6e50120f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,98 +1,191 @@ -version: 2 -jobs: - build: - working_directory: ~/code +version: 2.0 + +references: + + workspace_root: &workspace_root + ~/code + + container_config: &container_config docker: - image: circleci/android:api-28 + + working_directory: *workspace_root + environment: +# TERM: dumb JVM_OPTS: -XX\:MaxHeapSize\=2048m -Xmx1536m LIBS: NoFree BUILD_TYPE: Release APPCENTER_OWNER: nicidienase APPCENTER_GROUP: "Collaborators" RELEASENOTES_FILE: "release_notes.txt" - branches: - only: - - master - - develop - - /feature\/.*/ + + attach_workspace: &attach_workspace + attach_workspace: + at: *workspace_root + + general_cache_key: &general_cache_key + key: app-{{ checksum ".circleci/config.yml" }}-{{ checksum "gradle.properties" }}-{{ checksum "build.gradle" }}-{{ checksum "touch/build.gradle" }}-{{ checksum "leanback/build.gradle" }}-{{ checksum "common/build.gradle" }}-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }} + +jobs: + + build: + <<: *container_config steps: - checkout + - restore_cache: - key: jars-{{ checksum "build.gradle" }}-{{ checksum "touch/build.gradle" }}-{{ checksum "leanback/build.gradle" }}-{{ checksum "common/build.gradle" }} + <<: *general_cache_key - run: - name: Setup env + name: Setup environment command: | .circleci/setup_env.sh >> $BASH_ENV echo "VERSION_CODE_TOUCH=$(.circleci/getVersionCode.sh -t)" >> $BASH_ENV echo "VERSION_CODE_LEANBACK=$(.circleci/getVersionCode.sh -l)" >> $BASH_ENV -# . $BASH_ENV -# echo "STAGE=${STAGE}" -# echo "VERSION_NAME=${VERSION_NAME}" -# echo "VersionCode: $(.circleci/getVersionCode.sh -t)" -# echo "BUILD_TYPE_LOWER=${BUILD_TYPE_LOWER}" -# echo "STAGE_LOWER=${STAGE_LOWER}" -# echo "LIBS_LOWER=${LIBS_LOWER}" + - run: name: Download Dependencies - command: ./gradlew $SIGN_CONFIG androidDependencies - - run: - name: ktlint command: | - ./gradlew $SIGN_CONFIG --continue \ - common:ktlint${STAGE}${LIBS}${BUILD_TYPE}Check \ - touch:ktlint${STAGE}${LIBS}${BUILD_TYPE}Check \ - leanback:ktlint${STAGE}${LIBS}${BUILD_TYPE}Check + ./gradlew $KEY_CONFIG $SIGN_CONFIG \ + -PversionCode=$VERSION_CODE_TOUCH \ + -PversionName=${VERSION_NAME} \ + androidDependencies + - run: name: Build Touch command: | - ./gradlew $SIGN_CONFIG \ + ./gradlew $SIGN_CONFIG $KEY_CONFIG \ -PversionCode=$VERSION_CODE_TOUCH \ -PversionName=${VERSION_NAME} \ touch:assemble${STAGE_LOWER}${LIBS}${BUILD_TYPE} - - run: - name: Build Leanback - command: | - ./gradlew $SIGN_CONFIG \ - -PversionCode=$VERSION_CODE_LEANBACK \ - -PversionName=${VERSION_NAME} \ - leanback:assemble${STAGE_LOWER}${LIBS}${BUILD_TYPE} - - run: - name: Test - command: | - ./gradlew $SIGN_CONFIG --continue \ - common:test${STAGE}${LIBS}${BUILD_TYPE}UnitTest \ - common:lint${STAGE}${LIBS}${BUILD_TYPE} \ - touch:test${STAGE}${LIBS}${BUILD_TYPE}UnitTest \ - touch:lint${STAGE}${LIBS}${BUILD_TYPE} \ - leanback:test${STAGE}${LIBS}${BUILD_TYPE}UnitTest \ - leanback:lint${STAGE}${LIBS}${BUILD_TYPE} - - store_artifacts: - path: common/build/outputs - destination: common-reports - store_artifacts: path: touch/build/outputs destination: touch - - store_artifacts: - path: touch/build/outputs - destination: touch-reports + + - run: + name: Build Leanback + command: | + ./gradlew $KEY_CONFIG $SIGN_CONFIG \ + -PversionCode=$VERSION_CODE_LEANBACK \ + -PversionName=${VERSION_NAME} \ + leanback:assemble${STAGE_LOWER}${LIBS}${BUILD_TYPE} - store_artifacts: path: leanback/build/outputs destination: leanback + + - save_cache: + <<: *general_cache_key + paths: + - "~/.gradle" + - "~/.m2" + - "/opt/android-sdk-linux/licenses/" + + - persist_to_workspace: + root: *workspace_root + paths: + - . + + check: + <<: *container_config + steps: + - *attach_workspace + + - restore_cache: + <<: *general_cache_key + + - run: + name: Setup environment + command: | + .circleci/setup_env.sh >> $BASH_ENV + echo "VERSION_CODE_TOUCH=$(.circleci/getVersionCode.sh -t)" >> $BASH_ENV + echo "VERSION_CODE_LEANBACK=$(.circleci/getVersionCode.sh -l)" >> $BASH_ENV + + - run: + name: Run checks + command: | + ./gradlew $KEY_CONFIG \ + -PversionCode=$VERSION_CODE_LEANBACK \ + -PversionName=${VERSION_NAME} \ + lint ktlintCheck + + - store_artifacts: + path: app/build/reports/ + destination: lint_reports/app/ + + test: + <<: *container_config + steps: + - *attach_workspace + + - restore_cache: + <<: *general_cache_key + + - run: + name: Setup environment + command: | + .circleci/setup_env.sh >> $BASH_ENV + echo "VERSION_CODE_TOUCH=$(.circleci/getVersionCode.sh -t)" >> $BASH_ENV + echo "VERSION_CODE_LEANBACK=$(.circleci/getVersionCode.sh -l)" >> $BASH_ENV + + - run: + name: Env + command: cat $BASH_ENV + + - run: + name: Test Common + command: | + ./gradlew $KEY_CONFIG common:test${STAGE}${LIBS}${BUILD_TYPE}UnitTest + + - run: + name: Test Touch + command: | + ./gradlew $KEY_CONFIG \ + -PversionCode=$VERSION_CODE_TOUCH \ + -PversionName=${VERSION_NAME} \ + touch:test${STAGE}${LIBS}${BUILD_TYPE}UnitTest + + - run: + name: Test Leanback + command: | + ./gradlew $KEY_CONFIG \ + -PversionCode=$VERSION_CODE_LEANBACK \ + -PversionName=${VERSION_NAME} \ + leanback:test${STAGE}${LIBS}${BUILD_TYPE}UnitTest \ + + - store_artifacts: + path: touch/build/reports + destination: touch-reports - store_artifacts: path: leanback/build/reports destination: leanback-reports - store_artifacts: - path: common/build/reports/ktlint/ - destination: ktlint-reports + path: leanback/build/reports + destination: leanback-reports - store_test_results: path: common/build/test-results - store_test_results: path: touch/build/test-results - store_test_results: path: leanback/build/test-results + + publish: + <<: *container_config + steps: + - *attach_workspace + + - restore_cache: + <<: *general_cache_key + - run: - name: Appcenter Upload + name: Setup environment + command: .circleci/setup_env.sh >> $BASH_ENV + + - run: + name: Touch Appcenter Upload + branches: + only: + - master + - develop command: | git log --format="%h %s" master..HEAD > $RELEASENOTES_FILE .circleci/appCenterUpload.sh \ @@ -104,7 +197,38 @@ jobs: "touch/build/outputs/mapping/${STAGE_LOWER}${LIBS}/${BUILD_TYPE_LOWER}/mapping.txt" \ "$VERSION_CODE_TOUCH" \ "$VERSION_NAME" - - save_cache: - paths: - - ~/.gradle - key: jars-{{ checksum "build.gradle" }}-{{ checksum "touch/build.gradle" }}-{{ checksum "leanback/build.gradle" }}-{{ checksum "common/build.gradle" }} + + - run: + name: Leanback Appcenter Upload + branches: + only: + - master + - develop + command: | + git log --format="%h %s" master..HEAD > $RELEASENOTES_FILE + .circleci/appCenterUpload.sh \ + $APPCENTER_OWNER \ + $APPCENTER_TOKEN \ + "leanback/build/outputs/apk/${STAGE_LOWER}${LIBS}/${BUILD_TYPE_LOWER}/touch-${STAGE_LOWER}-${LIBS_LOWER}-${BUILD_TYPE_LOWER}.apk" \ + $RELEASENOTES_FILE \ + $APPCENTER_GROUP \ + "leanback/build/outputs/mapping/${STAGE_LOWER}${LIBS}/${BUILD_TYPE_LOWER}/mapping.txt" \ + "$VERSION_CODE_LEANBACK" \ + "$VERSION_NAME" + +workflows: + version: 2 + + build_test_publish: + jobs: + - build + - check: + requires: + - build + - test: + requires: + - build + - publish: + requires: + - test + - check diff --git a/.circleci/setup_env.sh b/.circleci/setup_env.sh index 887be450..d9b857e4 100755 --- a/.circleci/setup_env.sh +++ b/.circleci/setup_env.sh @@ -15,9 +15,12 @@ echo "export LIBS_LOWER=\"$(tr '[:upper:]' '[:lower:]' <<< ${LIBS:0:1})${LIBS:1} echo "$ENCODED_KEYSTORE" | base64 --decode > ${HOME}/code/keystore.jks KEYSTORE=${HOME}/code/keystore.jks -echo "export SIGN_CONFIG=\"-PchaosflixKeystore=$KEYSTORE\ - -PchaosflixStorePassword=$KEYSTORE_PASSWORD\ - -PchaosflixKeyName=$KEY_NAME\ - -PchaosflixKeyPassword=$KEYSTORE_PASSWORD\ - -PappcenterId=$APPCENTER_ID\ +echo "export KEY_CONFIG=\"-PappcenterId=$APPCENTER_ID\ -PappcenterDevId=$APPCENTER_DEV_ID\"" + +echo "export SIGN_CONFIG=\"-PchaosflixKeystore=$KEYSTORE \ + -PchaosflixStorePassword=$KEYSTORE_PASSWORD \ + -PchaosflixKeyName=$KEY_NAME \ + -PchaosflixKeyPassword=$KEYSTORE_PASSWORD\"" + +env \ No newline at end of file