Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ jobs:
id: build
run: ./mvnw -ntp -B -Ppublication

- name: Sign release tag
env:
GPG_SECRET_KEY: ${{ secrets.GPG_SECRET_KEY }}
GPG_PUBLIC_KEY: ${{ secrets.GPG_PUBLIC_KEY }}
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
run: scripts/sign-release-tag.sh "release-$VERSION" "$(git rev-parse HEAD)"

- name: Release
env:
JRELEASER_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
32 changes: 32 additions & 0 deletions .github/workflows/repair-release-tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Repair release tag

on:
workflow_dispatch:
inputs:
version:
description: 'Version of the published release to repair'
required: true
type: string
commit:
description: 'Exact release commit (40-character SHA)'
required: true
type: string

jobs:
repair:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Sign and replace lightweight tag
env:
VERSION: ${{ inputs.version }}
RELEASE_COMMIT: ${{ inputs.commit }}
GPG_SECRET_KEY: ${{ secrets.GPG_SECRET_KEY }}
GPG_PUBLIC_KEY: ${{ secrets.GPG_PUBLIC_KEY }}
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
run: scripts/sign-release-tag.sh "release-$VERSION" "$RELEASE_COMMIT" repair
4 changes: 4 additions & 0 deletions MODELS.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,7 @@ Report actual checks and review coverage, unresolved findings, and compatibility
impact. Record user-visible changes under `Next release` in `change_log.md`.
Follow the README contribution process and AGENTS.md release restrictions;
model recommendations do not replace required human approvals.
For releases, verify the published tag resolves to the release commit and is
an annotated PGP-signed tag (`git cat-file -t` and `git tag -v`). JReleaser's
GitHub `sign` option signs commits, not tags; check the actual remote tag type
and signature after publication.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,8 @@ application while protecting against XSS.
<github>
<tagName>release-{{projectVersion}}</tagName>
<releaseName>Release {{projectVersion}}</releaseName>
<!-- Annotated, PGP-signed tags, as every pre-JReleaser release had. -->
<sign>true</sign>
<!-- The release workflow creates and pushes a signed tag. -->
<skipTag>true</skipTag>
<changelog>
<formatted>ALWAYS</formatted>
<skipMergeCommits>true</skipMergeCommits>
Expand Down
75 changes: 75 additions & 0 deletions scripts/sign-release-tag.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/usr/bin/env bash
# SPDX-License-Identifier: Apache-2.0 OR BSD-2-Clause

set -euo pipefail

tag=${1:?release tag required}
commit=${2:?release commit required}
mode=${3:-create}

if [[ ! $tag =~ ^release-[0-9]{8}\.[0-9]+$ || ! $commit =~ ^[0-9a-f]{40}$ ]]; then
echo 'Invalid release tag or commit' >&2
exit 1
fi
if [[ $mode != create && $mode != repair ]]; then
echo 'Mode must be create or repair' >&2
exit 1
fi
: "${GPG_SECRET_KEY:?GPG_SECRET_KEY required}"
: "${GPG_PUBLIC_KEY:?GPG_PUBLIC_KEY required}"
: "${GPG_PASSPHRASE:?GPG_PASSPHRASE required}"

remote_ref=$(git ls-remote --refs origin "refs/tags/$tag")
if [[ $mode == create ]]; then
if [[ -n $remote_ref ]] || git show-ref --verify --quiet "refs/tags/$tag"; then
echo "Tag $tag already exists" >&2
exit 1
fi
else
if [[ $remote_ref != "$commit"$'\t'"refs/tags/$tag" ]]; then
echo "Remote tag $tag has changed or is not a lightweight tag at $commit" >&2
exit 1
fi
if [[ $(git rev-parse "refs/tags/$tag^{commit}") != "$commit" ||
$(git cat-file -t "refs/tags/$tag") != commit ]]; then
echo "Local tag $tag is not a lightweight tag at $commit" >&2
exit 1
fi
fi

signing_home=$(mktemp -d)
trap 'gpgconf --kill gpg-agent >/dev/null 2>&1 || true; rm -rf "$signing_home"' EXIT
chmod 700 "$signing_home"
export GNUPGHOME=$signing_home
printf '%s\n' "$GPG_PUBLIC_KEY" | gpg --batch --quiet --import
printf '%s\n' "$GPG_SECRET_KEY" | gpg --batch --quiet --import

fingerprint=$(gpg --batch --with-colons --list-secret-keys |
awk -F: '$1 == "sec" { primary = 1; next } $1 == "fpr" && primary { print $10; primary = 0 }')
if [[ ! $fingerprint =~ ^[0-9A-F]{40}$ ]]; then
echo 'Expected exactly one release signing key' >&2
exit 1
fi

cat > "$signing_home/gpg-for-git" <<'EOF'
#!/usr/bin/env bash
exec gpg --batch --pinentry-mode loopback --passphrase-fd 3 "$@" 3<<<"$GPG_PASSPHRASE"
EOF
chmod 700 "$signing_home/gpg-for-git"

if [[ $mode == repair ]]; then
git tag -d "$tag"
fi
git -c "gpg.program=$signing_home/gpg-for-git" tag -s -u "$fingerprint" \
-m "Release ${tag#release-}" "$tag" "$commit"
git tag -v "$tag"
if [[ $(git rev-parse "$tag^{commit}") != "$commit" ]]; then
echo 'Signed tag does not point to the expected commit' >&2
exit 1
fi

if [[ $mode == repair ]]; then
git push --force-with-lease="refs/tags/$tag:$commit" origin "refs/tags/$tag"
else
git push origin "refs/tags/$tag"
fi
Loading