From c02e6a795419e1b08aa441a145c26e2900cb7d63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20M=C3=BCller?= Date: Sat, 13 Jan 2024 21:30:09 +0100 Subject: [PATCH 1/4] Add `scripts/update-changelog.sh` --- scripts/update-changelog.sh | 66 +++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100755 scripts/update-changelog.sh diff --git a/scripts/update-changelog.sh b/scripts/update-changelog.sh new file mode 100755 index 000000000000..f4ff09a9dbef --- /dev/null +++ b/scripts/update-changelog.sh @@ -0,0 +1,66 @@ +#! /bin/sh + +# This script automates generating changelog with `scripts/github-changelog.cr`, +# editing it into `CHANGELOG.md` and pushing it to a `changelog/$VERSION` branch. +# +# It reads the current (dev-)version from `src/VERSION` and generates the +# changelog entries for all PRs from the respective GitHub milestone via +# `scripts/github-changelog.cr`. +# The section is then inserted into `CHANGELOG.md`, overwriting any previous +# content for this milestone. +# Finally, the changes are commited and pushed to `changelog/$VERSION`. +# If the changelog section is *new*, also creates a draft PR for this branch. +# +# Usage: +# +# scripts/update-changelog.sh +# +# Requirements: +# +# - scripts/github-changelog.cr +# - git +# - grep +# - sed +# +# Environment variables: +# GITHUB_TOKEN: Access token for the GitHub API (required) + +set -eu + +VERSION=${1:-$(cat src/VERSION)} +VERSION=${VERSION%-dev} + +base_branch=$(git rev-parse --abbrev-ref HEAD) +branch="changelog/$VERSION" +current_changelog="CHANGELOG.$VERSION.md" + +echo "Switching to branch $branch" +git switch $branch 2>/dev/null || git switch -c $branch; + +echo "Generating $current_changelog..." + +scripts/github-changelog.cr $VERSION > $current_changelog + +if grep -E "^## \[$VERSION\]" CHANGELOG.md; then + echo "Replacing section in CHANGELOG" + + sed -iE "/^## \[$VERSION\]/,/^## /{ + /^## \[$VERSION\]/s/.*/cat $current_changelog/e; /^## /!d + }" CHANGELOG.md + + git add CHANGELOG.md + git commit -m "Update changelog for $VERSION" + git push +else + echo "Adding new section to CHANGELOG" + + sed -iE "2r $current_changelog" CHANGELOG.md + + git add CHANGELOG.md + git commit -m "Add changelog for $VERSION" + git push -u upstream $branch + + gh pr create --draft --base "$base_branch" \ + --body "Preview: https://github.com/crystal-lang/crystal/blob/$branch/CHANGELOG.md" \ + --label "topic:infrastructure" -t "Changelog for $VERSION" --milestone "$VERSION" +fi From a206e9f9533846631cb8302b499285e831f8cb29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20M=C3=BCller?= Date: Mon, 26 Feb 2024 10:45:31 +0100 Subject: [PATCH 2/4] Use script from current branch to generate changelog --- scripts/update-changelog.sh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/scripts/update-changelog.sh b/scripts/update-changelog.sh index f4ff09a9dbef..d691ccf00b35 100755 --- a/scripts/update-changelog.sh +++ b/scripts/update-changelog.sh @@ -34,13 +34,12 @@ base_branch=$(git rev-parse --abbrev-ref HEAD) branch="changelog/$VERSION" current_changelog="CHANGELOG.$VERSION.md" -echo "Switching to branch $branch" -git switch $branch 2>/dev/null || git switch -c $branch; - echo "Generating $current_changelog..." - scripts/github-changelog.cr $VERSION > $current_changelog +echo "Switching to branch $branch" +git switch $branch 2>/dev/null || git switch -c $branch; + if grep -E "^## \[$VERSION\]" CHANGELOG.md; then echo "Replacing section in CHANGELOG" From 45d0afcc4a1b3ad5b452d74bd6fa31a8c03638b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20M=C3=BCller?= Date: Wed, 3 Apr 2024 13:10:10 +0200 Subject: [PATCH 3/4] Add `--silent` --- scripts/update-changelog.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/update-changelog.sh b/scripts/update-changelog.sh index d691ccf00b35..61edf660db74 100755 --- a/scripts/update-changelog.sh +++ b/scripts/update-changelog.sh @@ -40,7 +40,7 @@ scripts/github-changelog.cr $VERSION > $current_changelog echo "Switching to branch $branch" git switch $branch 2>/dev/null || git switch -c $branch; -if grep -E "^## \[$VERSION\]" CHANGELOG.md; then +if grep --silent -E "^## \[$VERSION\]" CHANGELOG.md; then echo "Replacing section in CHANGELOG" sed -iE "/^## \[$VERSION\]/,/^## /{ From 541ede8ed7571debd039298a5c091750ef7b50a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20M=C3=BCller?= Date: Wed, 3 Apr 2024 13:14:47 +0200 Subject: [PATCH 4/4] Fix sed flags --- scripts/update-changelog.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/update-changelog.sh b/scripts/update-changelog.sh index 61edf660db74..777f65a60e3d 100755 --- a/scripts/update-changelog.sh +++ b/scripts/update-changelog.sh @@ -43,7 +43,7 @@ git switch $branch 2>/dev/null || git switch -c $branch; if grep --silent -E "^## \[$VERSION\]" CHANGELOG.md; then echo "Replacing section in CHANGELOG" - sed -iE "/^## \[$VERSION\]/,/^## /{ + sed -i -E "/^## \[$VERSION\]/,/^## /{ /^## \[$VERSION\]/s/.*/cat $current_changelog/e; /^## /!d }" CHANGELOG.md @@ -53,7 +53,7 @@ if grep --silent -E "^## \[$VERSION\]" CHANGELOG.md; then else echo "Adding new section to CHANGELOG" - sed -iE "2r $current_changelog" CHANGELOG.md + sed -i -E "2r $current_changelog" CHANGELOG.md git add CHANGELOG.md git commit -m "Add changelog for $VERSION"