diff --git a/release_tools/version_bump.sh b/release_tools/version_bump.sh new file mode 100755 index 0000000..01883e8 --- /dev/null +++ b/release_tools/version_bump.sh @@ -0,0 +1,65 @@ +#!/bin/bash + +# SPDX-FileCopyrightText: 2025 GitHub +# SPDX-License-Identifier: MIT + +# Script for updating the version number. Call it like this: +# +# ./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 +# 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 + +# 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 + 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." diff --git a/release_tools/version_tag.sh b/release_tools/version_tag.sh new file mode 100755 index 0000000..485c5eb --- /dev/null +++ b/release_tools/version_tag.sh @@ -0,0 +1,65 @@ +#!/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 + +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 +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\""