From 04efc8e73f83bf3343f80ae74f3178fb71d60727 Mon Sep 17 00:00:00 2001 From: Kevin Backhouse Date: Thu, 20 Nov 2025 15:47:01 +0000 Subject: [PATCH 01/16] Tools for updating the version number. --- release_tools/version_bump.sh | 55 ++++++++++++++++++++++++++++++++++ release_tools/version_tag.sh | 56 +++++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+) create mode 100755 release_tools/version_bump.sh create mode 100755 release_tools/version_tag.sh diff --git a/release_tools/version_bump.sh b/release_tools/version_bump.sh new file mode 100755 index 0000000..63674c3 --- /dev/null +++ b/release_tools/version_bump.sh @@ -0,0 +1,55 @@ +#!/bin/bash + +# SPDX-FileCopyrightText: 2025 GitHub +# SPDX-License-Identifier: MIT + +# Script for updating the version number. Call it like this: +# +# ./release_tools/version_bump minor +# +# It uses `hatch version` to update the version number. Use +# major/minor/micro to determine which part of the version number to +# bump. It creates a new branch and commits the version number +# change. +# +# This script does not push the change to GitHub, so you need to do +# that manually. + +if [[ $# -eq 0 ]] ; then + echo 'usage: new_version [ARG]' + echo 'ARG is passed to the hatch version command to bump the version number.' + echo 'ARG is usually "major", "minor", or "micro".' + exit 0 +fi + +# Check that the main branch is checked out. +if [ $(git rev-parse --abbrev-ref HEAD) != "main" ] ; then + echo "Please check out the main branch before running this command." + exit 1 +fi + +# Check no uncommitted changes. +git update-index --refresh +if ! git diff-index --quiet HEAD -- ; then + echo "There are uncommitted file changes. Aborting." + exit 1 +fi + +# Bump version number +hatch version $1 + +NEW_VERSION_NUMBER=$(hatch version) + +# Create new branch +if ! git checkout -b "version-$NEW_VERSION_NUMBER" ; then + echo "Creating the branch failed." + git restore . + exit 1 +fi + +# Commit the version number change. +git commit -a -m "Version $NEW_VERSION_NUMBER" + +echo +echo "I have updated the version number locally." +echo "The branch is ready for you to push to GitHub and create a pull request." diff --git a/release_tools/version_tag.sh b/release_tools/version_tag.sh new file mode 100755 index 0000000..e28bbc5 --- /dev/null +++ b/release_tools/version_tag.sh @@ -0,0 +1,56 @@ +#!/bin/bash + +# SPDX-FileCopyrightText: 2025 GitHub +# SPDX-License-Identifier: MIT + +# Create a signed tag for the new version number. This script is +# intended to be run after you have created a new version number +# (using `version_bump.sh` is recommended) and the change has been +# merged into main. +# +# This script does not push the tag to GitHub, so you need to do +# that manually. + +# Check that the main branch is checked out. +if [ $(git rev-parse --abbrev-ref HEAD) != "main" ] ; then + echo "Please check out the main branch before running this command." + exit 1 +fi + +# Check no uncommitted changes. +git update-index --refresh +if ! git diff-index --quiet HEAD -- ; then + echo "There are uncommitted file changes. Aborting." + exit 1 +fi + +# Check that this commit is signed by GitHub, to avoid +# accidentally tagging a commit that only exists locally. +if [ $(git verify-commit HEAD --raw 2>&1 | grep -E "GOODSIG [A-F0-9]+ GitHub" -c) -eq 0 ] ; then + echo "This commit hasn't been signed by GitHub." + echo "Please check that you are attempting to tag the correct commit." + exit 1 +fi + +# Check that this is a merge commit. +if ! git rev-parse HEAD^2 ; then + echo "This is not a merge commit." + echo "Please check that you are attempting to tag the correct commit." + exit 1 +fi + +PROJECT_NAME=$(hatch project metadata name) +VERSION_NUMBER=$(hatch version) +TAG_NAME="v$VERSION_NUMBER" + +# Create tag +if ! git tag $TAG_NAME -s -m "Release $PROJECT_NAME version $VERSION_NUMBER." ; then + echo "Failed to create the tag" + exit 1 +fi + +REMOTE_NAME=$(git for-each-ref --format='%(upstream:remotename)' refs/heads/main) + +echo +echo "I have created tag $TAG_NAME. You can push it to GitHub like this:" +echo "git push $REMOTE_NAME tag $TAG_NAME" From eefbaab1ebf8e33a5b6a4815e957ab1ef8869e2c Mon Sep 17 00:00:00 2001 From: Kevin Backhouse Date: Thu, 20 Nov 2025 15:53:15 +0000 Subject: [PATCH 02/16] Update release_tools/version_bump.sh Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- release_tools/version_bump.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/release_tools/version_bump.sh b/release_tools/version_bump.sh index 63674c3..14d66c1 100755 --- a/release_tools/version_bump.sh +++ b/release_tools/version_bump.sh @@ -16,7 +16,7 @@ # that manually. if [[ $# -eq 0 ]] ; then - echo 'usage: new_version [ARG]' + echo 'usage: ./release_tools/version_bump.sh [ARG]' echo 'ARG is passed to the hatch version command to bump the version number.' echo 'ARG is usually "major", "minor", or "micro".' exit 0 From efd81c8fbefecb9ec78069fad01fc628a964e474 Mon Sep 17 00:00:00 2001 From: Kevin Backhouse Date: Thu, 20 Nov 2025 15:54:08 +0000 Subject: [PATCH 03/16] Update release_tools/version_bump.sh Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- release_tools/version_bump.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/release_tools/version_bump.sh b/release_tools/version_bump.sh index 14d66c1..490dd0c 100755 --- a/release_tools/version_bump.sh +++ b/release_tools/version_bump.sh @@ -23,7 +23,7 @@ if [[ $# -eq 0 ]] ; then fi # Check that the main branch is checked out. -if [ $(git rev-parse --abbrev-ref HEAD) != "main" ] ; then +if [ "$(git rev-parse --abbrev-ref HEAD)" != "main" ] ; then echo "Please check out the main branch before running this command." exit 1 fi From 25eaa707ca22c8689ae82e59f1db0e99fec90b92 Mon Sep 17 00:00:00 2001 From: Kevin Backhouse Date: Thu, 20 Nov 2025 15:54:17 +0000 Subject: [PATCH 04/16] Update release_tools/version_tag.sh Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- release_tools/version_tag.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/release_tools/version_tag.sh b/release_tools/version_tag.sh index e28bbc5..1bf299b 100755 --- a/release_tools/version_tag.sh +++ b/release_tools/version_tag.sh @@ -12,7 +12,7 @@ # that manually. # Check that the main branch is checked out. -if [ $(git rev-parse --abbrev-ref HEAD) != "main" ] ; then +if [ "$(git rev-parse --abbrev-ref HEAD)" != "main" ] ; then echo "Please check out the main branch before running this command." exit 1 fi From a6202f419b5b4717910ae9601ab15a0a5f070986 Mon Sep 17 00:00:00 2001 From: Kevin Backhouse Date: Thu, 20 Nov 2025 17:09:33 +0000 Subject: [PATCH 05/16] Update release_tools/version_tag.sh Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- release_tools/version_tag.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/release_tools/version_tag.sh b/release_tools/version_tag.sh index 1bf299b..796a3d5 100755 --- a/release_tools/version_tag.sh +++ b/release_tools/version_tag.sh @@ -44,7 +44,7 @@ VERSION_NUMBER=$(hatch version) TAG_NAME="v$VERSION_NUMBER" # Create tag -if ! git tag $TAG_NAME -s -m "Release $PROJECT_NAME version $VERSION_NUMBER." ; then +if ! git tag "$TAG_NAME" -s -m "Release $PROJECT_NAME version $VERSION_NUMBER." ; then echo "Failed to create the tag" exit 1 fi From 34065c29d71a8ae5d23f058adc3d78a1a707e39d Mon Sep 17 00:00:00 2001 From: Kevin Backhouse Date: Thu, 20 Nov 2025 17:11:57 +0000 Subject: [PATCH 06/16] Add error handling code --- release_tools/version_tag.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/release_tools/version_tag.sh b/release_tools/version_tag.sh index 796a3d5..354b58d 100755 --- a/release_tools/version_tag.sh +++ b/release_tools/version_tag.sh @@ -50,6 +50,9 @@ if ! git tag "$TAG_NAME" -s -m "Release $PROJECT_NAME version $VERSION_NUMBER." fi REMOTE_NAME=$(git for-each-ref --format='%(upstream:remotename)' refs/heads/main) +if [ -z "$REMOTE_NAME" ]; then + REMOTE_NAME="origin" +fi echo echo "I have created tag $TAG_NAME. You can push it to GitHub like this:" From 7d181926c211d53772eb753b2ae70c6ed306c59b Mon Sep 17 00:00:00 2001 From: Kevin Backhouse Date: Thu, 20 Nov 2025 17:14:22 +0000 Subject: [PATCH 07/16] Update release_tools/version_tag.sh Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- release_tools/version_tag.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/release_tools/version_tag.sh b/release_tools/version_tag.sh index 354b58d..8561334 100755 --- a/release_tools/version_tag.sh +++ b/release_tools/version_tag.sh @@ -56,4 +56,4 @@ fi echo echo "I have created tag $TAG_NAME. You can push it to GitHub like this:" -echo "git push $REMOTE_NAME tag $TAG_NAME" +echo "git push \"$REMOTE_NAME\" tag \"$TAG_NAME\"" From 0bfb548f12a14a8f0ac32fa009b4bed3dd5365fa Mon Sep 17 00:00:00 2001 From: Kevin Backhouse Date: Thu, 20 Nov 2025 17:14:59 +0000 Subject: [PATCH 08/16] Update release_tools/version_bump.sh Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- release_tools/version_bump.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/release_tools/version_bump.sh b/release_tools/version_bump.sh index 490dd0c..a82f625 100755 --- a/release_tools/version_bump.sh +++ b/release_tools/version_bump.sh @@ -36,7 +36,10 @@ if ! git diff-index --quiet HEAD -- ; then fi # Bump version number -hatch version $1 +if ! hatch version "$1" ; then + echo "Failed to update version" + exit 1 +fi NEW_VERSION_NUMBER=$(hatch version) From 2c1a84d4bdc9f88346e6ec2aa7676304c9ad9ecd Mon Sep 17 00:00:00 2001 From: Kevin Backhouse Date: Thu, 20 Nov 2025 17:15:37 +0000 Subject: [PATCH 09/16] Update release_tools/version_tag.sh Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- release_tools/version_tag.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/release_tools/version_tag.sh b/release_tools/version_tag.sh index 8561334..40a1167 100755 --- a/release_tools/version_tag.sh +++ b/release_tools/version_tag.sh @@ -33,7 +33,7 @@ if [ $(git verify-commit HEAD --raw 2>&1 | grep -E "GOODSIG [A-F0-9]+ GitHub" -c fi # Check that this is a merge commit. -if ! git rev-parse HEAD^2 ; then +if ! git rev-parse HEAD^2 >/dev/null 2>&1 ; then echo "This is not a merge commit." echo "Please check that you are attempting to tag the correct commit." exit 1 From 593cefd39a69666b941e03bc36b62425cf63c1e0 Mon Sep 17 00:00:00 2001 From: Kevin Backhouse Date: Thu, 20 Nov 2025 17:41:09 +0000 Subject: [PATCH 10/16] Update release_tools/version_tag.sh Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- release_tools/version_tag.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/release_tools/version_tag.sh b/release_tools/version_tag.sh index 40a1167..fd0e384 100755 --- a/release_tools/version_tag.sh +++ b/release_tools/version_tag.sh @@ -26,7 +26,7 @@ fi # Check that this commit is signed by GitHub, to avoid # accidentally tagging a commit that only exists locally. -if [ $(git verify-commit HEAD --raw 2>&1 | grep -E "GOODSIG [A-F0-9]+ GitHub" -c) -eq 0 ] ; then +if [ "$(git verify-commit HEAD --raw 2>&1 | grep -E "GOODSIG [A-F0-9]+ GitHub" -c)" -eq 0 ] ; then echo "This commit hasn't been signed by GitHub." echo "Please check that you are attempting to tag the correct commit." exit 1 From aa32f302fde919b827f780ae90b983ccd8414e43 Mon Sep 17 00:00:00 2001 From: Kevin Backhouse Date: Thu, 20 Nov 2025 17:46:31 +0000 Subject: [PATCH 11/16] Allow multiple args to hatch version --- release_tools/version_bump.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/release_tools/version_bump.sh b/release_tools/version_bump.sh index a82f625..7366fd2 100755 --- a/release_tools/version_bump.sh +++ b/release_tools/version_bump.sh @@ -36,7 +36,7 @@ if ! git diff-index --quiet HEAD -- ; then fi # Bump version number -if ! hatch version "$1" ; then +if ! hatch version "$@" ; then echo "Failed to update version" exit 1 fi From d7d9f14c345aa1f1e471192d03a7adf4ecd42941 Mon Sep 17 00:00:00 2001 From: Kevin Backhouse Date: Thu, 20 Nov 2025 17:50:27 +0000 Subject: [PATCH 12/16] More error handling --- release_tools/version_bump.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/release_tools/version_bump.sh b/release_tools/version_bump.sh index 7366fd2..96958cf 100755 --- a/release_tools/version_bump.sh +++ b/release_tools/version_bump.sh @@ -51,7 +51,10 @@ if ! git checkout -b "version-$NEW_VERSION_NUMBER" ; then fi # Commit the version number change. -git commit -a -m "Version $NEW_VERSION_NUMBER" +if ! git commit -a -m "Version $NEW_VERSION_NUMBER" ; then + echo "git commit failed" + exit 1 +fi echo echo "I have updated the version number locally." From b25e32f1a779c6784156219d4c95896dd0d94144 Mon Sep 17 00:00:00 2001 From: Kevin Backhouse Date: Thu, 20 Nov 2025 17:51:15 +0000 Subject: [PATCH 13/16] Remove trailing whitespace --- release_tools/version_bump.sh | 2 +- release_tools/version_tag.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/release_tools/version_bump.sh b/release_tools/version_bump.sh index 96958cf..4e7693a 100755 --- a/release_tools/version_bump.sh +++ b/release_tools/version_bump.sh @@ -29,7 +29,7 @@ if [ "$(git rev-parse --abbrev-ref HEAD)" != "main" ] ; then fi # Check no uncommitted changes. -git update-index --refresh +git update-index --refresh if ! git diff-index --quiet HEAD -- ; then echo "There are uncommitted file changes. Aborting." exit 1 diff --git a/release_tools/version_tag.sh b/release_tools/version_tag.sh index fd0e384..d090819 100755 --- a/release_tools/version_tag.sh +++ b/release_tools/version_tag.sh @@ -18,7 +18,7 @@ if [ "$(git rev-parse --abbrev-ref HEAD)" != "main" ] ; then fi # Check no uncommitted changes. -git update-index --refresh +git update-index --refresh if ! git diff-index --quiet HEAD -- ; then echo "There are uncommitted file changes. Aborting." exit 1 From e6e766e3c80bf0a93103b0c9f36ec8e87c317768 Mon Sep 17 00:00:00 2001 From: Kevin Backhouse Date: Thu, 20 Nov 2025 17:52:23 +0000 Subject: [PATCH 14/16] Update release_tools/version_bump.sh Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- release_tools/version_bump.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/release_tools/version_bump.sh b/release_tools/version_bump.sh index 4e7693a..239f441 100755 --- a/release_tools/version_bump.sh +++ b/release_tools/version_bump.sh @@ -5,7 +5,7 @@ # Script for updating the version number. Call it like this: # -# ./release_tools/version_bump minor +# ./release_tools/version_bump.sh minor # # It uses `hatch version` to update the version number. Use # major/minor/micro to determine which part of the version number to From d48926144af55afb7d36d7ac2a9f10c44360fdf4 Mon Sep 17 00:00:00 2001 From: Kevin Backhouse Date: Thu, 20 Nov 2025 17:53:58 +0000 Subject: [PATCH 15/16] Update release_tools/version_tag.sh Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- release_tools/version_tag.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/release_tools/version_tag.sh b/release_tools/version_tag.sh index d090819..485c5eb 100755 --- a/release_tools/version_tag.sh +++ b/release_tools/version_tag.sh @@ -39,8 +39,14 @@ if ! git rev-parse HEAD^2 >/dev/null 2>&1 ; then exit 1 fi -PROJECT_NAME=$(hatch project metadata name) -VERSION_NUMBER=$(hatch version) +if ! PROJECT_NAME=$(hatch project metadata name) ; then + echo "Failed to retrieve project name." + exit 1 +fi +if ! VERSION_NUMBER=$(hatch version) ; then + echo "Failed to retrieve version number." + exit 1 +fi TAG_NAME="v$VERSION_NUMBER" # Create tag From 37e557d9a489c42aab3a4e357318c05cad570ae9 Mon Sep 17 00:00:00 2001 From: Kevin Backhouse Date: Thu, 20 Nov 2025 17:59:01 +0000 Subject: [PATCH 16/16] More error checking --- release_tools/version_bump.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/release_tools/version_bump.sh b/release_tools/version_bump.sh index 239f441..01883e8 100755 --- a/release_tools/version_bump.sh +++ b/release_tools/version_bump.sh @@ -41,7 +41,11 @@ if ! hatch version "$@" ; then exit 1 fi -NEW_VERSION_NUMBER=$(hatch version) +# Read new version number +if ! NEW_VERSION_NUMBER=$(hatch version) ; then + echo "Failed to retrieve version number." + exit 1 +fi # Create new branch if ! git checkout -b "version-$NEW_VERSION_NUMBER" ; then