Skip to content

Commit a00a80e

Browse files
katipallyCopilot
andcommitted
fix(ci): auto-detect .p8 PEM vs base64; use macOS base64 -D flag
The API key write step now handles both formats: - If APP_STORE_CONNECT_PRIVATE_KEY starts with '-----BEGIN' → raw PEM, written directly. - Otherwise → assumed base64-encoded, decoded with base64 -D (macOS BSD flag, equivalent to --decode on GNU). Validation step confirms the final file looks like PEM before proceeding. Also switches IOS_DISTRIBUTION_CERTIFICATE decode to base64 -D for consistency on macOS runners. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent a7adeb7 commit a00a80e

1 file changed

Lines changed: 18 additions & 4 deletions

File tree

.github/workflows/ios-testflight.yml

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ jobs:
9494
security unlock-keychain -p "$KEYCHAIN_PASSWORD" "$KEYCHAIN_PATH"
9595
security list-keychains -d user -s "$KEYCHAIN_PATH" $(security list-keychains -d user | tr -d '"')
9696
97-
echo "$DIST_CERT_B64" | base64 --decode > "$RUNNER_TEMP/dist.p12"
97+
echo "$DIST_CERT_B64" | base64 -D > "$RUNNER_TEMP/dist.p12"
9898
security import "$RUNNER_TEMP/dist.p12" \
9999
-k "$KEYCHAIN_PATH" \
100100
-P "$DIST_CERT_PASSWORD" \
@@ -119,9 +119,23 @@ jobs:
119119
exit 1
120120
fi
121121
mkdir -p ~/.appstoreconnect/private_keys
122-
# .p8 is a text/PEM file — write directly, no base64 needed.
123-
printf '%s' "$API_KEY" > ~/.appstoreconnect/private_keys/AuthKey_${API_KEY_ID}.p8
124-
echo "API key written: $(wc -c < ~/.appstoreconnect/private_keys/AuthKey_${API_KEY_ID}.p8) bytes"
122+
KEY_FILE=~/.appstoreconnect/private_keys/AuthKey_${API_KEY_ID}.p8
123+
124+
# Auto-detect: raw PEM (starts with -----BEGIN) or base64-encoded.
125+
# Both formats are accepted so users don't have to re-set the secret.
126+
if printf '%s' "$API_KEY" | head -c 20 | grep -q "^-----BEGIN"; then
127+
printf '%s\n' "$API_KEY" > "$KEY_FILE"
128+
echo "Detected raw PEM format"
129+
else
130+
printf '%s' "$API_KEY" | base64 -D > "$KEY_FILE"
131+
echo "Detected base64-encoded format, decoded successfully"
132+
fi
133+
134+
if ! head -c 20 "$KEY_FILE" | grep -q "^-----BEGIN"; then
135+
echo "::error::Written .p8 doesn't look like PEM. First 20 chars: $(head -c 20 "$KEY_FILE")"
136+
exit 1
137+
fi
138+
echo "API key validated: $(wc -c < "$KEY_FILE" | tr -d ' ') bytes"
125139
126140
- name: Archive (Release)
127141
working-directory: DoomCoderCompanion

0 commit comments

Comments
 (0)