Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit dd14627

Browse files
aduh95marco-ippolito
authored andcommittedJan 22, 2025
tools: filter release keys to reduce interactivity
PR-URL: #55950 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
1 parent cad33af commit dd14627

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed
 

‎tools/release.sh

+26-8
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,25 @@ webuser=dist
1515
promotablecmd=dist-promotable
1616
promotecmd=dist-promote
1717
signcmd=dist-sign
18+
allPGPKeys=""
1819
customsshkey="" # let ssh and scp use default key
20+
readmePath="README.md"
1921
signversion=""
2022
cloudflare_bucket="r2:dist-prod"
2123

22-
while getopts ":i:s:" option; do
24+
while getopts ":i:r:s:a" option; do
2325
case "${option}" in
26+
a)
27+
# With -a, local keys are not filtered based on the one listed in the README
28+
# useful if you want to sign with a subkey.
29+
allPGPKeys="true"
30+
;;
2431
i)
2532
customsshkey="-i ${OPTARG}"
2633
;;
34+
r)
35+
readmePath="${OPTARG}"
36+
;;
2737
s)
2838
signversion="${OPTARG}"
2939
;;
@@ -44,7 +54,16 @@ shift $((OPTIND-1))
4454

4555
echo "# Selecting GPG key ..."
4656

47-
gpgkey=$(gpg --list-secret-keys --keyid-format SHORT | awk -F'( +|/)' '/^(sec|ssb)/{print $3}')
57+
58+
if [ -z "$allPGPKeys" ]; then
59+
gpgkey="$(awk '{
60+
if ($1 == "gpg" && $2 == "--keyserver" && $4 == "--recv-keys" && (1 == 2'"$(
61+
gpg --list-secret-keys | awk -F' = ' '/^ +Key fingerprint/{ gsub(/ /,"",$2); print " || $5 == \"" $2 "\"" }' || true
62+
)"')) { print substr($5, 33) }
63+
}' "$readmePath")"
64+
else
65+
gpgkey=$(gpg --list-secret-keys --keyid-format SHORT | awk -F'( +|/)' '/^(sec|ssb)/{print $3}')
66+
fi
4867
keycount=$(echo "$gpgkey" | wc -w)
4968

5069
if [ "$keycount" -eq 0 ]; then
@@ -68,13 +87,12 @@ elif [ "$keycount" -ne 1 ]; then
6887
gpgkey=$(echo "$gpgkey" | sed -n "${keynum}p")
6988
fi
7089

71-
gpgfing=$(gpg --keyid-format 0xLONG --fingerprint "$gpgkey" | grep 'Key fingerprint =' | awk -F' = ' '{print $2}' | tr -d ' ')
72-
73-
grep -q "$gpgfing" README.md || (\
74-
echo 'Error: this GPG key fingerprint is not listed in ./README.md' && \
75-
exit 1 \
76-
)
90+
gpgfing=$(gpg --keyid-format 0xLONG --fingerprint "$gpgkey" | awk -F' = ' '/^ +Key fingerprint/{gsub(/ /,"",$2);print $2}')
7791

92+
grep -q "$gpgfing" "$readmePath" || {
93+
echo "Error: this GPG key fingerprint is not listed in $readmePath"
94+
exit 1
95+
}
7896

7997
echo "Using GPG key: $gpgkey"
8098
echo " Fingerprint: $gpgfing"

0 commit comments

Comments
 (0)
Please sign in to comment.