Skip to content

Commit ad280c3

Browse files
katipallyCopilot
andcommitted
fix(ci): strip \r and ensure trailing \n in .p8 key file
CryptoKit's PEM parser rejects files with Windows-style CRLF line endings (\r\n). tr -d '\r' normalises to Unix LF before writing. Also ensures the file ends with exactly one \n (CryptoKit requires a trailing newline on the -----END PRIVATE KEY----- line). Added first/last line print for easier diagnosis on the next run. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent a00a80e commit ad280c3

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

.github/workflows/ios-testflight.yml

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,20 +122,29 @@ jobs:
122122
KEY_FILE=~/.appstoreconnect/private_keys/AuthKey_${API_KEY_ID}.p8
123123
124124
# 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.
126125
if printf '%s' "$API_KEY" | head -c 20 | grep -q "^-----BEGIN"; then
127-
printf '%s\n' "$API_KEY" > "$KEY_FILE"
126+
# Raw PEM — strip carriage returns (Windows \r\n → \n) then write.
127+
printf '%s' "$API_KEY" | tr -d '\r' > "$KEY_FILE"
128128
echo "Detected raw PEM format"
129129
else
130-
printf '%s' "$API_KEY" | base64 -D > "$KEY_FILE"
130+
# Base64-encoded .p8 — decode then strip carriage returns.
131+
printf '%s' "$API_KEY" | tr -d '\r ' | base64 -D > "$KEY_FILE"
131132
echo "Detected base64-encoded format, decoded successfully"
132133
fi
133134
135+
# Ensure file ends with a single newline (CryptoKit requires it)
136+
if [[ "$(tail -c 1 "$KEY_FILE" | xxd -p)" != "0a" ]]; then
137+
printf '\n' >> "$KEY_FILE"
138+
fi
139+
134140
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")"
141+
echo "::error::Written .p8 doesn't look like PEM."
136142
exit 1
137143
fi
138-
echo "API key validated: $(wc -c < "$KEY_FILE" | tr -d ' ') bytes"
144+
SIZE=$(wc -c < "$KEY_FILE" | tr -d ' ')
145+
FIRST=$(head -1 "$KEY_FILE")
146+
LAST=$(tail -1 "$KEY_FILE")
147+
echo "API key: ${SIZE} bytes | first: '${FIRST}' | last: '${LAST}'"
139148
140149
- name: Archive (Release)
141150
working-directory: DoomCoderCompanion

0 commit comments

Comments
 (0)