|
| 1 | +name: Build Mobile App |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + environment: |
| 7 | + required: true |
| 8 | + type: string |
| 9 | + platform: |
| 10 | + required: true |
| 11 | + type: choice |
| 12 | + options: [android, ios, both] |
| 13 | + build_type: |
| 14 | + required: true |
| 15 | + type: choice |
| 16 | + options: [main, flask] |
| 17 | + default: main |
| 18 | + workflow_dispatch: |
| 19 | + inputs: |
| 20 | + environment: |
| 21 | + required: true |
| 22 | + type: choice |
| 23 | + options: [prod, rc, exp] |
| 24 | + platform: |
| 25 | + required: true |
| 26 | + type: choice |
| 27 | + options: [android, ios, both] |
| 28 | + build_type: |
| 29 | + required: true |
| 30 | + type: choice |
| 31 | + options: [main, flask] |
| 32 | + default: main |
| 33 | + |
| 34 | +jobs: |
| 35 | + load-environment-config: |
| 36 | + runs-on: ubuntu-latest |
| 37 | + outputs: |
| 38 | + config: ${{ steps.load-config.outputs.config }} |
| 39 | + requires_approval: ${{ steps.load-config.outputs.requires_approval }} |
| 40 | + github_environment: ${{ steps.load-config.outputs.github_environment }} |
| 41 | + secrets_mapping: ${{ steps.load-config.outputs.secrets_mapping }} |
| 42 | + steps: |
| 43 | + - uses: actions/checkout@v4 |
| 44 | + |
| 45 | + - name: Setup Node.js |
| 46 | + uses: actions/setup-node@v4 |
| 47 | + with: |
| 48 | + node-version: '20' |
| 49 | + |
| 50 | + - name: Install dependencies |
| 51 | + run: yarn install --immutable |
| 52 | + |
| 53 | + - name: Merge and load environment configuration |
| 54 | + id: load-config |
| 55 | + uses: actions/github-script@v7 |
| 56 | + with: |
| 57 | + script: | |
| 58 | + const { mergeConfigs } = require('./scripts/merge-config.js'); |
| 59 | + const env = '${{ inputs.environment }}'; |
| 60 | + const config = mergeConfigs(env); |
| 61 | +
|
| 62 | + // Extract secrets mapping |
| 63 | + const secretsMapping = JSON.stringify(config.secrets || {}); |
| 64 | +
|
| 65 | + return { |
| 66 | + config: JSON.stringify(config), |
| 67 | + requires_approval: config.environment.requires_approval, |
| 68 | + github_environment: config.environment.github_environment, |
| 69 | + secrets_mapping: secretsMapping |
| 70 | + }; |
| 71 | +
|
| 72 | + approval: |
| 73 | + if: needs.load-environment-config.outputs.requires_approval == 'true' |
| 74 | + needs: load-environment-config |
| 75 | + runs-on: ubuntu-latest |
| 76 | + environment: ${{ needs.load-environment-config.outputs.github_environment }} |
| 77 | + steps: |
| 78 | + - name: Wait for approval |
| 79 | + run: echo "Approval required for ${{ inputs.environment }} builds" |
| 80 | + |
| 81 | + build: |
| 82 | + needs: |
| 83 | + - load-environment-config |
| 84 | + - approval |
| 85 | + if: always() && (needs.approval.result == 'success' || needs.approval.result == 'skipped') |
| 86 | + strategy: |
| 87 | + matrix: |
| 88 | + platform: ${{ inputs.platform == 'both' && fromJSON('["android", "ios"]') || fromJSON(format('["{0}"]', inputs.platform)) }} |
| 89 | + runs-on: ${{ matrix.platform == 'ios' && 'macos-latest' || 'ubuntu-latest' }} |
| 90 | + environment: ${{ needs.load-environment-config.outputs.github_environment }} |
| 91 | + steps: |
| 92 | + - uses: actions/checkout@v4 |
| 93 | + |
| 94 | + - name: Setup Node.js |
| 95 | + uses: actions/setup-node@v4 |
| 96 | + with: |
| 97 | + node-version: '20' |
| 98 | + cache: 'yarn' |
| 99 | + |
| 100 | + - name: Install dependencies |
| 101 | + run: yarn install --immutable |
| 102 | + |
| 103 | + - name: Setup project |
| 104 | + run: yarn setup:github-ci |
| 105 | + |
| 106 | + - name: Apply environment configuration |
| 107 | + id: apply-config |
| 108 | + uses: actions/github-script@v7 |
| 109 | + with: |
| 110 | + script: | |
| 111 | + const { mergeConfigs } = require('./scripts/merge-config.js'); |
| 112 | + const env = '${{ inputs.environment }}'; |
| 113 | + const config = mergeConfigs(env); |
| 114 | +
|
| 115 | + // Set non-secret environment variables from merged config |
| 116 | + const outputs = {}; |
| 117 | +
|
| 118 | + // Server URLs |
| 119 | + Object.entries(config.servers).forEach(([key, value]) => { |
| 120 | + const envVar = key.toUpperCase(); |
| 121 | + outputs[envVar] = value; |
| 122 | + core.exportVariable(envVar, value); |
| 123 | + }); |
| 124 | +
|
| 125 | + // Feature flags |
| 126 | + Object.entries(config.features).forEach(([key, value]) => { |
| 127 | + const envVar = key.toUpperCase(); |
| 128 | + outputs[envVar] = value.toString(); |
| 129 | + core.exportVariable(envVar, value.toString()); |
| 130 | + }); |
| 131 | +
|
| 132 | + // Build configuration |
| 133 | + core.exportVariable('METAMASK_ENVIRONMENT', config.environment.name); |
| 134 | + core.exportVariable('METAMASK_BUILD_TYPE', '${{ inputs.build_type }}'); |
| 135 | +
|
| 136 | + // Output for other steps |
| 137 | + Object.entries(outputs).forEach(([key, value]) => { |
| 138 | + core.setOutput(key.toLowerCase().replace(/_/g, '_'), value); |
| 139 | + }); |
| 140 | +
|
| 141 | + - name: Set secrets as environment variables |
| 142 | + env: |
| 143 | + CONFIG_SECRETS: ${{ needs.load-environment-config.outputs.secrets_mapping }} |
| 144 | + run: | |
| 145 | + # Note: GitHub Actions doesn't allow dynamic secret access |
| 146 | + # Secrets must be configured in the GitHub environment and accessed directly |
| 147 | + # This step loads the mapping and sets env vars using the secrets context |
| 148 | + # For each secret in the mapping, we need to access it via ${{ secrets.SECRET_NAME }} |
| 149 | + # In a real implementation, you would need to explicitly list each secret |
| 150 | + # or use a composite action that handles this mapping |
| 151 | + echo "Secrets mapping loaded. Secrets should be configured in GitHub environment settings." |
| 152 | + echo "$CONFIG_SECRETS" | jq -r 'to_entries[] | "export \(.key)=\"${{ secrets.\(.value) }}\""' || true |
| 153 | +
|
| 154 | + - name: Build ${{ matrix.platform }} |
| 155 | + run: | |
| 156 | + ./scripts/build.sh ${{ matrix.platform }} ${{ inputs.build_type }} ${{ inputs.environment }} |
0 commit comments