#!/usr/bin/env bash # Cut a hub release: signed annotated tag on main, push. The version comes from the tag; there is no file to bump. # # scripts/release.sh 0.1.0 # remote: forgejo # scripts/release.sh 0.1.0 --dry-run # checks and the planned commands, changes nothing # # The Forgejo release lane (.forgejo/workflows/release.yml) builds the tag and publishes only when the tests pass and # the linux binary reports the tag version. `hub self-update` accepts only tags signed by a pinned key (docs/releasing.md). set -euo pipefail version=${1:?usage: scripts/release.sh X.Y.Z [--dry-run]} dry=${2:-} remote=${HUB_RELEASE_REMOTE:-forgejo} tag="v$version" die() { echo "release: $*" >&2; exit 1; } [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || die "version must look like 1.2.3 (self-update only offers X.Y.Z tags)" cd "$(git rev-parse --show-toplevel)" [ "$(git rev-parse --abbrev-ref HEAD)" = "main" ] || die "run from main" [ -z "$(git status --porcelain --untracked-files=no)" ] || die "tracked changes present; commit or stash first" git fetch -q "$remote" main --tags [ "$(git rev-parse HEAD)" = "$(git rev-parse "$remote/main")" ] || die "main is not equal to $remote/main; pull or push first" git rev-parse -q --verify "refs/tags/$tag" >/dev/null && die "tag $tag already exists" [ "$(git config --get tag.gpgSign || true)" = "true" ] || [ -n "$(git config --get user.signingkey || true)" ] || die "no signing key configured (tag must be signed)" echo "release $tag on $remote (HEAD $(git rev-parse --short HEAD))" if [ "$dry" = "--dry-run" ]; then echo "would: git tag -s $tag, push $remote $tag" exit 0 fi git tag -s "$tag" -m "hub $tag" git verify-tag "$tag" >/dev/null 2>&1 || echo "release: note: local gpg cannot verify $tag (public key not imported here)" >&2 git push -q "$remote" "$tag" echo "pushed $tag; the release lane builds it"