From b5016d632fdc626627942388ae617ec43b4d856c Mon Sep 17 00:00:00 2001 From: Dan Field Date: Wed, 25 Nov 2026 16:44:18 +0000 Subject: [PATCH] Add scripts/release.sh for the release procedure Scripts the steps in docs/DEVELOPMENT.md: stops on errors, checks the tree, versions, tag and branch before starting, test-signs with gpg, pauses for README/CHANGELOG edits and the PR merge, verifies the pom version at the commit it tags, and asks before each push and the deploy. Used to release 2.2.4. Co-Authored-By: Claude Opus 5.5 --- docs/DEVELOPMENT.md | 13 ++++ scripts/release.sh | 146 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 159 insertions(+) create mode 100755 scripts/release.sh diff --git a/docs/DEVELOPMENT.md b/docs/DEVELOPMENT.md index cb9db65c..c787e52f 100644 --- a/docs/DEVELOPMENT.md +++ b/docs/DEVELOPMENT.md @@ -66,6 +66,19 @@ fixtures, as part of the unit tests in the `ocfl-java-core` module. # Release +`scripts/release.sh` runs the steps below with checks, pauses for the manual +steps, and a confirmation before each push and the deploy. Run it from a +terminal on an up-to-date `main`. It pushes to `origin`; set +`RELEASE_REMOTE=upstream` if `origin` is your fork. Merge the release PR +with a merge commit, not a squash, so the release commit can be tagged. + +``` shell +scripts/release.sh # e.g. 2.2.4-SNAPSHOT -> 2.2.4, then 2.2.5-SNAPSHOT +scripts/release.sh 2.3.0 2.3.1-SNAPSHOT # explicit versions +``` + +Manual steps: + ``` shell RELEASE_VERSION=2.0.0 SNAP_VERSION=2.0.1-SNAPSHOT diff --git a/scripts/release.sh b/scripts/release.sh new file mode 100755 index 00000000..74ff956f --- /dev/null +++ b/scripts/release.sh @@ -0,0 +1,146 @@ +#!/usr/bin/env bash +# Release procedure from docs/DEVELOPMENT.md, with checks and pauses. +# +# Usage: scripts/release.sh [RELEASE_VERSION] [SNAP_VERSION] +# Defaults: RELEASE_VERSION from the pom (x.y.z-SNAPSHOT -> x.y.z), +# SNAP_VERSION = x.y.(z+1)-SNAPSHOT +# +# Pushes to the "origin" remote; set RELEASE_REMOTE to use another (e.g. upstream). +# Stops on the first failed command. Asks before every push and before deploy. +# Only tracked files are committed (git add -u), so untracked files are +# never included. + +set -euo pipefail + +# gpg-agent needs the terminal to show the passphrase prompt during deploy. +GPG_TTY="$(tty)" || { echo "ERROR: release.sh must be run from a terminal." >&2; exit 1; } +export GPG_TTY + +REMOTE="${RELEASE_REMOTE:-origin}" +MAIN=main + +die() { echo "ERROR: $*" >&2; exit 1; } +info() { echo; echo "==> $*"; } +confirm() { + local reply + read -r -p "$1 [y/N] " reply + [[ "$reply" == "y" || "$reply" == "Y" ]] || die "Stopped by user." +} +pom_version() { + # Project version from the root pom at the given ref (default: working tree). + local ref="${1:-}" + if [[ -n "$ref" ]]; then + git show "$ref:pom.xml" + else + cat pom.xml + fi | sed -n '//,/<\/parent>/d; s:.*\(.*\).*:\1:p' | head -n 1 +} + +cd "$(git rev-parse --show-toplevel)" + +# ---------------------------------------------------------------- versions +CURRENT_VERSION="$(pom_version)" +[[ "$CURRENT_VERSION" == *-SNAPSHOT ]] || die "pom version is $CURRENT_VERSION, expected a -SNAPSHOT version." + +RELEASE_VERSION="${1:-${CURRENT_VERSION%-SNAPSHOT}}" +if [[ -n "${2:-}" ]]; then + SNAP_VERSION="$2" +else + IFS=. read -r MAJ MIN PAT <<< "$RELEASE_VERSION" + [[ "$PAT" =~ ^[0-9]+$ ]] || die "Cannot derive SNAP_VERSION from $RELEASE_VERSION; pass it as the second argument." + SNAP_VERSION="$MAJ.$MIN.$((PAT + 1))-SNAPSHOT" +fi + +[[ "$RELEASE_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || die "RELEASE_VERSION '$RELEASE_VERSION' is not x.y.z." +[[ "$SNAP_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+-SNAPSHOT$ ]] || die "SNAP_VERSION '$SNAP_VERSION' is not x.y.z-SNAPSHOT." + +TAG="v$RELEASE_VERSION" +BRANCH="release-$RELEASE_VERSION" + +# --------------------------------------------------------------- preflight +info "Preflight checks" +command -v mvn >/dev/null || die "mvn not found on PATH." +# Sign once now so a gpg problem (stale keyring lock, no pinentry) stops the +# release before anything is pushed. Also caches the passphrase for deploy. +echo "release preflight" | gpg --clearsign >/dev/null || die "gpg signing failed." +git remote get-url "$REMOTE" >/dev/null 2>&1 || die "No git remote named '$REMOTE'." +REMOTE_URL="$(git remote get-url "$REMOTE")" + +[[ "$(git branch --show-current)" == "$MAIN" ]] || die "Not on $MAIN." +git diff --quiet && git diff --cached --quiet || die "Tracked files have uncommitted changes." + +git fetch "$REMOTE" --tags +git merge --ff-only "$REMOTE/$MAIN" >/dev/null || die "Local $MAIN cannot fast-forward to $REMOTE/$MAIN." +[[ "$(pom_version)" == "$CURRENT_VERSION" ]] || die "pom version changed after pulling $MAIN; re-run." + +git rev-parse -q --verify "refs/tags/$TAG" >/dev/null && die "Tag $TAG already exists locally." +[[ -z "$(git ls-remote --tags "$REMOTE" "refs/tags/$TAG")" ]] || die "Tag $TAG already exists on $REMOTE." +git rev-parse -q --verify "refs/heads/$BRANCH" >/dev/null && die "Branch $BRANCH already exists locally." +[[ -z "$(git ls-remote --heads "$REMOTE" "$BRANCH")" ]] || die "Branch $BRANCH already exists on $REMOTE." + +cat <