Skip to content

Commit de73848

Browse files
authored
ci: verify release secrets before deploy (#2185)
## Summary - Replace `Debug gpg key` step with explicit checks for Sonatype token, GPG key import, and GPG passphrase match. - Each failure points at the matching `RELEASING.md` section. - Add `If the Sonatype Central Token is Invalid` section to `RELEASING.md`. Context: recent release attempt failed with `403` on Maven Central upload because the user token was stale. The token mismatch was only visible deep in Maven output. Note: Also fixes zizmor - I'm still investigating why flint didn't catch this before ## Test plan - [ ] Re-run release workflow with current secrets and confirm verify step passes (or surfaces the actual broken secret). --------- Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
1 parent 4aa20f0 commit de73848

2 files changed

Lines changed: 63 additions & 4 deletions

File tree

‎.github/workflows/release.yml‎

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,52 @@ jobs:
1818
permissions: {}
1919

2020
steps:
21-
- name: Debug gpg key
21+
- name: Verify release secrets
2222
env:
23+
MAVEN_USERNAME: ${{ secrets.SONATYPE_MAVEN_REPOSITORY_USERNAME }}
24+
MAVEN_CENTRAL_TOKEN: ${{ secrets.SONATYPE_MAVEN_REPOSITORY_PASSWORD }}
2325
GPG_SIGNING_KEY: ${{ secrets.GPG_SIGNING_KEY }}
26+
GPG_SIGNING_PASSPHRASE: ${{ secrets.GPG_SIGNING_PASSPHRASE }}
2427
run: |
25-
echo "${#GPG_SIGNING_KEY}"
26-
echo "${GPG_SIGNING_KEY}" | gpg --batch --import-options import-show --import
28+
fail() {
29+
echo "::error::$1"
30+
echo "::error::Fix: see '$2' in RELEASING.md"
31+
exit 1
32+
}
33+
34+
# Sonatype token
35+
response=$(curl -s -u "${MAVEN_USERNAME}:${MAVEN_CENTRAL_TOKEN}" \
36+
"https://central.sonatype.com/api/v1/publisher/status?id=test")
37+
echo "Sonatype response: ${response}"
38+
if echo "${response}" | grep -q "Invalid token"; then
39+
fail "Sonatype Central token is invalid." \
40+
"If the Sonatype Central Token is Invalid"
41+
fi
42+
43+
# GPG key import
44+
if ! echo "${GPG_SIGNING_KEY}" | gpg --batch --import 2>&1 | \
45+
tee /tmp/gpg-import.log | grep -q "secret key imported\|secret keys read"; then
46+
cat /tmp/gpg-import.log
47+
fail "GPG_SIGNING_KEY did not import a secret key." \
48+
"If the GPG Key Expired"
49+
fi
50+
51+
# GPG passphrase
52+
key_id=$(gpg --list-secret-keys --with-colons | \
53+
awk -F: '/^sec:/ { print $5; exit }')
54+
if [ -z "${key_id}" ]; then
55+
fail "No secret key available after import." \
56+
"If the GPG Key Expired"
57+
fi
58+
if ! echo "test" | gpg --batch --pinentry-mode loopback \
59+
--passphrase "${GPG_SIGNING_PASSPHRASE}" \
60+
-u "${key_id}" --clearsign >/dev/null 2>/tmp/gpg-sign.log; then
61+
cat /tmp/gpg-sign.log
62+
fail "GPG_SIGNING_PASSPHRASE does not match GPG_SIGNING_KEY." \
63+
"If the GPG Key Expired"
64+
fi
2765
- name: Checkout Plugin Repository
28-
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
66+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
2967
with:
3068
ref: ${{ inputs.tag }}
3169
persist-credentials: false

‎RELEASING.md‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,27 @@ the benchmarks before merging the release PR:
4444
mise run update-benchmarks
4545
```
4646

47+
## If the Sonatype Central Token is Invalid
48+
49+
The release workflow verifies the token before deploy. If it fails:
50+
51+
1. Sign in at <https://central.sonatype.com> and open
52+
View Account -> Generate User Token.
53+
2. Copy the `username` and `password` values from the snippet.
54+
3. Update the secrets:
55+
- <https://github.com/prometheus/client_java/settings/secrets/actions/SONATYPE_MAVEN_REPOSITORY_USERNAME>
56+
- <https://github.com/prometheus/client_java/settings/secrets/actions/SONATYPE_MAVEN_REPOSITORY_PASSWORD>
57+
4. Verify locally:
58+
59+
```shell
60+
curl -i -u "$USER:$PASS" \
61+
"https://central.sonatype.com/api/v1/publisher/status?id=test"
62+
```
63+
64+
`{"error":{"message":"Invalid token"}}` means the token is still
65+
wrong. Any other response (including 404 for the test id) means the
66+
token works.
67+
4768
## If the GPG Key Expired
4869

4970
1. Generate a new key:

0 commit comments

Comments
 (0)