Add scripts/release-notes

This commit is contained in:
Robert Hensing 2023-11-19 16:49:11 +01:00
parent b26038c517
commit 2a538c571b
2 changed files with 166 additions and 27 deletions

View file

@ -24,34 +24,23 @@ release:
* In a checkout of the Nix repo, make sure you're on `master` and run * In a checkout of the Nix repo, make sure you're on `master` and run
`git pull`. `git pull`.
* Move the contents of `doc/manual/src/release-notes/rl-next.md` * Compile the release notes by running
(except the first line) to
`doc/manual/src/release-notes/rl-$VERSION.md` (where `$VERSION` is
the contents of `.version` *without* the patch level, e.g. `2.12`
rather than `2.12.0`).
* Add a header to `doc/manual/src/release-notes/rl-$VERSION.md` like
```
# Release 2.12 (2022-12-06)
```
* Proof-read / edit / rearrange the release notes. Breaking changes
and highlights should go to the top.
* Add a link to the release notes to `doc/manual/src/SUMMARY.md.in`
(*not* `SUMMARY.md`), e.g.
```
- [Release 2.12 (2022-12-06)](release-notes/rl-2.12.md)
```
* Run
```console ```console
$ git checkout -b release-notes $ git checkout -b release-notes
$ git add doc/manual/src/release-notes/rl-$VERSION.md $ VERSION=X.YY ./scripts/release-notes
$ git commit -a -m 'Release notes' ```
where `X.YY` is *without* the patch level, e.g. `2.12` rather than ~~`2.12.0`~~.
A commit is created.
* Proof-read / edit / rearrange the release notes if needed. Breaking changes
and highlights should go to the top.
* Push.
```console
$ git push --set-upstream $REMOTE release-notes $ git push --set-upstream $REMOTE release-notes
``` ```
@ -67,15 +56,17 @@ release:
$ git checkout -b $VERSION-maintenance $ git checkout -b $VERSION-maintenance
``` ```
* Mark the release as stable: * Mark the release as official:
```console ```console
$ git cherry-pick f673551e71942a52b6d7ae66af8b67140904a76a $ sed -e 's/officialRelease = false;/officialRelease = true;/' -i flake.nix
``` ```
This removes the link to `rl-next.md` from the manual and sets This removes the link to `rl-next.md` from the manual and sets
`officialRelease = true` in `flake.nix`. `officialRelease = true` in `flake.nix`.
* Commit
* Push the release branch: * Push the release branch:
```console ```console

148
scripts/release-notes Executable file
View file

@ -0,0 +1,148 @@
#!/usr/bin/env nix-shell
#!nix-shell -i bash ../shell.nix -I nixpkgs=channel:nixos-unstable-small
# ^^^^^^^
# Only used for bash. shell.nix goes to the flake.
# --- CONFIGURATION ---
# This does double duty for
# - including rl-next
# - marking where to insert new links (right after)
SUMMARY_MARKER_LINE='{{#include ./SUMMARY-rl-next.md}}'
# --- LIB ---
log() {
echo 1>&2 "release-notes:" "$@"
}
logcmd() {
local cmd="$1"
shift
logcmd2 "$cmd" "${*@Q}" "$cmd" "$@"
}
logcmd2() {
local fakecmd="$1"
local fakeargs="$2"
shift
shift
printf 1>&2 "release-notes: \033[34;1m$fakecmd\033[0m "
echo "$fakeargs" 1>&2
"$@"
}
die() {
# ANSI red
printf 1>&2 "release-notes: \033[31;1merror:\033[0m"
echo 1>&2 "" "$@"
exit 1
}
confirm() {
local answer
echo 1>&2 "$@" "[y/n]"
read -r answer
case "$answer" in
y|Y|yes|Yes|YES)
return 0
;;
n|N|no|No|NO)
return 1
;;
*)
echo 1>&2 "please answer y or n"
confirm "$@"
;;
esac
}
report_done() {
logcmd2 "git" "show" git -c pager.show=false show
printf 1>&2 "release-notes: \033[32;1mdone\033[0m\n"
}
# --- PARSE ARGS ---
if [[ $# -gt 0 ]]; then
die "Release notes takes no arguments, but make sure to set VERSION."
fi
# --- CHECKS ---
if [[ ! -e flake.nix ]] || [[ ! -e .git ]]; then
die "must run in repo root"
exit 1
fi
# repo must be clean
if ! git diff --quiet; then
die "repo is dirty, please commit or stash changes"
fi
if ! git diff --quiet --cached; then
die "repo has staged changes, please commit or stash them"
fi
if ! grep "$SUMMARY_MARKER_LINE" doc/manual/src/SUMMARY.md.in >/dev/null; then
# would have been nice to catch this early, but won't be worth the extra infra
die "SUMMARY.md.in is missing the marker line '$SUMMARY_MARKER_LINE', which would be used for inserting a new release notes page. Please fix the script."
fi
if [[ ! -n "${VERSION:-}" ]]; then
die "please set the VERSION environment variable before invoking this script"
exit 1
fi
case "$VERSION" in
# FIXME: accepts "." without any real digits
[[:digit:]]*.[[:digit:]]*)
;;
*)
die "VERSION must be MAJOR.MINOR, where each is a number, e.g. 2.20 (VERSION was set to $VERSION)"
;;
esac
# --- DEFAULTS ---
if [[ ! -n "${DATE:-}" ]]; then
DATE="$(date +%Y-%m-%d)"
log "DATE not set, using $DATE"
fi
case "$DATE" in
[[:digit:]]*-[[:digit:]]*-[[:digit:]]*)
;;
*)
die "DATE must be YYYY-MM-DD, e.g. 2021-12-31 (DATE was set to $DATE)"
;;
esac
# --- DO THE WORK ---
basename=rl-$VERSION.md
file=doc/manual/src/release-notes/$basename
title="Release $VERSION ($DATE)"
(
# TODO add minor number, and append?
echo "# $title"
echo
changelog-d doc/manual/rl-next | sed -e 's/ *$//'
) > $file
log "Wrote $file"
NEW_SUMMARY_LINE=" - [$title](release-notes/$basename)"
# find the marker line, insert new link after it
escaped_marker="$(echo "$SUMMARY_MARKER_LINE" | sed -e 's/\//\\\//g' -e 's/ /\\ /g')"
escaped_line="$(echo "$NEW_SUMMARY_LINE" | sed -e 's/\//\\\//g' -e 's/ /\\ /g')"
logcmd sed -i -e "/$escaped_marker/a $escaped_line" doc/manual/src/SUMMARY.md.in
for f in doc/manual/rl-next/*.md; do
if [[ config != "$(basename $f)" ]]; then
logcmd git rm $f
fi
done
logcmd git add $file doc/manual/src/SUMMARY.md.in
logcmd git status
logcmd git commit -m "release notes: $VERSION"
report_done