From 25ef7a19566aff71d12640cfcf2cbdae068ffe34 Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Sun, 27 Apr 2025 17:08:41 -0400 Subject: [PATCH] Automatically generate release notes draft during proposal --- .github/release-notes.sh | 63 +++++++++++++++++++++++++++ .github/workflows/propose-release.yml | 2 + 2 files changed, 65 insertions(+) create mode 100755 .github/release-notes.sh diff --git a/.github/release-notes.sh b/.github/release-notes.sh new file mode 100755 index 000000000..641426b36 --- /dev/null +++ b/.github/release-notes.sh @@ -0,0 +1,63 @@ +#!/bin/sh + +scratch=$(mktemp -d -t tmp.XXXXXXXXXX) +finish() { + rm -rf "$scratch" +} +trap finish EXIT + +DATE=$(date +%Y-%m-%d) +DETERMINATE_NIX_VERSION=$(cat .version-determinate) +TAG_NAME="v${DETERMINATE_NIX_VERSION}" +NIX_VERSION=$(cat .version) +NIX_VERSION_MAJOR_MINOR=$(echo "$NIX_VERSION" | cut -d. -f1,2) +GITHUB_REPOSITORY="${GITHUB_REPOSITORY:-DeterminateSystems/nix-src}" + +gh api "/repos/${GITHUB_REPOSITORY}/releases/generate-notes" \ + -f "tag_name=${TAG_NAME}" > "$scratch/notes.json" + +trim_trailing_newlines() { + tac \ + | awk 'flag {print} {if(NF) flag=1}' \ + | tac +} + +linkify_gh() { + sed \ + -e 's#\(https://github.com/DeterminateSystems/nix-src/\(pull\|issue\)/\([[:digit:]]\+\)\)#[dnix\#\3](\1)#' \ + -e 's#\(https://github.com/DeterminateSystems/nix-src/compare/\([^ ]\+\)\)#[\2](\1)#' +} + +( + cat doc/manual/source/release-notes-determinate/changes.md \ + | sed 's/^.*\(\)$/This section lists the differences between upstream Nix '"$NIX_VERSION_MAJOR_MINOR"' and Determinate Nix '"$DETERMINATE_NIX_VERSION"'.\1/' \ + + printf "\n\n" "$DETERMINATE_NIX_VERSION" + cat "$scratch/notes.json" \ + | jq -r .body \ + | grep -v '^#' \ + | grep -v "Full Changelog" \ + | trim_trailing_newlines \ + | sed -e 's/^\* /\n* /' \ + | linkify_gh +) > "$scratch/changes.md" + +( + printf "# Release %s (%s)\n\n" \ + "$DETERMINATE_NIX_VERSION" \ + "$DATE" + printf "* Based on [upstream Nix %s](../release-notes/rl-%s.md).\n\n" \ + "$NIX_VERSION" \ + "$NIX_VERSION_MAJOR_MINOR" + + cat "$scratch/notes.json" | jq -r .body | linkify_gh +) > "$scratch/rl.md" + +( + cat doc/manual/source/SUMMARY.md.in \ + | sed 's/\(\)$/\1\n - [Release '"$DETERMINATE_NIX_VERSION"' ('"$DATE"')](release-notes-determinate\/rl-'"$DETERMINATE_NIX_VERSION"'.md)/' +) > "$scratch/summary.md" + +mv "$scratch/changes.md" doc/manual/source/release-notes-determinate/changes.md +mv "$scratch/rl.md" "doc/manual/source/release-notes-determinate/rl-${DETERMINATE_NIX_VERSION}.md" +mv "$scratch/summary.md" doc/manual/source/SUMMARY.md.in diff --git a/.github/workflows/propose-release.yml b/.github/workflows/propose-release.yml index 8b897072c..c01167994 100644 --- a/.github/workflows/propose-release.yml +++ b/.github/workflows/propose-release.yml @@ -26,4 +26,6 @@ jobs: extra-commands-early: | echo ${{ inputs.version }} > .version-determinate git add .version-determinate + ./.github/release-notes.sh + git add doc git commit -m "Set .version-determinate to ${{ inputs.version }}" || true