-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbump-tag.sh
More file actions
executable file
·152 lines (128 loc) · 3.61 KB
/
bump-tag.sh
File metadata and controls
executable file
·152 lines (128 loc) · 3.61 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/usr/bin/env bash
# File: `bump-patch.sh`
set -euo pipefail
# Find latest tag excluding major v0
LATEST_TAG=$(git tag --list --sort=-v:refname | head -n1 || true)
if [ -z "$LATEST_TAG" ]; then
echo "No suitable tag found (excluding v0). Aborting." >&2
exit 1
fi
# check that the working directory is clean
if [ -n "$(git status --porcelain)" ]; then
echo "Working directory is not clean. Please commit or stash changes before running this script." >&2
exit 1
fi
# check coverage timestamp before proceeding, to ensure tests have been run recently
tests/scripts/coverage/assert-coverage-timestamp.sh
usage() {
cat <<-EOF
Usage: $0 [--major | --minor | --patch]
LATEST_TAG: $LATEST_TAG
Options:
--major Bump major (MAJOR+1, MINOR=0, PATCH=0)
--minor Bump minor (MINOR+1, PATCH=0)
--patch Bump patch (PATCH+1) [default]
EOF
exit 1
}
# Parse options
opt_major=false
opt_minor=false
opt_patch=false
count=0
while [ $# -gt 0 ]; do
case "$1" in
--major)
opt_major=true
count=$((count + 1))
shift
;;
--minor)
opt_minor=true
count=$((count + 1))
shift
;;
--patch)
opt_patch=true
count=$((count + 1))
shift
;;
--help|-h)
usage
;;
*)
echo "Unknown option: $1" >&2
usage
;;
esac
done
# Default to patch if no option provided
if [ "$count" -eq 0 ]; then
opt_patch=true
fi
# Disallow specifying more than one
if [ "$count" -gt 1 ]; then
echo "Specify only one of --major, --minor, or --patch" >&2
exit 1
fi
# Parse semver vMAJOR.MINOR.PATCH
if [[ "$LATEST_TAG" =~ ^v?([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
MAJOR="${BASH_REMATCH[1]}"
MINOR="${BASH_REMATCH[2]}"
PATCH="${BASH_REMATCH[3]}"
else
echo "Latest tag '$LATEST_TAG' is not in semver format. Aborting." >&2
exit 1
fi
# Compute new version
if [ "$opt_major" = true ]; then
NEW_MAJOR=$((MAJOR + 1))
NEW_MINOR=0
NEW_PATCH=0
NEW_TAG="${NEW_MAJOR}.${NEW_MINOR}.${NEW_PATCH}"
NEW_FILE_VER="${NEW_MAJOR}.${NEW_MINOR}.${NEW_PATCH}"
elif [ "$opt_minor" = true ]; then
NEW_MAJOR=$MAJOR
NEW_MINOR=$((MINOR + 1))
NEW_PATCH=0
NEW_TAG="${NEW_MAJOR}.${NEW_MINOR}.${NEW_PATCH}"
NEW_FILE_VER="${NEW_MAJOR}.${NEW_MINOR}.${NEW_PATCH}"
else
# patch
NEW_MAJOR=$MAJOR
NEW_MINOR=$MINOR
NEW_PATCH=$((PATCH + 1))
NEW_TAG="${NEW_MAJOR}.${NEW_MINOR}.${NEW_PATCH}"
NEW_FILE_VER="${NEW_MAJOR}.${NEW_MINOR}.${NEW_PATCH}"
fi
BRANCH="$(git rev-parse --abbrev-ref HEAD)"
echo "Latest branch: $BRANCH"
echo "Latest tag: $LATEST_TAG"
echo "New tag: $NEW_TAG (files will use ${NEW_FILE_VER})"
# Update simple VERSION file if present
if [ -f VERSION ]; then
echo "${NEW_FILE_VER}" > VERSION
git add VERSION
fi
## Update version in pyproject.toml or setup.cfg or any file matching version = "x.y.z"
#for f in pyproject.toml setup.cfg $(git grep -Il 'version *= *"' || true); do
# [ -f "$f" ] || continue
# # macOS sed in-place
# sed -E -i '' -e "s/(version *= *\")[^\"]+(\")/\1${NEW_FILE_VER}\2/g" "$f" || true
# git add "$f"
#done
#
## Update Go internal version file if common pattern exists
#if [ -f internal/version/version.go ]; then
# sed -E -i '' -e "s/(Version *= *\")[^\"]+(\")/\1${NEW_FILE_VER}\2/" internal/version/version.go
# git add internal/version/version.go
#fi
# Run tests/builds (non-fatal for Python tests)
# Commit, tag and push
NEW_TAG="v${NEW_TAG}"
git commit -m "chore(release): bump to ${NEW_TAG}" || echo "No changes to commit"
git tag -a "${NEW_TAG}" -m "Release ${NEW_TAG}"
echo "Created tag. Please push tag ${NEW_TAG} on branch ${BRANCH}."
echo "To push, run:"
echo git push origin "${BRANCH}"
echo git push origin "${NEW_TAG}"