Build staging Android project #3317
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build staging Android project | |
on: | |
workflow_dispatch: | |
inputs: | |
force-build: | |
description: 'Forces a new build and ignores the cache' | |
required: false | |
type: choice | |
default: false | |
options: | |
- true | |
- false | |
push: | |
branches: | |
- master | |
- release/** | |
jobs: | |
build-android: | |
name: Build Android | |
strategy: | |
fail-fast: false | |
matrix: | |
org: [atb, nfk, fram, troms] | |
environment: ${{ matrix.org }} | |
timeout-minutes: 180 | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout project | |
uses: actions/checkout@v1 | |
- name: Set global env vars | |
run: | | |
echo "BUILD_ID=$(date +%s)" >> $GITHUB_ENV | |
echo "APP_ENVIRONMENT=staging" >> $GITHUB_ENV | |
echo "KEYSTORE_PATH=./android/app/keystore.jks" >> $GITHUB_ENV | |
echo "APK_FILE_NAME=app-staging.apk" >> $GITHUB_ENV | |
echo "JAVA_HOME=$JAVA_HOME_17_X64" >> $GITHUB_ENV | |
echo "/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin" >> $GITHUB_PATH | |
- name: Decrypt env files | |
run: bash ./scripts/git-crypt-unlock.sh | |
env: | |
GIT_CRYPT_KEY: ${{ secrets.GIT_CRYPT_KEY }} | |
- name: Add Entur private registry credentials | |
run: bash ./scripts/add-entur-private-registry.sh | |
env: | |
ENTUR_REGISTRY_USER: ${{ vars.ENTUR_REGISTRY_USER }} | |
ENTUR_REGISTRY_TOKEN: ${{ secrets.ENTUR_REGISTRY_TOKEN }} | |
- name: Install imagemagick | |
run: sudo apt-get update && sudo apt-get install imagemagick | |
- name: install node v18 | |
uses: actions/setup-node@v1 | |
with: | |
node-version: 18 | |
- name: Get potential cached node_modules | |
if: inputs.force-build != 'true' | |
uses: actions/cache@v2 | |
id: modules-cache | |
with: | |
path: '**/node_modules' | |
key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}-${{ hashFiles('**/patches/**.patch') }} | |
- name: Install node_modules | |
if: inputs.force-build == 'true' || steps.modules-cache.outputs.cache-hit != 'true' | |
run: yarn install --frozen-lockfile | |
- name: Setup ruby and bundle install | |
uses: ruby/setup-ruby@v1 | |
with: | |
ruby-version: 2.7.6 | |
cache-version: 1 | |
bundler-cache: true # runs 'bundle install' and caches installed gems automatically | |
- name: Set environment | |
run: bash ./scripts/override-environment.sh $APP_ENVIRONMENT ${{ matrix.org }} | |
- name: Export workflow env variables based on environment | |
run: bash ./scripts/export-workflow-parameters.sh | |
- name: Override native config files | |
run: bash ./scripts/android/override-config-files.sh | |
- name: Get potential cached APK | |
uses: actions/cache@v2 | |
id: apk-cache | |
with: | |
path: app-staging.apk | |
key: ${{ matrix.org }}-${{ runner.os }}-android-cache-${{ hashFiles('android/**') }}-${{ hashFiles('**/yarn.lock') }}-${{ hashFiles('**/patches/**.patch') }}-${{ hashFiles('.env') }} | |
- name: Decode Android keystore | |
run: bash ./scripts/android/create-keystore-file.sh | |
env: | |
KEYSTORE: ${{ secrets.KEYSTORE }} | |
- name: Generate native assets | |
if: inputs.force-build == 'true' || steps.apk-cache.outputs.cache-hit != 'true' | |
run: yarn generate-native-assets | |
- name: Run fastlane build | |
if: inputs.force-build == 'true' || steps.apk-cache.outputs.cache-hit != 'true' | |
run: bundle exec fastlane android build | |
env: | |
KEYSTORE_PASS: ${{ secrets.KEYSTORE_PASS }} | |
KEY_PASS: ${{ secrets.KEYSTORE_KEY_PASS }} | |
KEY_ALIAS: ${{ secrets.KEYSTORE_KEY_ALIAS }} | |
- name: Replace apk bundle | |
if: inputs.force-build == 'true' || steps.apk-cache.outputs.cache-hit == 'true' | |
run: bash ./scripts/android/replace-bundle.sh | |
env: | |
KEYSTORE_PASS: ${{ secrets.KEYSTORE_PASS }} | |
KEY_PASS: ${{ secrets.KEYSTORE_KEY_PASS }} | |
KEY_ALIAS: ${{ secrets.KEYSTORE_KEY_ALIAS }} | |
- name: Distribute to AppCenter | |
if: matrix.org == 'atb' | |
run: bundle exec fastlane android appcenter_staging | |
env: | |
APPCENTER_API_KEY: ${{ secrets.APPCENTER_ANDROID_API_KEY }} | |
- name: Distribute to Firebase App Distribution | |
if: matrix.org != 'atb' | |
run: | | |
echo ${{ secrets.FIREBASE_DISTRIBUTION_CREDENTIALS}} | base64 --decode > google-services.json | |
bundle exec fastlane android firebase_distribution_staging | |
env: | |
GCP_CREDENTIALS_PATH: google-services.json | |
FIREBASE_APP_ID: ${{ secrets.FIREBASE_APP_ID }} | |
- name: Upload bundle and source maps | |
run: bash ./scripts/android/upload-sourcemaps.sh | |
env: | |
BUGSNAG_API_KEY: ${{ secrets.BUGSNAG_API_KEY }} | |
- name: Register app version | |
run: bash ./scripts/android/register-app-version.sh | |
env: | |
ENTUR_PUBLISH_CLIENT: ${{ secrets.ABT_ENTUR_PUBLISH_CLIENT_STAGING }} | |
DISABLE_LISTED_ON_PLAY_STORE: true |