release: report a missing GPG key instead of exiting silently
CI / test (push) Successful in 1m18s

`resolve_gpg_key` and `gpg_fingerprint` pipe gpg into awk, and with `set -o
pipefail` a failing gpg (no secret key in the keyring, or a key id gpg cannot
find) made the pipeline, the command substitution and the script fail — so
`sign` aborted before its own `[ -n "$key" ] || die` / "could not read the
fingerprint" lines could print anything. Only gpg's message was suppressed,
leaving a release that stopped for no stated reason.

Both now tolerate the failed lookup so the intended error message is what the
user sees.
This commit is contained in:
raucao committed 2026-12-01 13:08:26 +04:00
1 parent b66a77dc7f
commit e6a06a7962
1 file changed
+7 -2
+7 -2
View File
@@ -159,14 +159,19 @@ probe_ssh_sign() {
resolve_gpg_key() {
local key=${REGENT_GPG_KEY:-}
if [ -z "$key" ]; then
key=$(gpg --batch --list-secret-keys --with-colons 2>/dev/null | awk -F: '/^sec:/ {print $5; exit}')
# `|| true`: with pipefail an empty keyring would otherwise abort the script
# silently here, never reaching the message below.
key=$(gpg --batch --list-secret-keys --with-colons 2>/dev/null | awk -F: '/^sec:/ {print $5; exit}' || true)
fi
[ -n "$key" ] || die "no GPG key: set REGENT_GPG_KEY, or import one (gpg --import)"
printf '%s' "$key"
}
gpg_fingerprint() {
gpg --batch --list-keys --with-colons --fingerprint "$1" 2>/dev/null | awk -F: '/^fpr:/ {print $10; exit}'
# Same `|| true`: a key id gpg cannot find makes the pipeline fail, and the
# caller's "could not read the fingerprint" check is meant to report that.
gpg --batch --list-keys --with-colons --fingerprint "$1" 2>/dev/null \
| awk -F: '/^fpr:/ {print $10; exit}' || true
}
load_release_env() {