-
Notifications
You must be signed in to change notification settings - Fork 11
/
tag.sh
executable file
·66 lines (50 loc) · 1.99 KB
/
tag.sh
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
66
#!/bin/sh
# usage: ./tag.sh [BRANCH]
# Tag the latest release commit (i.e., a commit with a "Release-Version" trailer)
#
# This script should be run on the default branch after a version bump (using bump_version.sh) has
# been merged to the default branch. It will find and tag the latest release commit. If no branch
# argument is provided, the search will begin from HEAD.
#
# Note: After the commit is found, a check is performed to ensure that the commit is reachable from
# the default branch on the remote (origin/HEAD). To skip this check, set SKIP_ORIGIN_HEAD_CHECK=1
set -eu
SOURCE_BRANCH=HEAD
if [ -n "${1:-}" ]; then
SOURCE_BRANCH="$1"
fi
echo "Searching for latest release commit from ${SOURCE_BRANCH}"
TAG_COMMIT=$(git rev-list -i --grep='^release-version:' -1 "${SOURCE_BRANCH}")
if [ -z "${TAG_COMMIT}" ]; then
echo "No release commit found!" >&2
exit 1
fi
TAG=$(git log --pretty="format:%(trailers:key=release-version,valueonly)" -1 "${TAG_COMMIT}")
if git show "tags/${TAG}" > /dev/null 2>&1; then
echo "Tag ${TAG} already exists!" >&2
exit 1
fi
echo "Tagging this commit:"
git log --oneline -1 "${TAG_COMMIT}"
if [ -z "${SKIP_ORIGIN_HEAD_CHECK:-}" ]; then
# Check that the tag is being created on the default branch
git fetch origin >/dev/null
if ! git merge-base --is-ancestor "${TAG_COMMIT}" origin/HEAD; then
echo "WARNING! You are about to tag a commit that is not on the default branch!"
echo "Unless you are patching an old version, this is probably not what you want!"
printf "Are you sure? [y/N] "
read -r yn
if [ "${yn}" != "y" ] && [ "${yn}" != "Y" ]; then
echo "Aborting tag"
exit 1
fi
fi
fi
git tag --sign -m "Phylum CLI ${TAG}" "${TAG}" "${TAG_COMMIT}"
printf "\nOutput of the command: git show %s\n" "${TAG}"
git show "${TAG}"
cat << __instructions__
Successfully created tag!
Run the following command manually to push the new tag:
git push origin ${TAG}
__instructions__