Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions release_tools/version_bump.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/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: ./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
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
if ! hatch version "$@" ; then
echo "Failed to update version"
exit 1
fi

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.
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."
echo "The branch is ready for you to push to GitHub and create a pull request."
59 changes: 59 additions & 0 deletions release_tools/version_tag.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/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 >/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
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)
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:"
echo "git push \"$REMOTE_NAME\" tag \"$TAG_NAME\""