|
| 1 | +name: Build Mobile App |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + build_name: |
| 7 | + required: true |
| 8 | + type: string |
| 9 | + platform: |
| 10 | + required: true |
| 11 | + type: string # android, ios, or both |
| 12 | + workflow_dispatch: |
| 13 | + inputs: |
| 14 | + build_name: |
| 15 | + required: true |
| 16 | + type: choice |
| 17 | + options: |
| 18 | + - main-prod |
| 19 | + - main-rc |
| 20 | + - main-test |
| 21 | + - main-e2e |
| 22 | + - main-exp |
| 23 | + - main-dev |
| 24 | + - flask-prod |
| 25 | + - flask-test |
| 26 | + - flask-e2e |
| 27 | + - flask-dev |
| 28 | + - qa-prod |
| 29 | + - qa-dev |
| 30 | + platform: |
| 31 | + required: true |
| 32 | + type: choice |
| 33 | + options: [android, ios, both] |
| 34 | + |
| 35 | +permissions: |
| 36 | + contents: read |
| 37 | + id-token: write |
| 38 | + |
| 39 | +jobs: |
| 40 | + # Load config |
| 41 | + prepare: |
| 42 | + runs-on: ubuntu-latest |
| 43 | + outputs: |
| 44 | + github_environment: ${{ steps.config.outputs.github_environment }} |
| 45 | + secrets_json: ${{ steps.config.outputs.secrets_json }} |
| 46 | + steps: |
| 47 | + - uses: actions/checkout@v4 |
| 48 | + - uses: actions/setup-node@v4 |
| 49 | + with: |
| 50 | + node-version: '20' |
| 51 | + - run: yarn install --immutable |
| 52 | + - run: node scripts/validate-build-config.js |
| 53 | + |
| 54 | + - name: Load config |
| 55 | + id: config |
| 56 | + run: | |
| 57 | + node -e " |
| 58 | + const yaml = require('js-yaml'); |
| 59 | + const fs = require('fs'); |
| 60 | + const config = yaml.load(fs.readFileSync('.github/builds.yml', 'utf8')); |
| 61 | + const build = config.builds['${{ inputs.build_name }}']; |
| 62 | + fs.appendFileSync(process.env.GITHUB_OUTPUT, 'github_environment=' + build.github_environment + '\n'); |
| 63 | + fs.appendFileSync(process.env.GITHUB_OUTPUT, 'secrets_json=' + JSON.stringify(build.secrets || {}) + '\n'); |
| 64 | + " |
| 65 | +
|
| 66 | + # Build |
| 67 | + build: |
| 68 | + needs: [prepare] |
| 69 | + strategy: |
| 70 | + matrix: |
| 71 | + platform: ${{ inputs.platform == 'both' && fromJSON('["android", "ios"]') || fromJSON(format('["{0}"]', inputs.platform)) }} |
| 72 | + # Android uses Cirrus runner with SDK pre-installed; iOS uses GitHub-hosted macOS |
| 73 | + runs-on: ${{ matrix.platform == 'ios' && 'macos-latest' || 'ghcr.io/cirruslabs/ubuntu-runner-amd64:24.04-lg' }} |
| 74 | + environment: ${{ needs.prepare.outputs.github_environment }} |
| 75 | + steps: |
| 76 | + - uses: actions/checkout@v4 |
| 77 | + - uses: actions/setup-node@v4 |
| 78 | + with: |
| 79 | + node-version: '20' |
| 80 | + cache: 'yarn' |
| 81 | + - run: yarn install --immutable |
| 82 | + |
| 83 | + - name: Apply build config |
| 84 | + run: | |
| 85 | + # Load env vars from builds.yml |
| 86 | + eval "$(node scripts/apply-build-config.js ${{ inputs.build_name }} --export)" |
| 87 | +
|
| 88 | + - name: Set secrets |
| 89 | + env: |
| 90 | + CONFIG_SECRETS: ${{ needs.prepare.outputs.secrets_json }} |
| 91 | + run: node scripts/set-secrets-from-config.js |
| 92 | + |
| 93 | + # Android only: minimal env (SDK is pre-installed on Cirrus runner) |
| 94 | + - name: Set Android environment variables |
| 95 | + if: matrix.platform == 'android' |
| 96 | + run: | |
| 97 | + echo "ANDROID_HOME=/opt/android-sdk" >> "$GITHUB_ENV" |
| 98 | + echo "ANDROID_SDK_ROOT=/opt/android-sdk" >> "$GITHUB_ENV" |
| 99 | +
|
| 100 | + - name: Setup Java |
| 101 | + if: matrix.platform == 'android' |
| 102 | + uses: actions/setup-java@v4 |
| 103 | + with: |
| 104 | + java-version: '17' |
| 105 | + distribution: 'temurin' |
| 106 | + |
| 107 | + # Android qa signing (exp-test-e2e): skip for Expo dev builds (main-dev, flask-dev, qa-dev use debug keystore) |
| 108 | + - name: Configure Android signing certificates |
| 109 | + if: matrix.platform == 'android' && inputs.build_name != 'main-dev' && inputs.build_name != 'flask-dev' && inputs.build_name != 'qa-dev' |
| 110 | + uses: MetaMask/github-tools/.github/actions/configure-keystore@0259e8a920318b02a8860e178d79796eaa08de02 |
| 111 | + with: |
| 112 | + aws-role-to-assume: 'arn:aws:iam::363762752069:role/metamask-mobile-build-signer-qa' |
| 113 | + aws-region: 'us-east-2' |
| 114 | + platform: 'android' |
| 115 | + target: ${{ startsWith(inputs.build_name, 'flask') && 'flask' || 'qa' }} |
| 116 | + |
| 117 | + - name: Setup project dependencies with retry |
| 118 | + uses: nick-fields/retry@ce71cc2ab81d554ebbe88c79ab5975992d79ba08 #v3.0.2 |
| 119 | + with: |
| 120 | + timeout_minutes: 10 |
| 121 | + max_attempts: 3 |
| 122 | + retry_wait_seconds: 30 |
| 123 | + command: | |
| 124 | + echo "🚀 Setting up project..." |
| 125 | + if [ "${{ matrix.platform }}" = "ios" ]; then |
| 126 | + yarn setup:github-ci --build-ios --no-build-android |
| 127 | + else |
| 128 | + yarn setup:github-ci --no-build-ios |
| 129 | + fi |
| 130 | +
|
| 131 | + - name: Build ${{ matrix.platform }} |
| 132 | + run: | |
| 133 | + ./scripts/build.sh ${{ matrix.platform }} ${{ inputs.build_name }} |
| 134 | +
|
| 135 | + # Expo development builds: upload iOS .app for simulator (Runway-style artifact) |
| 136 | + - name: Upload iOS Expo development build |
| 137 | + if: matrix.platform == 'ios' && (inputs.build_name == 'main-dev' || inputs.build_name == 'flask-dev' || inputs.build_name == 'qa-dev') |
| 138 | + uses: actions/upload-artifact@v4 |
| 139 | + with: |
| 140 | + name: expo-dev-ios-${{ inputs.build_name }} |
| 141 | + path: ios/build/Build/Products/Release-iphonesimulator/ |
0 commit comments