@@ -6,6 +6,11 @@ name: Upload to TestFlight
66on :
77 workflow_dispatch :
88 inputs :
9+ source_branch :
10+ description : ' Branch, tag, or SHA to build'
11+ required : true
12+ type : string
13+ default : ' main'
914 environment :
1015 description : ' Build environment / track'
1116 required : true
3843 build_name : main-${{ inputs.environment || 'rc' }}
3944 platform : ios
4045 skip_version_bump : false
46+ source_branch : ${{ inputs.source_branch }}
4147 secrets : inherit
4248
4349 testflight-upload-summary :
4854 - uses : actions/checkout@v4
4955 with :
5056 fetch-depth : 0
57+ ref : ${{ inputs.source_branch }}
5158 - name : Display TestFlight upload summary
5259 run : |
5360 BUILD_VERSION=$(node -p "require('./package.json').version")
@@ -56,18 +63,19 @@ jobs:
5663 echo ""
5764 echo "| Field | Value |"
5865 echo "| --- | --- |"
66+ echo "| **Workflow ref** | ${{ github.ref_name }} (required for AWS) |"
67+ echo "| **Source branch** | ${{ inputs.source_branch }} |"
5968 echo "| **Build name** | main-${{ inputs.environment || 'rc' }} |"
6069 echo "| **Build version** | ${BUILD_VERSION} |"
6170 echo "| **TestFlight group** | ${{ inputs.testflight_group || 'MetaMask BETA & Release Candidates' }} |"
62- echo "| **Branch** | ${{ github.ref_name }} |"
6371 } >> "$GITHUB_STEP_SUMMARY"
6472
65- # Uses GitHub Environment "apple" for App Store Connect API secrets.
73+ # Pulls App Store Connect API keys from AWS Secrets Manager (OIDC).
74+ # Workflow must run from main; build uses inputs.source_branch.
6675 upload-ios-testflight :
6776 name : Upload iOS to TestFlight
6877 needs : [build, testflight-upload-summary]
6978 runs-on : ghcr.io/cirruslabs/macos-runner:sequoia-xl
70- environment : apple
7179 steps :
7280 - name : Checkout repository
7381 uses : actions/checkout@v4
@@ -97,22 +105,63 @@ jobs:
97105 case "$IPA" in /*) ABS="$IPA" ;; *) ABS="$PWD/$IPA" ;; esac
98106 echo "path=$ABS" >> "$GITHUB_OUTPUT"
99107
108+ - name : Configure AWS credentials
109+ uses : aws-actions/configure-aws-credentials@v4
110+ with :
111+ role-to-assume : ${{ secrets.AWS_ROLE_APPLE_TESTFLIGHT }}
112+ aws-region : ' us-east-2'
113+
114+ - name : Fetch Apple API keys from AWS Secrets Manager
115+ run : |
116+ echo "🔐 Fetching App Store Connect API keys from Secrets Manager..."
117+ secret_id="metamask-mobile-main-apple-api-keys"
118+ secret_json=$(aws secretsmanager get-secret-value \
119+ --region 'us-east-2' \
120+ --secret-id "$secret_id" \
121+ --query SecretString \
122+ --output text)
123+
124+ for key in APP_STORE_CONNECT_API_KEY_ISSUER_ID APP_STORE_CONNECT_API_KEY_KEY_ID; do
125+ value=$(echo "$secret_json" | jq -r --arg k "$key" '.[$k] // empty')
126+ if [ -z "$value" ]; then
127+ echo "::error::Missing key in secret: $key"
128+ exit 1
129+ fi
130+ echo "::add-mask::$value"
131+ echo "${key}=${value}" >> "$GITHUB_ENV"
132+ done
133+
134+ key=APP_STORE_CONNECT_API_KEY_KEY_CONTENT
135+ value=$(echo "$secret_json" | jq -r --arg k "$key" '.[$k] // empty')
136+ if [ -z "$value" ]; then
137+ echo "::error::Missing key in secret: $key"
138+ exit 1
139+ fi
140+ while IFS= read -r line || [ -n "$line" ]; do
141+ [ -n "$line" ] && echo "::add-mask::$line"
142+ done <<< "$(printf '%s\n' "$value")"
143+
144+ delim="APPLEP8$(openssl rand -hex 16)"
145+ {
146+ printf '%s<<%s\n' "$key" "$delim"
147+ printf '%s\n' "$value"
148+ printf '%s\n' "$delim"
149+ } >> "$GITHUB_ENV"
150+
151+ echo "✅ Apple API keys loaded from AWS"
152+
100153 - name: Setup App Store Connect API Key
101154 run: |
102155 bash scripts/setup-app-store-connect-api-key.sh \
103156 "$APP_STORE_CONNECT_API_KEY_ISSUER_ID" \
104157 "$APP_STORE_CONNECT_API_KEY_KEY_ID" \
105158 "$APP_STORE_CONNECT_API_KEY_KEY_CONTENT"
106- env :
107- APP_STORE_CONNECT_API_KEY_ISSUER_ID : ${{ secrets.APP_STORE_CONNECT_API_KEY_ISSUER_ID }}
108- APP_STORE_CONNECT_API_KEY_KEY_ID : ${{ secrets.APP_STORE_CONNECT_API_KEY_KEY_ID }}
109- APP_STORE_CONNECT_API_KEY_KEY_CONTENT : ${{ secrets.APP_STORE_CONNECT_API_KEY_KEY_CONTENT }}
110159
111160 - name: Upload to TestFlight
112161 run: |
113162 bash scripts/upload-to-testflight.sh \
114163 "github_actions_main-${{ inputs.environment || 'rc' }}" \
115- "${{ github.ref_name }}" \
164+ "${{ inputs.source_branch }}" \
116165 "${{ steps.ipa.outputs.path }}" \
117166 "${{ inputs.testflight_group || 'MetaMask BETA & Release Candidates' }}"
118167
0 commit comments