From f8cb5a2fea1eff6a088d384206b1ea0e0e3de240 Mon Sep 17 00:00:00 2001 From: Mark McCracken Date: Thu, 14 Sep 2023 18:44:32 +0100 Subject: [PATCH] Teamcity migration (#2276) * New build workflow for android beta to replace teamcity pipeline * Add build trigger to run on pull request as well * Added environment variable for iTunes connect, which isn't even really needed * Added quotes to secrets for echoing, copied build details from iOS build * Add a debugging step * Fixed with a newline hopefully * escape newline character * push the escape on the right line * Added new secret to auth with google play store * programmatically set build number * Fix syntax error * fix syntax error * fix syntax error * Make the fastlane fetch the last build number form google play store * only using node 14 and saving artifacts * deleted fastnale additional code; added few more line to debug working dir * fix the keystore filename * Simplified android build number calculation Co-authored-by: Julia Branke * Give GITHUB_TOKEN write permissions * Upload apk to internal * Explicitly use Java 11. Also dry run again * Commenting out iOS specific env vars * Try to fix syntax error * ANDROID_RELEASE_STREAM is not a secret * Add back in ITUNES_CONNECT_SHARED_SECRET * Use .nvmrc file for node version in ci Co-authored-by: Kenny * New ci workflow file for release android-release.yml, not uploading for now (waiting for key approval) Co-authored-by: Kenny * Disable running of the release workflow on push for now Co-authored-by: Jorge * Remove commented out vars / steps * Indent fix and upload artifact update Co-authored-by: Julia Branke * Reduce permissions to contents write * Remove 14001358 from minor version calc * Use SHA to create release (instead of branch name) * Log github.ref as a test on push Co-authored-by: Jorge Co-authored-by: Michael * Revert change in make-release and delete test echo Co-authored-by: Jorge Co-authored-by: Michael * Add beta workflow updates to release * Echo build number so we can confirm it more easily * Better artifact names * Remove debugging commands * Add optional track param to release script * Actually pass track internal/production to script * Undo unintentional linting * Revert build.gradle * Use GHA output to manage version code * Update comments on build number calculation * Disable run on every push (testing only) --------- Co-authored-by: Mohammad Haque Co-authored-by: Michael Clapham Co-authored-by: Julia Branke Co-authored-by: Julia Branke Co-authored-by: Kenny Co-authored-by: Michael --- .github/workflows/android-beta.yml | 85 +++++++++++++++++++++++ .github/workflows/android-release.yml | 85 +++++++++++++++++++++++ build_apk.sh | 7 -- projects/Mallard/android/app/build.gradle | 2 +- projects/Mallard/fastlane/Fastfile | 5 +- script/make-release.js | 15 ++-- 6 files changed, 186 insertions(+), 13 deletions(-) create mode 100644 .github/workflows/android-beta.yml create mode 100644 .github/workflows/android-release.yml diff --git a/.github/workflows/android-beta.yml b/.github/workflows/android-beta.yml new file mode 100644 index 0000000000..c9c6207beb --- /dev/null +++ b/.github/workflows/android-beta.yml @@ -0,0 +1,85 @@ +name: android-beta + +on: + workflow_dispatch: + +jobs: + build: + permissions: + contents: write + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Set up JDK 11 + uses: actions/setup-java@v3 + with: + java-version: '11' + distribution: 'temurin' + + - uses: actions/setup-node@v3 + with: + node-version-file: 'projects/Mallard/.nvmrc' + + - name: Setup Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: 2.7.3 + bundler-cache: true + + - name: inject credentials + run: | + echo -e "\n\n${{ secrets.ANDROID_GRADLE_PROPERTIES }}" >> projects/Mallard/android/gradle.properties + echo "${{ secrets.ANDROID_KEYSTORE_BASE64 }}" | base64 --decode > projects/Mallard/android/app/editions-release-2023.keystore + + # We add ~900 to the github run number to syncronise it with the last beta build number from TeamCity + - name: set build number + run: | + echo "BUILD_NUMBER=$(($GITHUB_RUN_NUMBER + 894))" >> "$GITHUB_ENV" + + - run: echo $BUILD_NUMBER + + - name: install + run: | + make install + + - name: validate + run: make validate-Mallard + + - name: Build APK + id: build_app + run: | + ./build_apk.sh BETA + env: + ID_ACCESS_TOKEN: ${{ secrets.ID_ACCESS_TOKEN }} + ID_API_URL: ${{ secrets.ID_API_URL }} + LOGGING_API_KEY: ${{ secrets.LOGGING_API_KEY }} + ITUNES_CONNECT_SHARED_SECRET: ${{ secrets.ITUNES_CONNECT_SHARED_SECRET }} + MEMBERS_DATA_API_URL: ${{ secrets.MEMBERS_DATA_API_URL }} + SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} + SENTRY_CLI_EXECUTABLE: ${{ secrets.SENTRY_CLI_EXECUTABLE }} + SENTRY_DEFAULTS_ORG: ${{ secrets.SENTRY_DEFAULTS_ORG }} + SENTRY_DEFAULTS_PROJECT: ${{ secrets.SENTRY_DEFAULTS_PROJECT }} + SENTRY_DEFAULTS_URL: ${{ secrets.SENTRY_DEFAULTS_URL }} + SENTRY_DSN_URL: ${{ secrets.SENTRY_DSN_URL }} + FASTLANE_USER: ${{ secrets.FASTLANE_USER }} + FASTLANE_PASSWORD: ${{ secrets.FASTLANE_PASSWORD }} + ANDROID_RELEASE_STREAM: 'DEBUG' + USE_SANDBOX_IAP: 'true' + FASTLANE_TEAM_ID: ${{ secrets.FASTLANE_TEAM_ID }} + SUPPLY_JSON_KEY_DATA: ${{ secrets.SUPPLY_JSON_KEY_DATA }} + BUILD_NUMBER: ${{ env.BUILD_NUMBER }} + + - uses: actions/upload-artifact@v3 + if: always() + with: + name: internal-apk + path: | + projects/Mallard/android/app/build/outputs/apk/release/app-release.apk + + - name: tag release on github + working-directory: script + run: node make-release.js ${{ github.sha }} ${{ github.ref }} ${{ steps.build_app.outputs.VERSION_CODE }} android internal + env: + REPO_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/android-release.yml b/.github/workflows/android-release.yml new file mode 100644 index 0000000000..93cf30299a --- /dev/null +++ b/.github/workflows/android-release.yml @@ -0,0 +1,85 @@ +name: android-release + +on: + workflow_dispatch: + +jobs: + build: + permissions: + contents: write + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Set up JDK 11 + uses: actions/setup-java@v3 + with: + java-version: '11' + distribution: 'temurin' + + - uses: actions/setup-node@v3 + with: + node-version-file: 'projects/Mallard/.nvmrc' + + - name: Setup Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: 2.7.3 + bundler-cache: true + + - name: inject credentials + run: | + echo -e "\n\n${{ secrets.ANDROID_GRADLE_PROPERTIES }}" >> projects/Mallard/android/gradle.properties + echo "${{ secrets.ANDROID_KEYSTORE_BASE64 }}" | base64 --decode > projects/Mallard/android/app/editions-release-2023.keystore + + # We add 50 to the github run number to syncronise it with the last release build number from TeamCity + - name: set build number + run: | + echo "BUILD_NUMBER=$(($GITHUB_RUN_NUMBER + 50))" >> "$GITHUB_ENV" + + - run: echo $BUILD_NUMBER + + - name: install + run: | + make install + + - name: validate + run: make validate-Mallard + + - name: Build APK + id: build_app + run: | + ./build_apk.sh RELEASE + env: + ID_ACCESS_TOKEN: ${{ secrets.ID_ACCESS_TOKEN }} + ID_API_URL: ${{ secrets.ID_API_URL }} + LOGGING_API_KEY: ${{ secrets.LOGGING_API_KEY }} + ITUNES_CONNECT_SHARED_SECRET: ${{ secrets.ITUNES_CONNECT_SHARED_SECRET }} + MEMBERS_DATA_API_URL: ${{ secrets.MEMBERS_DATA_API_URL }} + SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} + SENTRY_CLI_EXECUTABLE: ${{ secrets.SENTRY_CLI_EXECUTABLE }} + SENTRY_DEFAULTS_ORG: ${{ secrets.SENTRY_DEFAULTS_ORG }} + SENTRY_DEFAULTS_PROJECT: ${{ secrets.SENTRY_DEFAULTS_PROJECT }} + SENTRY_DEFAULTS_URL: ${{ secrets.SENTRY_DEFAULTS_URL }} + SENTRY_DSN_URL: ${{ secrets.SENTRY_DSN_URL }} + FASTLANE_USER: ${{ secrets.FASTLANE_USER }} + FASTLANE_PASSWORD: ${{ secrets.FASTLANE_PASSWORD }} + ANDROID_RELEASE_STREAM: 'RELEASE' + USE_SANDBOX_IAP: 'true' + FASTLANE_TEAM_ID: ${{ secrets.FASTLANE_TEAM_ID }} + SUPPLY_JSON_KEY_DATA: ${{ secrets.SUPPLY_JSON_KEY_DATA }} + BUILD_NUMBER: ${{ env.BUILD_NUMBER }} + + - uses: actions/upload-artifact@v3 + if: always() + with: + name: release-apk + path: | + projects/Mallard/android/app/build/outputs/apk/release/app-release.apk + + - name: tag release on github + working-directory: script + run: node make-release.js ${{ github.sha }} ${{ github.ref }} ${{ steps.build_app.outputs.VERSION_CODE }} android production + env: + REPO_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/build_apk.sh b/build_apk.sh index d097651118..d35d638798 100755 --- a/build_apk.sh +++ b/build_apk.sh @@ -23,13 +23,6 @@ case $1 in ;; esac -npm cache clean -f -npm install -g n -n 16.16 -PATH="$PATH" -echo "NEW NODE VERSION" -node --version - npm install -g yarn npx --force cd projects/Mallard echo "building APK with command 'make $TARGET'" diff --git a/projects/Mallard/android/app/build.gradle b/projects/Mallard/android/app/build.gradle index 7eec4b35c3..f302032184 100644 --- a/projects/Mallard/android/app/build.gradle +++ b/projects/Mallard/android/app/build.gradle @@ -71,7 +71,7 @@ def enableProguardInReleaseBuilds = false //For legacy reason we are adding current build number (14001358) from Play Store def appVersionCode = 14001358 + buildNumber() -println("##teamcity[setParameter name='VERSION_CODE' value='${appVersionCode}']") +println("::set-output name=VERSION_CODE::${appVersionCode}") /** * The preferred build flavor of JavaScriptCore (JSC) diff --git a/projects/Mallard/fastlane/Fastfile b/projects/Mallard/fastlane/Fastfile index 947033a445..80db6d6375 100644 --- a/projects/Mallard/fastlane/Fastfile +++ b/projects/Mallard/fastlane/Fastfile @@ -39,7 +39,7 @@ platform :ios do duration: 1200, # optional in_house: false # optional but may be required if using match/sigh ) - + create_keychain( name: "CI", password: ENV["FASTLANE_PASSWORD"], @@ -113,9 +113,11 @@ platform :android do project_dir: 'android/' ) supply( + skip_upload_apk: true, # TODO: Remove when new upload key approved track: 'internal', package_name: 'com.guardian.editions' ) + end end @@ -127,6 +129,7 @@ platform :android do project_dir: 'android/' ) supply( + skip_upload_apk: true, # TODO: Remove when new upload key approved track: 'production', package_name: 'com.guardian.editions' ) diff --git a/script/make-release.js b/script/make-release.js index befd230f01..b09ab42820 100644 --- a/script/make-release.js +++ b/script/make-release.js @@ -51,16 +51,21 @@ const makeReleaseName = (name, os, appStoreId) => `${name}--${os}:${appStoreId}` const cleanBranch = branch => branch.replace('refs/heads/', '') -const updateRelease = async (commitSha, branch, appStoreId, os) => { +const updateRelease = async (commitSha, branch, appStoreId, os, track) => { console.log( - `Updating github release tags with sha: ${commitSha} branch: ${branch} appStoreId: ${appStoreId} os: ${os}`, + `Updating github release tags with sha: ${commitSha} branch: ${branch} appStoreId: ${appStoreId} os: ${os} track: ${track}`, ) const shortBranch = cleanBranch(branch) const releases = await get('releases') const matchingRelease = findReleaseForCommit(commitSha, releases) const appStoreName = os === 'ios' ? 'Apple App Store' : 'Google Play Store' - const releaseMessage = `Released to ${appStoreName}, version ${appStoreId}. Built from branch ${branch}.` + let releaseMessage = `Released to ${appStoreName}, version ${appStoreId}. Built from branch ${branch}.` + + // On android this is internal or production + if (track) { + releaseMessage += ` Track: ${track}` + } if (matchingRelease) { console.log( @@ -102,9 +107,10 @@ const params = { branch: 3, appStoreId: 4, os: 5, + track: 6, } -if (process.argv.length - 2 < Object.keys(params).length) { +if (process.argv.length - 2 < Object.keys(params).length - 1) { console.error('Invalid arguments to release script') console.log( `Usage: node ${process.argv[1]} <${Object.keys(params).join('> <')}>`, @@ -116,5 +122,6 @@ if (process.argv.length - 2 < Object.keys(params).length) { process.argv[params.branch], process.argv[params.appStoreId], process.argv[params.os], + process.argv[params.track], ) }