Skip to content

Commit cd391be

Browse files
Added TTY and options to stop the passphrase being prompted
Signed-off-by: Gary Bright <gary@mondoo.com>
1 parent a9c8358 commit cd391be

2 files changed

Lines changed: 29 additions & 14 deletions

File tree

.github/workflows/release.yml

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ jobs:
5757

5858
- name: "Setup GPG Key"
5959
run: |
60+
# Configure GPG for CI environment
61+
export GPG_TTY=$(tty)
62+
echo "GPG_TTY=$GPG_TTY" >> $GITHUB_ENV
63+
6064
# Write key to temp file
6165
gpgkey="$(mktemp -t gpgkey.XXX)"
6266
base64 -d <<<"$GPG_KEY" > "$gpgkey"
@@ -73,9 +77,20 @@ jobs:
7377
file "$gpgkey" || true
7478
fi
7579
76-
# Import the key
80+
# Configure GPG agent for non-interactive use
81+
echo "=== Configuring GPG Agent ==="
82+
mkdir -p ~/.gnupg
83+
chmod 700 ~/.gnupg
84+
echo "pinentry-mode loopback" >> ~/.gnupg/gpg.conf
85+
echo "use-agent" >> ~/.gnupg/gpg.conf
86+
echo "batch" >> ~/.gnupg/gpg.conf
87+
88+
# Start gpg-agent if needed
89+
gpg-agent --daemon --allow-loopback-pinentry --default-cache-ttl 7200 || true
90+
91+
# Import the key with passphrase
7792
echo "=== Importing GPG Key ==="
78-
if ! gpg --batch --import "$gpgkey"; then
93+
if ! DISPLAY="" gpg --batch --yes --pinentry-mode=loopback --passphrase="$GPG_PASSPHRASE" --import "$gpgkey"; then
7994
echo "Error: Failed to import GPG key"
8095
echo "Key file size: $(wc -c < "$gpgkey")"
8196
echo "First few bytes (hex): $(hexdump -C "$gpgkey" | head -3)"
@@ -98,18 +113,17 @@ jobs:
98113
echo "Successfully extracted key ID: $KEY_ID"
99114
echo "GPG_FINGERPRINT=$KEY_ID" >> $GITHUB_ENV
100115
101-
# Verify key can be used for signing
102-
echo "=== Verifying Key ==="
103-
if ! gpg --list-secret-keys "$KEY_ID" >/dev/null 2>&1; then
104-
echo "Error: Key $KEY_ID not found in secret keyring"
105-
exit 1
106-
fi
116+
# Test signing to verify passphrase works
117+
echo "=== Testing GPG Signing ==="
118+
echo "test" | DISPLAY="" gpg --batch --yes --pinentry-mode=loopback --passphrase="$GPG_PASSPHRASE" --armor --sign --local-user "$KEY_ID" > /dev/null
119+
echo "GPG signing test successful"
107120
108121
# Clean up temp file
109122
rm "$gpgkey"
110123
echo "GPG key setup completed successfully"
111124
env:
112125
GPG_KEY: "${{ secrets.GPG_KEY }}"
126+
GPG_PASSPHRASE: "${{ secrets.GPG_PASSPHRASE }}"
113127

114128
- name: Run GoReleaser
115129
uses: goreleaser/goreleaser-action@e435ccd777264be153ace6237001ef4d979d3a7a # v6.4.0
@@ -125,6 +139,7 @@ jobs:
125139
# GitHub sets the GITHUB_TOKEN secret automatically.
126140
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
127141
NFPM_DEFAULT_RPM_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
142+
GPG_TTY: ${{ env.GPG_TTY }}
128143

129144
- name: Upload artifacts
130145
if: ${{ inputs.upload-artifacts == true }}

.goreleaser.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ builds:
1919
ldflags:
2020
- '-s -w -X main.version={{.Version}} -X main.commit={{.Commit}}'
2121
goos:
22-
- freebsd
23-
- windows
22+
# - freebsd
23+
# - windows
2424
- linux
25-
- darwin
25+
# - darwin
2626
goarch:
2727
- amd64
28-
- '386'
29-
- arm
30-
- arm64
28+
# - '386'
29+
# - arm
30+
# - arm64
3131
ignore:
3232
- goos: darwin
3333
goarch: '386'

0 commit comments

Comments
 (0)