Skip to content

Commit 04efc8e

Browse files
Tools for updating the version number.
1 parent cb49ece commit 04efc8e

File tree

2 files changed

+111
-0
lines changed

2 files changed

+111
-0
lines changed

release_tools/version_bump.sh

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/bin/bash
2+
3+
# SPDX-FileCopyrightText: 2025 GitHub
4+
# SPDX-License-Identifier: MIT
5+
6+
# Script for updating the version number. Call it like this:
7+
#
8+
# ./release_tools/version_bump minor
9+
#
10+
# It uses `hatch version` to update the version number. Use
11+
# major/minor/micro to determine which part of the version number to
12+
# bump. It creates a new branch and commits the version number
13+
# change.
14+
#
15+
# This script does not push the change to GitHub, so you need to do
16+
# that manually.
17+
18+
if [[ $# -eq 0 ]] ; then
19+
echo 'usage: new_version [ARG]'
20+
echo 'ARG is passed to the hatch version command to bump the version number.'
21+
echo 'ARG is usually "major", "minor", or "micro".'
22+
exit 0
23+
fi
24+
25+
# Check that the main branch is checked out.
26+
if [ $(git rev-parse --abbrev-ref HEAD) != "main" ] ; then
27+
echo "Please check out the main branch before running this command."
28+
exit 1
29+
fi
30+
31+
# Check no uncommitted changes.
32+
git update-index --refresh
33+
if ! git diff-index --quiet HEAD -- ; then
34+
echo "There are uncommitted file changes. Aborting."
35+
exit 1
36+
fi
37+
38+
# Bump version number
39+
hatch version $1
40+
41+
NEW_VERSION_NUMBER=$(hatch version)
42+
43+
# Create new branch
44+
if ! git checkout -b "version-$NEW_VERSION_NUMBER" ; then
45+
echo "Creating the branch failed."
46+
git restore .
47+
exit 1
48+
fi
49+
50+
# Commit the version number change.
51+
git commit -a -m "Version $NEW_VERSION_NUMBER"
52+
53+
echo
54+
echo "I have updated the version number locally."
55+
echo "The branch is ready for you to push to GitHub and create a pull request."

release_tools/version_tag.sh

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/bin/bash
2+
3+
# SPDX-FileCopyrightText: 2025 GitHub
4+
# SPDX-License-Identifier: MIT
5+
6+
# Create a signed tag for the new version number. This script is
7+
# intended to be run after you have created a new version number
8+
# (using `version_bump.sh` is recommended) and the change has been
9+
# merged into main.
10+
#
11+
# This script does not push the tag to GitHub, so you need to do
12+
# that manually.
13+
14+
# Check that the main branch is checked out.
15+
if [ $(git rev-parse --abbrev-ref HEAD) != "main" ] ; then
16+
echo "Please check out the main branch before running this command."
17+
exit 1
18+
fi
19+
20+
# Check no uncommitted changes.
21+
git update-index --refresh
22+
if ! git diff-index --quiet HEAD -- ; then
23+
echo "There are uncommitted file changes. Aborting."
24+
exit 1
25+
fi
26+
27+
# Check that this commit is signed by GitHub, to avoid
28+
# accidentally tagging a commit that only exists locally.
29+
if [ $(git verify-commit HEAD --raw 2>&1 | grep -E "GOODSIG [A-F0-9]+ GitHub" -c) -eq 0 ] ; then
30+
echo "This commit hasn't been signed by GitHub."
31+
echo "Please check that you are attempting to tag the correct commit."
32+
exit 1
33+
fi
34+
35+
# Check that this is a merge commit.
36+
if ! git rev-parse HEAD^2 ; then
37+
echo "This is not a merge commit."
38+
echo "Please check that you are attempting to tag the correct commit."
39+
exit 1
40+
fi
41+
42+
PROJECT_NAME=$(hatch project metadata name)
43+
VERSION_NUMBER=$(hatch version)
44+
TAG_NAME="v$VERSION_NUMBER"
45+
46+
# Create tag
47+
if ! git tag $TAG_NAME -s -m "Release $PROJECT_NAME version $VERSION_NUMBER." ; then
48+
echo "Failed to create the tag"
49+
exit 1
50+
fi
51+
52+
REMOTE_NAME=$(git for-each-ref --format='%(upstream:remotename)' refs/heads/main)
53+
54+
echo
55+
echo "I have created tag $TAG_NAME. You can push it to GitHub like this:"
56+
echo "git push $REMOTE_NAME tag $TAG_NAME"

0 commit comments

Comments
 (0)