|
| 1 | +name: Build Android app |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + type: |
| 7 | + description: 'What type of build to run. Must be one of ["release", "adhoc", "e2e", "e2eDelta"]' |
| 8 | + type: string |
| 9 | + required: true |
| 10 | + ref: |
| 11 | + description: Git ref to checkout and build |
| 12 | + type: string |
| 13 | + required: true |
| 14 | + artifact-prefix: |
| 15 | + description: 'The prefix for build artifact names. This is useful if you need to call multiple builds from the same workflow' |
| 16 | + type: string |
| 17 | + required: false |
| 18 | + default: '' |
| 19 | + pull_request_number: |
| 20 | + description: The pull request number associated with this build, if relevant. |
| 21 | + type: string |
| 22 | + required: false |
| 23 | + outputs: |
| 24 | + AAB_FILE_NAME: |
| 25 | + value: ${{ jobs.build.outputs.AAB_FILE_NAME }} |
| 26 | + APK_FILE_NAME: |
| 27 | + value: ${{ jobs.build.outputs.APK_FILE_NAME }} |
| 28 | + |
| 29 | + workflow_dispatch: |
| 30 | + inputs: |
| 31 | + type: |
| 32 | + description: What type of build do you want to run? |
| 33 | + required: true |
| 34 | + type: choice |
| 35 | + options: |
| 36 | + - release |
| 37 | + - adhoc |
| 38 | + - e2e |
| 39 | + - e2eDelta |
| 40 | + ref: |
| 41 | + description: Git ref to checkout and build |
| 42 | + required: true |
| 43 | + type: string |
| 44 | + |
| 45 | + pull_request_number: |
| 46 | + description: The pull request number associated with this build, if relevant. |
| 47 | + type: number |
| 48 | + required: false |
| 49 | + |
| 50 | +jobs: |
| 51 | + build: |
| 52 | + name: Build Android app |
| 53 | + runs-on: ubuntu-latest-xl |
| 54 | + env: |
| 55 | + RUBYOPT: '-rostruct' |
| 56 | + outputs: |
| 57 | + AAB_FILE_NAME: ${{ steps.build.outputs.AAB_FILE_NAME }} |
| 58 | + APK_FILE_NAME: ${{ steps.build.outputs.APK_FILE_NAME }} |
| 59 | + |
| 60 | + steps: |
| 61 | + - name: Checkout |
| 62 | + uses: actions/checkout@v4 |
| 63 | + with: |
| 64 | + ref: ${{ inputs.ref }} |
| 65 | + |
| 66 | + - name: Configure MapBox SDK |
| 67 | + run: ./scripts/setup-mapbox-sdk.sh ${{ secrets.MAPBOX_SDK_DOWNLOAD_TOKEN }} |
| 68 | + |
| 69 | + - name: Setup Node |
| 70 | + uses: ./.github/actions/composite/setupNode |
| 71 | + |
| 72 | + - name: Setup Java |
| 73 | + uses: actions/setup-java@v4 |
| 74 | + with: |
| 75 | + distribution: oracle |
| 76 | + java-version: 17 |
| 77 | + |
| 78 | + - name: Setup Gradle |
| 79 | + uses: gradle/actions/setup-gradle@v4 |
| 80 | + |
| 81 | + - name: Setup Ruby |
| 82 | + uses: ruby/setup-ruby@v1.190.0 |
| 83 | + with: |
| 84 | + bundler-cache: true |
| 85 | + |
| 86 | + - name: Decrypt keystore and json key |
| 87 | + run: | |
| 88 | + cd android/app |
| 89 | + gpg --batch --yes --decrypt --passphrase="${{ secrets.LARGE_SECRET_PASSPHRASE }}" --output my-upload-key.keystore my-upload-key.keystore.gpg |
| 90 | + gpg --batch --yes --decrypt --passphrase="${{ secrets.LARGE_SECRET_PASSPHRASE }}" --output android-fastlane-json-key.json android-fastlane-json-key.json.gpg |
| 91 | +
|
| 92 | + - name: Get package version |
| 93 | + id: getPackageVersion |
| 94 | + run: echo "VERSION=$(jq -r .version < package.json)" >> "$GITHUB_OUTPUT" |
| 95 | + |
| 96 | + - name: Get Android native version |
| 97 | + id: getAndroidVersion |
| 98 | + run: echo "VERSION_CODE=$(grep -o 'versionCode\s\+[0-9]\+' android/app/build.gradle | awk '{ print $2 }')" >> "$GITHUB_OUTPUT" |
| 99 | + |
| 100 | + - name: Setup DotEnv |
| 101 | + if: ${{ inputs.type != 'release' }} |
| 102 | + run: | |
| 103 | + if [ '${{ inputs.type }}' == 'adhoc' ]; then |
| 104 | + cp .env.staging .env.adhoc |
| 105 | + sed -i 's/ENVIRONMENT=staging/ENVIRONMENT=adhoc/' .env.adhoc |
| 106 | + echo "PULL_REQUEST_NUMBER=${{ inputs.pull_request_number }}" >> .env.adhoc |
| 107 | + else |
| 108 | + envFile='' |
| 109 | + if [ '${{ inputs.type }}' == 'e2e' ]; then |
| 110 | + envFile='tests/e2e/.env.e2e' |
| 111 | + else |
| 112 | + envFile=tests/e2e/.env.e2edelta |
| 113 | + fi |
| 114 | + { |
| 115 | + echo "EXPENSIFY_PARTNER_NAME=${{ secrets.EXPENSIFY_PARTNER_NAME }}" |
| 116 | + echo "EXPENSIFY_PARTNER_PASSWORD=${{ secrets.EXPENSIFY_PARTNER_PASSWORD }}" |
| 117 | + echo "EXPENSIFY_PARTNER_USER_ID=${{ secrets.EXPENSIFY_PARTNER_USER_ID }}" |
| 118 | + echo "EXPENSIFY_PARTNER_USER_SECRET=${{ secrets.EXPENSIFY_PARTNER_USER_SECRET }}" |
| 119 | + echo "EXPENSIFY_PARTNER_PASSWORD_EMAIL=${{ secrets.EXPENSIFY_PARTNER_PASSWORD_EMAIL }}" |
| 120 | + } >> "$envFile" |
| 121 | + fi |
| 122 | +
|
| 123 | + - name: Build Android app |
| 124 | + id: build |
| 125 | + run: | |
| 126 | + lane='' |
| 127 | + case '${{ inputs.type }}' in |
| 128 | + 'release') |
| 129 | + lane='build';; |
| 130 | + 'adhoc') |
| 131 | + lane='build_adhoc';; |
| 132 | + 'e2e') |
| 133 | + lane='build_e2e';; |
| 134 | + 'e2eDelta') |
| 135 | + lane='build_e2eDelta';; |
| 136 | + esac |
| 137 | + bundle exec fastlane android "$lane" |
| 138 | +
|
| 139 | + # Refresh environment variables from GITHUB_ENV that are updated when running fastlane |
| 140 | + # shellcheck disable=SC1090 |
| 141 | + source "$GITHUB_ENV" |
| 142 | +
|
| 143 | + SHOULD_UPLOAD_SOURCEMAPS='false' |
| 144 | + if [ -f ./android/app/build/generated/sourcemaps/react/productionRelease/index.android.bundle.map ]; then |
| 145 | + SHOULD_UPLOAD_SOURCEMAPS='true' |
| 146 | + fi |
| 147 | +
|
| 148 | + { |
| 149 | + # aabPath and apkPath are environment varibles set within the Fastfile |
| 150 | + echo "AAB_PATH=$aabPath" |
| 151 | + echo "AAB_FILE_NAME=$(basename "$aabPath")" |
| 152 | + echo "APK_PATH=$apkPath" |
| 153 | + echo "APK_FILE_NAME=$(basename "$apkPath")" |
| 154 | + echo "SHOULD_UPLOAD_SOURCEMAPS=$SHOULD_UPLOAD_SOURCEMAPS" |
| 155 | + } >> "$GITHUB_OUTPUT" |
| 156 | + env: |
| 157 | + MYAPP_UPLOAD_STORE_PASSWORD: ${{ secrets.MYAPP_UPLOAD_STORE_PASSWORD }} |
| 158 | + MYAPP_UPLOAD_KEY_PASSWORD: ${{ secrets.MYAPP_UPLOAD_KEY_PASSWORD }} |
| 159 | + |
| 160 | + - name: Upload Android AAB artifact |
| 161 | + if: ${{ steps.build.outputs.AAB_PATH != '' }} |
| 162 | + continue-on-error: true |
| 163 | + uses: actions/upload-artifact@v4 |
| 164 | + with: |
| 165 | + name: ${{ inputs.artifact-prefix }}android-artifact-aab |
| 166 | + path: ${{ steps.build.outputs.AAB_PATH }} |
| 167 | + |
| 168 | + - name: Upload Android APK artifact |
| 169 | + if: ${{ steps.build.outputs.APK_PATH != '' }} |
| 170 | + continue-on-error: true |
| 171 | + uses: actions/upload-artifact@v4 |
| 172 | + with: |
| 173 | + name: ${{ inputs.artifact-prefix }}android-artifact-apk |
| 174 | + path: ${{ steps.build.outputs.APK_PATH }} |
| 175 | + |
| 176 | + - name: Upload Android sourcemaps artifact |
| 177 | + if: ${{ steps.build.outputs.SHOULD_UPLOAD_SOURCEMAPS == 'true' }} |
| 178 | + continue-on-error: true |
| 179 | + uses: actions/upload-artifact@v4 |
| 180 | + with: |
| 181 | + name: ${{ inputs.artifact-prefix }}android-artifact-sourcemaps |
| 182 | + path: ./android/app/build/generated/sourcemaps/react/productionRelease/index.android.bundle.map |
| 183 | + |
| 184 | + - name: Announce failure in slack |
| 185 | + if: failure() |
| 186 | + uses: ./.github/actions/composite/announceFailedWorkflowInSlack |
| 187 | + with: |
| 188 | + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} |
0 commit comments