-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathversion_tag.sh
More file actions
executable file
·65 lines (55 loc) · 1.95 KB
/
version_tag.sh
File metadata and controls
executable file
·65 lines (55 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash
# SPDX-FileCopyrightText: GitHub, Inc.
# 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\""