From 1e83b28e1ebea517541ce337ed33ab027f8dc6be Mon Sep 17 00:00:00 2001 From: faumaray Date: Sat, 1 Aug 2026 19:48:48 +0300 Subject: [PATCH] Fix subject-only signed release tags --- scripts/tests/test-gitea-tag-verification.sh | 16 ++++++ scripts/verify-gitea-release-tag.sh | 57 ++++++++++++-------- 2 files changed, 52 insertions(+), 21 deletions(-) diff --git a/scripts/tests/test-gitea-tag-verification.sh b/scripts/tests/test-gitea-tag-verification.sh index 69b8cad..f797be3 100755 --- a/scripts/tests/test-gitea-tag-verification.sh +++ b/scripts/tests/test-gitea-tag-verification.sh @@ -62,6 +62,22 @@ if grep -Fq -- 'SSH SIGNATURE' "$temporary/notes.md"; then exit 1 fi +# Git 2.34 can underflow while formatting %(contents:body) for an SSH-signed +# tag with only a subject. Subject-only release notes must remain supported. +git -C "$repository" switch -q main +git -C "$repository" tag -s -a v1.2.4 -m 'Echoion 1.2.4' +subject_only_tag=$(git -C "$repository" rev-parse 'refs/tags/v1.2.4^{tag}') +( + cd "$repository" + "$verifier" \ + --tag v1.2.4 \ + --event-sha "$subject_only_tag" \ + --allowed-signers "$temporary/allowed-signers" \ + --notes-output "$temporary/subject-only-notes.md" \ + >/dev/null +) +test "$(<"$temporary/subject-only-notes.md")" = 'Echoion 1.2.4' + ( cd "$repository" "$verifier" \ diff --git a/scripts/verify-gitea-release-tag.sh b/scripts/verify-gitea-release-tag.sh index f852ca6..4671b10 100755 --- a/scripts/verify-gitea-release-tag.sh +++ b/scripts/verify-gitea-release-tag.sh @@ -93,10 +93,8 @@ if [[ "$target_type" != commit || fi git cat-file -e "$tag_target^{commit}" -signature=$( - git for-each-ref --count=1 --format='%(contents:signature)' "$tag_ref" -) -if [[ "$signature" != '-----BEGIN SSH SIGNATURE-----'* ]]; then +if ! git cat-file tag "$tag_object" | + grep -q '^-----BEGIN SSH SIGNATURE-----$'; then printf '%s\n' \ 'verify-gitea-release-tag: annotated tag must use an SSH signature' >&2 exit 1 @@ -118,23 +116,40 @@ if [[ "$event_sha" != "$tag_object" && "$event_sha" != "$tag_target" ]]; then exit 1 fi -subject=$( - git for-each-ref --count=1 --format='%(contents:subject)' "$tag_ref" -) -body=$( - git for-each-ref --count=1 --format='%(contents:body)' "$tag_ref" -) -if [[ -z "$subject" ]]; then - printf '%s\n' \ - 'verify-gitea-release-tag: annotated tag has no release-note subject' >&2 - exit 1 -fi +python3 - "$tag_object" "$notes_output" <<'PY' +from pathlib import Path +import subprocess +import sys -{ - printf '%s\n' "$subject" - if [[ -n "$body" ]]; then - printf '\n%s\n' "$body" - fi -} >"$notes_output" + +def fail(message: str) -> None: + print(f"verify-gitea-release-tag: {message}", file=sys.stderr) + raise SystemExit(1) + + +tag = subprocess.run( + ["git", "cat-file", "tag", sys.argv[1]], + check=True, + stdout=subprocess.PIPE, +).stdout +try: + _, message = tag.split(b"\n\n", 1) +except ValueError: + fail("annotated tag has no release-note subject") + +marker = b"\n-----BEGIN SSH SIGNATURE-----\n" +signature_offset = message.rfind(marker) +if signature_offset < 0: + fail("annotated tag must use an SSH signature") +notes = message[:signature_offset] +try: + text = notes.decode("utf-8").rstrip("\n") +except UnicodeDecodeError: + fail("release notes are not valid UTF-8") +if not text or not text.splitlines()[0]: + fail("annotated tag has no release-note subject") + +Path(sys.argv[2]).write_text(text + "\n", encoding="utf-8") +PY printf '%s\n' "$tag_target"