@@ -254,12 +254,7 @@ jobs:
254254 env :
255255 GPG_PRIVATE_KEY : ${{ secrets.GPG_PRIVATE_KEY }}
256256 GPG_FINGERPRINT : ${{ secrets.GPG_FINGERPRINT }}
257- GPG_PASSPHRASE : ${{ secrets.GPG_PASSPHRASE }}
258257 run : |
259- # GPG_PASSPHRASE is optional - subkey may not have a passphrase
260- if [ -z "$GPG_PASSPHRASE" ]; then
261- echo "ℹ GPG_PASSPHRASE not set - assuming subkey has no passphrase"
262- fi
263258 # Install gnupg2 if not already available
264259 sudo apt-get update && sudo apt-get install -y gnupg2 || true
265260
@@ -291,20 +286,10 @@ jobs:
291286 gpg-agent --daemon --allow-loopback-pinentry > /dev/null 2>&1 || true
292287 sleep 2 # Give gpg-agent time to start
293288
294- # Import the subkey
295- # Write key to temp file (key data is okay, but passphrase never touches disk)
289+ # Import the subkey (no passphrase required)
296290 KEY_FILE=$(mktemp)
297291 echo "$GPG_PRIVATE_KEY" > "$KEY_FILE"
298-
299- # Import the key - handle both with and without passphrase
300- if [ -n "$GPG_PASSPHRASE" ]; then
301- echo "$GPG_PASSPHRASE" | gpg --batch --yes --pinentry-mode loopback --passphrase-fd 0 --import "$KEY_FILE"
302- else
303- # No passphrase - import directly
304- gpg --batch --yes --import "$KEY_FILE"
305- fi
306-
307- # Clean up temp file (only contains key data, not passphrase)
292+ gpg --batch --yes --import "$KEY_FILE"
308293 rm -f "$KEY_FILE"
309294
310295 # Trust the key (required for signing)
@@ -316,53 +301,20 @@ jobs:
316301 # Verify key is available
317302 gpg --list-secret-keys --keyid-format LONG
318303
319- # Preset passphrase in gpg-agent only if passphrase is provided
320- # If subkey has no passphrase, skip this step
321- if [ -n "$GPG_PASSPHRASE" ]; then
322- # Extract keygrip - try both sec (master key) and ssb (subkey) lines
323- KEYGRIP=$(gpg --list-secret-keys --with-keygrip --keyid-format LONG "$FINGERPRINT_UPPER" 2>/dev/null | grep -E "^sec|^ssb" | head -1 | awk '{print $NF}')
324- if [ -z "$KEYGRIP" ]; then
325- # Try alternative method - get keygrip from the subkey line
326- KEYGRIP=$(gpg --list-secret-keys --with-keygrip --keyid-format LONG "$FINGERPRINT_UPPER" 2>/dev/null | grep -A5 "^sec" | grep "Keygrip" | head -1 | awk '{print $3}')
327- fi
328-
329- if [ -n "$KEYGRIP" ] && [ ${#KEYGRIP} -eq 40 ]; then
330- echo "$GPG_PASSPHRASE" | gpg-preset-passphrase --preset "$KEYGRIP" 2>&1
331- if [ $? -eq 0 ]; then
332- echo "✓ Passphrase preset in gpg-agent for keygrip: $KEYGRIP"
333- else
334- echo "⚠ Warning: Failed to preset passphrase for keygrip: $KEYGRIP"
335- fi
336- else
337- echo "⚠ Warning: Could not find valid keygrip for fingerprint $FINGERPRINT_UPPER"
338- fi
339- else
340- echo "ℹ No passphrase provided - subkey should work without passphrase"
341- fi
342-
343- # Verify gpg-agent is running and can sign
304+ # Verify signing works (subkey has no passphrase)
344305 echo "test" | gpg --batch --no-tty --pinentry-mode loopback --sign --local-user "$FINGERPRINT_UPPER" -o /dev/null 2>&1 && echo "✓ Test signing successful" || echo "⚠ Test signing failed"
345306
346- # Test signing capability (GoReleaser will test this anyway, but verify key is importable)
347- # Note: We skip actual signing test here since --passphrase-fd consumes stdin
348- # GoReleaser uses --passphrase flag directly, which works differently
349307 echo "✓ GPG key imported successfully"
350308
351309 - name : Verify GPG setup before GoReleaser
352310 env :
353311 GPG_FINGERPRINT : ${{ secrets.GPG_FINGERPRINT }}
354- GPG_PASSPHRASE : ${{ secrets.GPG_PASSPHRASE }}
355312 run : |
356- echo "Verifying GPG environment variables ..."
313+ echo "Verifying GPG setup ..."
357314 echo "GPG_FINGERPRINT length: ${#GPG_FINGERPRINT}"
358- echo "GPG_PASSPHRASE length: ${#GPG_PASSPHRASE:-0}"
359315 gpg --list-secret-keys --keyid-format LONG
360- # Test signing - handle both with and without passphrase
361- if [ -n "$GPG_PASSPHRASE" ]; then
362- echo "test" | gpg --batch --yes --no-tty --pinentry-mode loopback --passphrase "$GPG_PASSPHRASE" --local-user "$GPG_FINGERPRINT" --sign -o /tmp/test.sig - 2>&1 && echo "✓ Test signing successful (with passphrase)" || echo "⚠ Test signing failed"
363- else
364- echo "test" | gpg --batch --yes --no-tty --pinentry-mode loopback --local-user "$GPG_FINGERPRINT" --sign -o /tmp/test.sig - 2>&1 && echo "✓ Test signing successful (no passphrase)" || echo "⚠ Test signing failed"
365- fi
316+ # Test signing (subkey has no passphrase)
317+ echo "test" | gpg --batch --yes --no-tty --pinentry-mode loopback --local-user "$GPG_FINGERPRINT" --sign -o /tmp/test.sig - 2>&1 && echo "✓ Test signing successful" || echo "⚠ Test signing failed"
366318 rm -f /tmp/test.sig
367319
368320 - name : Run GoReleaser
@@ -375,9 +327,7 @@ jobs:
375327 env :
376328 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
377329 GPG_FINGERPRINT : ${{ secrets.GPG_FINGERPRINT }}
378- GPG_PASSPHRASE : ${{ secrets.GPG_PASSPHRASE }}
379330 GPG_TTY : $(tty)
380- # GPG_PASSPHRASE is optional - if empty, GoReleaser won't use --passphrase flag
381331
382332 # terraform-provider-release:
383333 # needs: [release]
0 commit comments