Skip to content

Commit 414fe27

Browse files
committed
fix: improve base64 decoding robustness in release pipeline
- Added validation for all required environment variables - Implemented multiple base64 decoding methods as fallback - Added automatic whitespace/newline removal if needed - Added file verification to ensure API key was properly created - Better error messages for debugging This handles potential issues with: - Different base64 command flags (-d vs --decode) - Whitespace or newline characters in the secret - Empty or missing secrets
1 parent 6ccfa96 commit 414fe27

File tree

1 file changed

+50
-3
lines changed

1 file changed

+50
-3
lines changed

.github/workflows/release.yml

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,61 @@ jobs:
122122
APP_STORE_CONNECT_ISSUER_ID: ${{ secrets.APP_STORE_CONNECT_ISSUER_ID }}
123123
APP_STORE_CONNECT_API_KEY_BASE64: ${{ secrets.APP_STORE_CONNECT_API_KEY_BASE64 }}
124124
run: |
125+
# Debug: Check if environment variables are set
126+
if [ -z "$APP_STORE_CONNECT_KEY_ID" ]; then
127+
echo "ERROR: APP_STORE_CONNECT_KEY_ID is not set"
128+
exit 1
129+
fi
130+
if [ -z "$APP_STORE_CONNECT_ISSUER_ID" ]; then
131+
echo "ERROR: APP_STORE_CONNECT_ISSUER_ID is not set"
132+
exit 1
133+
fi
134+
if [ -z "$APP_STORE_CONNECT_API_KEY_BASE64" ]; then
135+
echo "ERROR: APP_STORE_CONNECT_API_KEY_BASE64 is not set"
136+
exit 1
137+
fi
138+
139+
# Create directory for API key
125140
mkdir -p ~/.appstoreconnect/private_keys
126-
echo "$APP_STORE_CONNECT_API_KEY_BASE64" | base64 --decode > ~/.appstoreconnect/private_keys/AuthKey_${APP_STORE_CONNECT_KEY_ID}.p8
127-
chmod 600 ~/.appstoreconnect/private_keys/AuthKey_${APP_STORE_CONNECT_KEY_ID}.p8
141+
142+
# Decode base64 with better error handling
143+
# Try different approaches to handle potential formatting issues
144+
KEY_PATH=~/.appstoreconnect/private_keys/AuthKey_${APP_STORE_CONNECT_KEY_ID}.p8
145+
146+
# Method 1: Direct echo and decode
147+
if echo "$APP_STORE_CONNECT_API_KEY_BASE64" | base64 -d > "$KEY_PATH" 2>/dev/null; then
148+
echo "✅ Successfully decoded API key using base64 -d"
149+
# Method 2: Try with --decode flag (macOS)
150+
elif echo "$APP_STORE_CONNECT_API_KEY_BASE64" | base64 --decode > "$KEY_PATH" 2>/dev/null; then
151+
echo "✅ Successfully decoded API key using base64 --decode"
152+
# Method 3: Remove potential whitespace/newlines and try again
153+
elif echo "$APP_STORE_CONNECT_API_KEY_BASE64" | tr -d '\n\r ' | base64 -d > "$KEY_PATH" 2>/dev/null; then
154+
echo "✅ Successfully decoded API key after removing whitespace"
155+
else
156+
echo "ERROR: Failed to decode APP_STORE_CONNECT_API_KEY_BASE64"
157+
echo "Please ensure the secret is properly base64 encoded"
158+
exit 1
159+
fi
160+
161+
# Verify the file was created and has content
162+
if [ ! -f "$KEY_PATH" ]; then
163+
echo "ERROR: API key file was not created"
164+
exit 1
165+
fi
166+
167+
if [ ! -s "$KEY_PATH" ]; then
168+
echo "ERROR: API key file is empty"
169+
exit 1
170+
fi
171+
172+
# Set proper permissions
173+
chmod 600 "$KEY_PATH"
174+
echo "✅ API key file created successfully at $KEY_PATH"
128175
129176
# Set environment variables for Fastlane
130177
echo "APP_STORE_CONNECT_API_KEY_KEY_ID=$APP_STORE_CONNECT_KEY_ID" >> $GITHUB_ENV
131178
echo "APP_STORE_CONNECT_API_KEY_ISSUER_ID=$APP_STORE_CONNECT_ISSUER_ID" >> $GITHUB_ENV
132-
echo "APP_STORE_CONNECT_API_KEY_KEY=~/.appstoreconnect/private_keys/AuthKey_${APP_STORE_CONNECT_KEY_ID}.p8" >> $GITHUB_ENV
179+
echo "APP_STORE_CONNECT_API_KEY_KEY=$KEY_PATH" >> $GITHUB_ENV
133180
134181
- name: Run Fastlane Match
135182
env:

0 commit comments

Comments
 (0)