-
Notifications
You must be signed in to change notification settings - Fork 6
Tools for updating the version number #89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
kevinbackhouse
merged 16 commits into
GitHubSecurityLab:main
from
kevinbackhouse:version-tools
Nov 21, 2025
Merged
Changes from 13 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
04efc8e
Tools for updating the version number.
kevinbackhouse eefbaab
Update release_tools/version_bump.sh
kevinbackhouse efd81c8
Update release_tools/version_bump.sh
kevinbackhouse 25eaa70
Update release_tools/version_tag.sh
kevinbackhouse a6202f4
Update release_tools/version_tag.sh
kevinbackhouse 34065c2
Add error handling code
kevinbackhouse 7d18192
Update release_tools/version_tag.sh
kevinbackhouse 0bfb548
Update release_tools/version_bump.sh
kevinbackhouse 2c1a84d
Update release_tools/version_tag.sh
kevinbackhouse 593cefd
Update release_tools/version_tag.sh
kevinbackhouse aa32f30
Allow multiple args to hatch version
kevinbackhouse d7d9f14
More error handling
kevinbackhouse b25e32f
Remove trailing whitespace
kevinbackhouse e6e766e
Update release_tools/version_bump.sh
kevinbackhouse d489261
Update release_tools/version_tag.sh
kevinbackhouse 37e557d
More error checking
kevinbackhouse File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
kevinbackhouse marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| # Create new branch | ||
| if ! git checkout -b "version-$NEW_VERSION_NUMBER" ; then | ||
| echo "Creating the branch failed." | ||
| git restore . | ||
kevinbackhouse marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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." | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
kevinbackhouse marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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 | ||
kevinbackhouse marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| REMOTE_NAME="origin" | ||
| fi | ||
|
|
||
kevinbackhouse marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| echo | ||
| echo "I have created tag $TAG_NAME. You can push it to GitHub like this:" | ||
| echo "git push \"$REMOTE_NAME\" tag \"$TAG_NAME\"" | ||
kevinbackhouse marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.