|
| 1 | +name: Push OTA Update (Test) |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + pr_number: |
| 7 | + description: 'Pull request number to publish' |
| 8 | + required: true |
| 9 | + type: string |
| 10 | + base_branch: |
| 11 | + description: 'Base branch ref to compare fingerprints against (e.g., main)' |
| 12 | + required: true |
| 13 | + type: string |
| 14 | + |
| 15 | +permissions: |
| 16 | + contents: read |
| 17 | + id-token: write |
| 18 | + |
| 19 | +env: |
| 20 | + TARGET_PR_NUMBER: ${{ inputs.pr_number }} |
| 21 | + BASE_BRANCH_REF: ${{ inputs.base_branch }} |
| 22 | + |
| 23 | +jobs: |
| 24 | + fingerprint-comparison: |
| 25 | + name: Compare Expo Fingerprints |
| 26 | + runs-on: ubuntu-latest |
| 27 | + outputs: |
| 28 | + branch_fingerprint: ${{ steps.branch_fingerprint.outputs.fingerprint }} |
| 29 | + main_fingerprint: ${{ steps.main_fingerprint.outputs.fingerprint }} |
| 30 | + fingerprints_equal: ${{ steps.compare.outputs.equal }} |
| 31 | + steps: |
| 32 | + - name: Checkout target PR branch |
| 33 | + uses: actions/checkout@v4 |
| 34 | + with: |
| 35 | + ref: refs/pull/${{ env.TARGET_PR_NUMBER }}/head |
| 36 | + fetch-depth: 0 |
| 37 | + |
| 38 | + - name: Checkout base branch snapshot |
| 39 | + uses: actions/checkout@v4 |
| 40 | + with: |
| 41 | + ref: ${{ env.BASE_BRANCH_REF }} |
| 42 | + path: main |
| 43 | + fetch-depth: 0 |
| 44 | + |
| 45 | + - name: Setup Node.js |
| 46 | + uses: actions/setup-node@v4 |
| 47 | + with: |
| 48 | + node-version: '20' |
| 49 | + cache: 'yarn' |
| 50 | + |
| 51 | + - name: Install dependencies (workflow branch) |
| 52 | + run: | |
| 53 | + echo "📦 Installing dependencies for current branch..." |
| 54 | + yarn install --immutable |
| 55 | +
|
| 56 | + - name: Generate fingerprint (workflow branch) |
| 57 | + id: branch_fingerprint |
| 58 | + run: | |
| 59 | + echo "🧬 Generating fingerprint for current branch..." |
| 60 | + FINGERPRINT=$(yarn fingerprint:generate) |
| 61 | + echo "fingerprint=$FINGERPRINT" >> "$GITHUB_OUTPUT" |
| 62 | + echo "Target PR fingerprint: $FINGERPRINT" |
| 63 | + echo "Writing detailed fingerprint file to fingerprint-pr.json" |
| 64 | + npx @expo/fingerprint ./ > fingerprint-pr.json |
| 65 | +
|
| 66 | + - name: Install dependencies (base branch) |
| 67 | + working-directory: main |
| 68 | + run: | |
| 69 | + echo "📦 Installing dependencies for base branch snapshot (${BASE_BRANCH_REF})..." |
| 70 | + yarn install --immutable |
| 71 | +
|
| 72 | + - name: Generate fingerprint (base branch) |
| 73 | + id: main_fingerprint |
| 74 | + working-directory: main |
| 75 | + run: | |
| 76 | + echo "🧬 Generating fingerprint for base branch (${BASE_BRANCH_REF})..." |
| 77 | + FINGERPRINT=$(yarn fingerprint:generate) |
| 78 | + echo "fingerprint=$FINGERPRINT" >> "$GITHUB_OUTPUT" |
| 79 | + echo "Base branch fingerprint: $FINGERPRINT" |
| 80 | + echo "Writing detailed fingerprint file to ../fingerprint-base.json" |
| 81 | + npx @expo/fingerprint ./ > ../fingerprint-base.json |
| 82 | +
|
| 83 | + - name: Compare fingerprints |
| 84 | + id: compare |
| 85 | + env: |
| 86 | + BRANCH_FP: ${{ steps.branch_fingerprint.outputs.fingerprint }} |
| 87 | + MAIN_FP: ${{ steps.main_fingerprint.outputs.fingerprint }} |
| 88 | + run: | |
| 89 | + if [ -z "$BRANCH_FP" ] || [ -z "$MAIN_FP" ]; then |
| 90 | + echo "❌ Fingerprint generation failed." >&2 |
| 91 | + exit 1 |
| 92 | + fi |
| 93 | +
|
| 94 | + echo "Target PR fingerprint: $BRANCH_FP" |
| 95 | + echo "Base branch fingerprint: $MAIN_FP" |
| 96 | +
|
| 97 | + if [ "$BRANCH_FP" = "$MAIN_FP" ]; then |
| 98 | + echo "✅ Fingerprints match. No native changes detected." |
| 99 | + echo "equal=true" >> "$GITHUB_OUTPUT" |
| 100 | + else |
| 101 | + echo "⚠️ Fingerprints differ. Native changes detected." |
| 102 | + echo "equal=false" >> "$GITHUB_OUTPUT" |
| 103 | + if [ -f fingerprint-base.json ] && [ -f fingerprint-pr.json ]; then |
| 104 | + echo "Fingerprint differences:" |
| 105 | + npx @expo/fingerprint ./ fingerprint-base.json fingerprint-pr.json || true |
| 106 | + else |
| 107 | + echo "Detailed fingerprint files not found; skipping diff." |
| 108 | + fi |
| 109 | + fi |
| 110 | +
|
| 111 | + - name: Record fingerprint summary |
| 112 | + env: |
| 113 | + BRANCH_FP: ${{ steps.branch_fingerprint.outputs.fingerprint }} |
| 114 | + MAIN_FP: ${{ steps.main_fingerprint.outputs.fingerprint }} |
| 115 | + MATCHES: ${{ steps.compare.outputs.equal }} |
| 116 | + TARGET_PR_NUMBER: ${{ env.TARGET_PR_NUMBER }} |
| 117 | + BASE_BRANCH_REF: ${{ env.BASE_BRANCH_REF }} |
| 118 | + run: | |
| 119 | + { |
| 120 | + echo "### Expo Fingerprint Comparison" |
| 121 | + echo "" |
| 122 | + echo "- Target PR (#$TARGET_PR_NUMBER) fingerprint: \`$BRANCH_FP\`" |
| 123 | + echo "- Base branch (\`$BASE_BRANCH_REF\`) fingerprint: \`$MAIN_FP\`" |
| 124 | + echo "- Match: \`$MATCHES\`" |
| 125 | + } >> "$GITHUB_STEP_SUMMARY" |
| 126 | +
|
| 127 | + approval: |
| 128 | + name: Require OTA Update Approval |
| 129 | + needs: fingerprint-comparison |
| 130 | + if: ${{ needs.fingerprint-comparison.outputs.fingerprints_equal == 'true' }} |
| 131 | + runs-on: ubuntu-latest |
| 132 | + steps: |
| 133 | + - name: Await approval from mobile platform team |
| 134 | + uses: op5dev/require-team-approval@dfd7b8b9a88bf82a955c103f7e19642b0411aecd |
| 135 | + with: |
| 136 | + team: mobile-platform |
| 137 | + pr-number: ${{ env.TARGET_PR_NUMBER }} |
| 138 | + token: ${{ secrets.METAMASK_MOBILE_ORG_READ_TOKEN }} |
| 139 | + |
| 140 | + push-update: |
| 141 | + name: Push EAS Update |
| 142 | + runs-on: ubuntu-latest |
| 143 | + environment: expo-update |
| 144 | + needs: |
| 145 | + - fingerprint-comparison |
| 146 | + - approval |
| 147 | + if: ${{ needs.fingerprint-comparison.outputs.fingerprints_equal == 'true' }} |
| 148 | + env: |
| 149 | + EXPO_TOKEN: ${{ secrets.EXPO_TOKEN }} |
| 150 | + EXPO_PROJECT_ID: ${{ secrets.EXPO_PROJECT_ID }} |
| 151 | + EXPO_CHANNEL: ${{ vars.EXPO_CHANNEL }} |
| 152 | + |
| 153 | + steps: |
| 154 | + - name: Checkout repository |
| 155 | + uses: actions/checkout@v4 |
| 156 | + with: |
| 157 | + ref: refs/pull/${{ env.TARGET_PR_NUMBER }}/head |
| 158 | + fetch-depth: 0 |
| 159 | + |
| 160 | + - name: Setup Node.js |
| 161 | + uses: actions/setup-node@v4 |
| 162 | + with: |
| 163 | + node-version: '20' |
| 164 | + cache: 'yarn' |
| 165 | + |
| 166 | + - name: Install dependencies |
| 167 | + run: | |
| 168 | + echo "📦 Installing dependencies..." |
| 169 | + yarn install --immutable |
| 170 | +
|
| 171 | + - name: Setup project |
| 172 | + run: | |
| 173 | + echo "🔧 Running setup for GitHub CI..." |
| 174 | + yarn setup:github-ci |
| 175 | +
|
| 176 | + - name: Display configuration |
| 177 | + run: | |
| 178 | + TARGET_RUNTIME_VERSION=$(node -p "require('./package.json').version") |
| 179 | + TARGET_PROJECT_ID=$(node -p "require('./ota.config.js').PROJECT_ID") |
| 180 | + echo "🔧 Configuration:" |
| 181 | + echo " Channel: ${EXPO_CHANNEL:-<not set>}" |
| 182 | + echo " Channel (vars.EXPO_CHANNEL): ${{ vars.EXPO_CHANNEL }}" |
| 183 | + echo " Message: test eas update workflow" |
| 184 | + echo " Runtime Version (target): ${TARGET_RUNTIME_VERSION}" |
| 185 | + # Fingerprint comparison temporarily disabled |
| 186 | + echo "" |
| 187 | + echo "📱 Project Info:" |
| 188 | + echo " Project ID (target branch): ${TARGET_PROJECT_ID}" |
| 189 | + echo " EXPO_PROJECT_ID (from secrets): $EXPO_PROJECT_ID" |
| 190 | + echo " EXPO_TOKEN (from secrets): $EXPO_TOKEN" |
| 191 | +
|
| 192 | + - name: Prepare Expo update signing key |
| 193 | + env: |
| 194 | + EXPO_KEY_PRIV: ${{ secrets.EXPO_KEY_PRIV }} |
| 195 | + run: | |
| 196 | + if [ -z "${EXPO_KEY_PRIV}" ]; then |
| 197 | + echo "::error title=Missing EXPO_KEY_PRIV::EXPO_KEY_PRIV secret is not configured. Cannot sign update." >&2 |
| 198 | + exit 1 |
| 199 | + fi |
| 200 | + mkdir -p keys |
| 201 | + echo "Writing Expo private key to ./keys/private-key.pem" |
| 202 | + printf '%s' "${EXPO_KEY_PRIV}" > keys/private-key.pem |
| 203 | +
|
| 204 | + - name: Push EAS Update |
| 205 | + env: |
| 206 | + # Skip linting during Metro transform in CI (linting already done separately) |
| 207 | + SKIP_TRANSFORM_LINT: 'true' |
| 208 | + # Increase Node heap to avoid OOM during Expo export in CI |
| 209 | + NODE_OPTIONS: '--max_old_space_size=8192' |
| 210 | + # Disable LavaMoat sandbox to prevent duplicate bundle executions in CI |
| 211 | + EXPO_NO_LAVAMOAT: '1' |
| 212 | + run: | |
| 213 | + echo "🚀 Publishing EAS update..." |
| 214 | +
|
| 215 | + if [ -z "${EXPO_CHANNEL}" ]; then |
| 216 | + echo "::error title=Missing EXPO_CHANNEL::EXPO_CHANNEL environment variable is not set. Cannot publish update." >&2 |
| 217 | + exit 1 |
| 218 | + fi |
| 219 | +
|
| 220 | + if [ ! -f keys/private-key.pem ]; then |
| 221 | + echo "::error title=Missing signing key::keys/private-key.pem not found. Ensure the signing key step ran successfully." >&2 |
| 222 | + exit 1 |
| 223 | + fi |
| 224 | +
|
| 225 | + echo "ℹ️ Git head: $(git rev-parse HEAD)" |
| 226 | + echo "ℹ️ Checking for eas script in package.json..." |
| 227 | + if ! grep -q '"eas": "eas"' package.json; then |
| 228 | + echo "::error title=Missing eas script::package.json does not include an \"eas\" script. Commit hash: $(git rev-parse HEAD)." >&2 |
| 229 | + exit 1 |
| 230 | + fi |
| 231 | +
|
| 232 | + echo "ℹ️ Available yarn scripts containing eas:" |
| 233 | + yarn run --json | grep '"name":"eas"' || true |
| 234 | +
|
| 235 | + yarn run eas update \ |
| 236 | + --channel "${EXPO_CHANNEL}" \ |
| 237 | + --private-key-path "./keys/private-key.pem" \ |
| 238 | + --message "test eas update workflow" \ |
| 239 | + --non-interactive |
| 240 | +
|
| 241 | + - name: Update summary |
| 242 | + if: success() |
| 243 | + run: | |
| 244 | + { |
| 245 | + echo "### ✅ EAS Update Published Successfully" |
| 246 | + echo |
| 247 | + echo "**Channel:** \`${EXPO_CHANNEL:-<not set>}\`" |
| 248 | + echo "**Message:** test eas update workflow" |
| 249 | + echo |
| 250 | + echo "Users on the \`${EXPO_CHANNEL:-<not set>}\` channel will receive this update on their next app launch." |
| 251 | + } >> "$GITHUB_STEP_SUMMARY" |
| 252 | +
|
| 253 | + - name: Update summary on failure |
| 254 | + if: failure() |
| 255 | + run: | |
| 256 | + { |
| 257 | + echo "### ❌ EAS Update Failed" |
| 258 | + echo |
| 259 | + echo "Check the logs above for error details." |
| 260 | + } >> "$GITHUB_STEP_SUMMARY" |
| 261 | +
|
| 262 | + fingerprint-mismatch: |
| 263 | + name: Fingerprint Mismatch Guard |
| 264 | + needs: fingerprint-comparison |
| 265 | + if: ${{ needs.fingerprint-comparison.outputs.fingerprints_equal != 'true' }} |
| 266 | + runs-on: ubuntu-latest |
| 267 | + steps: |
| 268 | + - name: Fail on native changes |
| 269 | + run: | |
| 270 | + echo "::error title=Fingerprint mismatch::Current branch fingerprint differs from main. Native changes detected; aborting workflow." |
| 271 | + echo "Current fingerprint: ${{ needs.fingerprint-comparison.outputs.branch_fingerprint }}" |
| 272 | + echo "Main fingerprint: ${{ needs.fingerprint-comparison.outputs.main_fingerprint }}" |
| 273 | + exit 1 |
0 commit comments