Skip to content

Commit

Permalink
Teamcity migration (#2276)
Browse files Browse the repository at this point in the history
* 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 <JuliaBrigitte@users.noreply.github.com>

* 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 <Jorge.Azevedo@guardian.co.uk>

* New ci workflow file for release android-release.yml, not uploading for now (waiting for key approval)

Co-authored-by: Kenny <Jorge.Azevedo@guardian.co.uk>

* Disable running of the release workflow on push for now

Co-authored-by: Jorge <Jorge.Azevedo@guardian.co.uk>

* Remove commented out vars / steps

* Indent fix and upload artifact update

Co-authored-by: Julia Branke <JuliaBrigitte@users.noreply.github.com>

* 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 <Jorge.Azevedo@guardian.co.uk>
Co-authored-by: Michael <Michael.Clapham@guardian.co.uk>

* Revert change in make-release and delete test echo

Co-authored-by: Jorge <Jorge.Azevedo@guardian.co.uk>
Co-authored-by: Michael <Michael.Clapham@guardian.co.uk>

* 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 <mohammad.haque@theguardian.com>
Co-authored-by: Michael Clapham <michaeljclapham@gmail.com>
Co-authored-by: Julia Branke <JuliaBrigitte@users.noreply.github.com>
Co-authored-by: Julia Branke <Julia.Branke@guardian.co.uk>
Co-authored-by: Kenny <Jorge.Azevedo@guardian.co.uk>
Co-authored-by: Michael <Michael.Clapham@guardian.co.uk>
  • Loading branch information
7 people committed Sep 14, 2023
1 parent 9690e4a commit f8cb5a2
Show file tree
Hide file tree
Showing 6 changed files with 186 additions and 13 deletions.
85 changes: 85 additions & 0 deletions .github/workflows/android-beta.yml
Original file line number Diff line number Diff line change
@@ -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 }}
85 changes: 85 additions & 0 deletions .github/workflows/android-release.yml
Original file line number Diff line number Diff line change
@@ -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 }}
7 changes: 0 additions & 7 deletions build_apk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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'"
Expand Down
2 changes: 1 addition & 1 deletion projects/Mallard/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion projects/Mallard/fastlane/Fastfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down Expand Up @@ -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

Expand All @@ -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'
)
Expand Down
15 changes: 11 additions & 4 deletions script/make-release.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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('> <')}>`,
Expand All @@ -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],
)
}

0 comments on commit f8cb5a2

Please sign in to comment.