Skip to content

Commit 52aacba

Browse files
committed
Enable GoReleaser with GPG signing for all artifacts
- Updated .goreleaser.yml to sign checksums and archives with passphrase support - Enabled release job in GitHub Actions with GPG subkey import - Configured non-interactive GPG signing with loopback pinentry - Added signing test before running GoReleaser
1 parent cf63c46 commit 52aacba

File tree

2 files changed

+80
-25
lines changed

2 files changed

+80
-25
lines changed

.github/workflows/main.yml

Lines changed: 63 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -193,32 +193,70 @@ jobs:
193193
else
194194
DOCKER_IMAGE=${{ matrix.docker_image }} go test -tags=testcontainers -v ./mysql/... -run WithTestcontainers -timeout=30m
195195
fi
196-
# DISABLED to figure out GPG signing issue on Github Actions
197-
# possibly due to lack of TTY inside docker?
198-
# release:
199-
# name: Release
200-
# needs: [tests]
201-
# # Can't use non-semvar for the testing tag
202-
# # https://github.com/orgs/goreleaser/discussions/3708
203-
# if: ( startsWith( github.ref, 'refs/tags/v' ) ||
204-
# startsWith(github.ref, 'refs/tags/v0.0.0-rc') )
205-
# runs-on: ubuntu-22.04
206-
# steps:
207-
# - name: Checkout Git repo
208-
# uses: actions/checkout@v4
196+
release:
197+
name: Release
198+
needs: [tests]
199+
# Can't use non-semvar for the testing tag
200+
# https://github.com/orgs/goreleaser/discussions/3708
201+
if: ( startsWith( github.ref, 'refs/tags/v' ) ||
202+
startsWith(github.ref, 'refs/tags/v0.0.0-rc') )
203+
runs-on: ubuntu-22.04
204+
permissions:
205+
contents: write # Required for creating releases
206+
steps:
207+
- name: Checkout Git repo
208+
uses: actions/checkout@v4
209+
with:
210+
fetch-depth: 0 # Full history needed for changelog
209211

210-
# # Goreleaser
211-
# - name: Set up Go
212-
# uses: actions/setup-go@v4
213-
# - name: Run GoReleaser
214-
# uses: goreleaser/goreleaser-action@v6
215-
# with:
216-
# distribution: goreleaser
217-
# version: '~> v2'
218-
# # Run goreleaser and ignore non-committed files (downloaded artifacts)
219-
# args: release --clean --skip=validate --verbose
220-
# env:
221-
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
212+
- name: Set up Go
213+
uses: actions/setup-go@v4
214+
with:
215+
go-version-file: go.mod
216+
217+
- name: Import GPG Subkey
218+
env:
219+
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
220+
GPG_FINGERPRINT: ${{ secrets.GPG_FINGERPRINT }}
221+
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
222+
run: |
223+
# Create GPG directory
224+
mkdir -p ~/.gnupg
225+
chmod 700 ~/.gnupg
226+
227+
# Configure GPG for non-interactive use with passphrase
228+
echo "use-agent" >> ~/.gnupg/gpg.conf
229+
echo "pinentry-mode loopback" >> ~/.gnupg/gpg.conf
230+
echo "allow-loopback-pinentry" >> ~/.gnupg/gpg.conf
231+
232+
# Start gpg-agent with loopback pinentry
233+
gpg-agent --daemon --allow-loopback-pinentry
234+
235+
# Import the subkey
236+
echo "$GPG_PRIVATE_KEY" | gpg --batch --import --passphrase "$GPG_PASSPHRASE"
237+
238+
# Trust the key (required for signing)
239+
# Use ultimate trust (6) for the subkey
240+
echo "$GPG_FINGERPRINT:6:" | gpg --import-ownertrust
241+
242+
# Verify key is available and can sign
243+
gpg --list-secret-keys --keyid-format LONG
244+
245+
# Test signing capability
246+
echo "test" | gpg --batch --pinentry-mode loopback --passphrase "$GPG_PASSPHRASE" --sign --armor > /dev/null 2>&1 && echo "✓ GPG signing test successful"
247+
248+
- name: Run GoReleaser
249+
uses: goreleaser/goreleaser-action@v6
250+
with:
251+
distribution: goreleaser
252+
version: '~> v2'
253+
# Run goreleaser and ignore non-committed files (downloaded artifacts)
254+
args: release --clean --skip=validate
255+
env:
256+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
257+
GPG_FINGERPRINT: ${{ secrets.GPG_FINGERPRINT }}
258+
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
259+
GPG_TTY: $(tty)
222260

223261
# terraform-provider-release:
224262
# needs: [release]

.goreleaser.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,29 @@ signs:
4444
# if you are using this is a GitHub action or some other automated pipeline, you
4545
# need to pass the batch flag to indicate its not interactive.
4646
- "--batch"
47+
- "--pinentry-mode"
48+
- "loopback"
49+
- "--passphrase"
50+
- "{{ .Env.GPG_PASSPHRASE }}"
4751
- "--local-user"
4852
- "{{ .Env.GPG_FINGERPRINT }}" # set this environment variable for your signing key
4953
- "--output"
5054
- "${signature}"
5155
- "--detach-sign"
5256
- "${artifact}"
57+
- artifacts: archive
58+
args:
59+
- "--batch"
60+
- "--pinentry-mode"
61+
- "loopback"
62+
- "--passphrase"
63+
- "{{ .Env.GPG_PASSPHRASE }}"
64+
- "--local-user"
65+
- "{{ .Env.GPG_FINGERPRINT }}"
66+
- "--output"
67+
- "${signature}"
68+
- "--detach-sign"
69+
- "${artifact}"
5370
release:
5471
# If you want to manually examine the release before its live, uncomment this line:
5572
draft: true

0 commit comments

Comments
 (0)