@@ -127,14 +127,34 @@ jobs:
127127 echo "ERROR: APP_STORE_CONNECT_KEY_ID is not set"
128128 exit 1
129129 fi
130+ echo "✅ APP_STORE_CONNECT_KEY_ID is set"
131+
130132 if [ -z "$APP_STORE_CONNECT_ISSUER_ID" ]; then
131133 echo "ERROR: APP_STORE_CONNECT_ISSUER_ID is not set"
132134 exit 1
133135 fi
136+ echo "✅ APP_STORE_CONNECT_ISSUER_ID is set"
137+
134138 if [ -z "$APP_STORE_CONNECT_API_KEY_BASE64" ]; then
135139 echo "ERROR: APP_STORE_CONNECT_API_KEY_BASE64 is not set"
136140 exit 1
137141 fi
142+ echo "✅ APP_STORE_CONNECT_API_KEY_BASE64 is set"
143+
144+ # Debug: Check the content characteristics
145+ echo "Debug: Checking base64 string characteristics..."
146+ echo "Length: $(echo -n "$APP_STORE_CONNECT_API_KEY_BASE64" | wc -c)"
147+ echo "First 10 chars: $(echo -n "$APP_STORE_CONNECT_API_KEY_BASE64" | head -c 10)..."
148+ echo "Last 10 chars: ...$(echo -n "$APP_STORE_CONNECT_API_KEY_BASE64" | tail -c 10)"
149+
150+ # Check if it contains valid base64 characters
151+ if echo "$APP_STORE_CONNECT_API_KEY_BASE64" | grep -qE '^[A-Za-z0-9+/]*={0,2}$'; then
152+ echo "✅ String contains valid base64 characters"
153+ else
154+ echo "⚠️ String may contain invalid base64 characters"
155+ # Show which characters are invalid
156+ echo "$APP_STORE_CONNECT_API_KEY_BASE64" | sed 's/[A-Za-z0-9+/=]//g' | od -c
157+ fi
138158
139159 # Create directory for API key
140160 mkdir -p ~/.appstoreconnect/private_keys
@@ -143,18 +163,58 @@ jobs:
143163 # Try different approaches to handle potential formatting issues
144164 KEY_PATH=~/.appstoreconnect/private_keys/AuthKey_${APP_STORE_CONNECT_KEY_ID}.p8
145165
166+ # Try to decode the base64 string
167+ DECODE_SUCCESS=false
168+
146169 # Method 1: Direct echo and decode
170+ echo "Trying method 1: base64 -d..."
147171 if echo "$APP_STORE_CONNECT_API_KEY_BASE64" | base64 -d > "$KEY_PATH" 2>/dev/null; then
148172 echo "✅ Successfully decoded API key using base64 -d"
173+ DECODE_SUCCESS=true
174+ fi
175+
149176 # 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"
177+ if [ "$DECODE_SUCCESS" = false ]; then
178+ echo "Trying method 2: base64 --decode..."
179+ if echo "$APP_STORE_CONNECT_API_KEY_BASE64" | base64 --decode > "$KEY_PATH" 2>/dev/null; then
180+ echo "✅ Successfully decoded API key using base64 --decode"
181+ DECODE_SUCCESS=true
182+ fi
183+ fi
184+
152185 # 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
186+ if [ "$DECODE_SUCCESS" = false ]; then
187+ echo "Trying method 3: removing whitespace first..."
188+ if echo "$APP_STORE_CONNECT_API_KEY_BASE64" | tr -d '\n\r ' | base64 -d > "$KEY_PATH" 2>/dev/null; then
189+ echo "✅ Successfully decoded API key after removing whitespace"
190+ DECODE_SUCCESS=true
191+ fi
192+ fi
193+
194+ # Method 4: Try assuming it's not base64 encoded at all (raw .p8 content)
195+ if [ "$DECODE_SUCCESS" = false ]; then
196+ echo "Trying method 4: treating as raw .p8 content..."
197+ if echo "$APP_STORE_CONNECT_API_KEY_BASE64" > "$KEY_PATH" 2>/dev/null; then
198+ # Check if it looks like a valid .p8 file (should start with -----BEGIN PRIVATE KEY-----)
199+ if grep -q "BEGIN PRIVATE KEY" "$KEY_PATH"; then
200+ echo "✅ Secret appears to be raw .p8 content, not base64 encoded"
201+ DECODE_SUCCESS=true
202+ else
203+ rm -f "$KEY_PATH"
204+ fi
205+ fi
206+ fi
207+
208+ if [ "$DECODE_SUCCESS" = false ]; then
156209 echo "ERROR: Failed to decode APP_STORE_CONNECT_API_KEY_BASE64"
157- echo "Please ensure the secret is properly base64 encoded"
210+ echo "The secret might be:"
211+ echo "1. Empty or containing only whitespace"
212+ echo "2. Incorrectly base64 encoded"
213+ echo "3. Already in .p8 format (not base64)"
214+ echo ""
215+ echo "To fix this, re-create the secret with:"
216+ echo " cat AuthKey_XXXXXX.p8 | base64 | tr -d '\\n' > base64_key.txt"
217+ echo "Then copy the contents of base64_key.txt to the secret"
158218 exit 1
159219 fi
160220
0 commit comments