Files
opu/tools/release.sh
T
yann64andClaude Opus 5.5 114976b912
CI / Linux arm64 (push) Waiting to run
CI / Linux x86_64 (push) Waiting to run
CI / ASan + UBSan (push) Waiting to run
release.sh: fix release notes extraction (empty notes in v0.2.0)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WDASLCiN764v685boRVYar
2026-11-28 20:09:05 +01:00

50 lines
2.6 KiB
Bash

#!/bin/sh
# SPDX-License-Identifier: MIT
# Cut a release: set project(VERSION) in CMakeLists.txt, date the "Unreleased" section of
# CHANGELOG.md, commit, create the annotated tag vX.Y.Z, push to every remote (GitHub origin and
# the Gitea mirror) and publish the GitHub release that the in-app update check reads.
#
# usage: tools/release.sh X.Y.Z [--no-push]
set -eu
VERSION=${1:-}
PUSH=1
[ "${2:-}" = "--no-push" ] && PUSH=0
echo "$VERSION" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+$' || { echo "usage: $0 X.Y.Z [--no-push]" >&2; exit 2; }
cd "$(dirname "$0")/.."
[ -z "$(git status --porcelain)" ] || { echo "the working tree is not clean" >&2; exit 1; }
git rev-parse -q --verify "refs/tags/v$VERSION" >/dev/null && { echo "tag v$VERSION already exists" >&2; exit 1; }
grep -q '^## \[Unreleased\]' CHANGELOG.md || { echo "CHANGELOG.md has no [Unreleased] section" >&2; exit 1; }
PREVIOUS=$(git describe --tags --abbrev=0 --match 'v[0-9]*' 2>/dev/null || true)
TODAY=$(date +%Y-%m-%d)
sed -i "s/^project(openpu VERSION [0-9.]* /project(openpu VERSION $VERSION /" CMakeLists.txt
grep -q "^project(openpu VERSION $VERSION " CMakeLists.txt || { echo "cannot update CMakeLists.txt" >&2; exit 1; }
# New release section under an empty Unreleased one, and comparison links at the bottom.
sed -i "s/^## \[Unreleased\]$/## [Unreleased]\n\n## [$VERSION] - $TODAY/" CHANGELOG.md
sed -i "s|^\[Unreleased\]: \(.*\)/compare/v[0-9.]*\.\.\.HEAD$|[Unreleased]: \1/compare/v$VERSION...HEAD\n[$VERSION]: \1/releases/tag/v$VERSION|" CHANGELOG.md
git add CMakeLists.txt CHANGELOG.md
# RELEASE_TRAILER: optional trailer lines appended to the release commit message (e.g. co-authors).
git commit -q -m "release: v$VERSION" ${RELEASE_TRAILER:+-m "$RELEASE_TRAILER"}
# Plain string comparison (not a regex: "[" and "." in the heading would be special).
NOTES=$(awk -v v="$VERSION" 'index($0, "## [" v "]") == 1 {on=1; next}
on && (index($0, "## ") == 1 || index($0, "[") == 1) {exit}
on {print}' CHANGELOG.md | sed -e '/./,$!d')
[ -n "$NOTES" ] || { echo "no release notes found for $VERSION in CHANGELOG.md" >&2; exit 1; }
git tag -a "v$VERSION" -m "OpenPU $VERSION" -m "$NOTES"
echo "tagged v$VERSION (previous: ${PREVIOUS:-none})"
[ "$PUSH" = 1 ] || exit 0
for remote in $(git remote); do
git push --follow-tags "$remote" HEAD
done
GH=$(command -v gh || command -v gh.exe || true)
[ -z "$GH" ] && [ -x "/c/Program Files/GitHub CLI/gh.exe" ] && GH="/c/Program Files/GitHub CLI/gh.exe"
if [ -n "$GH" ]; then
printf '%s\n' "$NOTES" | "$GH" release create "v$VERSION" --verify-tag --title "OpenPU $VERSION" --notes-file -
else
echo "gh not found: create the GitHub release for v$VERSION by hand" >&2
fi