Skip to content

Commit 6232ab6

Browse files
committed
Add local script to auto-bump the next v1.x.x release tag
Reads the highest existing v1.*.* tag and creates the next major/minor/patch tag without having to check git tag list manually. Local convenience only, not used by CI.
1 parent 4cae767 commit 6232ab6

1 file changed

Lines changed: 60 additions & 0 deletions

File tree

scripts/tag-release.sh

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/env bash
2+
# Create the next v1.<minor>.<patch> git tag based on the highest existing tag.
3+
#
4+
# Usage: scripts/tag-release.sh [major|minor|patch] [--push]
5+
# major/minor/patch defaults to "patch"
6+
# --push also pushes the new tag to origin
7+
8+
set -euo pipefail
9+
10+
bump="${1:-patch}"
11+
push=false
12+
for arg in "$@"; do
13+
if [[ "$arg" == "--push" ]]; then
14+
push=true
15+
fi
16+
done
17+
18+
if [[ "$bump" != "major" && "$bump" != "minor" && "$bump" != "patch" ]]; then
19+
echo "Usage: $0 [major|minor|patch] [--push]" >&2
20+
exit 1
21+
fi
22+
23+
latest=$(git tag --list 'v1.*.*' | sort -V | tail -1)
24+
25+
if [[ -z "$latest" ]]; then
26+
major=1
27+
minor=0
28+
patch=0
29+
else
30+
version="${latest#v}"
31+
IFS='.' read -r major minor patch <<< "$version"
32+
fi
33+
34+
case "$bump" in
35+
major)
36+
major=$((major + 1))
37+
minor=0
38+
patch=0
39+
;;
40+
minor)
41+
minor=$((minor + 1))
42+
patch=0
43+
;;
44+
patch)
45+
patch=$((patch + 1))
46+
;;
47+
esac
48+
49+
new_tag="v${major}.${minor}.${patch}"
50+
51+
echo "Latest tag: ${latest:-<none>}"
52+
echo "New tag: ${new_tag}"
53+
54+
git tag "$new_tag"
55+
56+
if [[ "$push" == true ]]; then
57+
git push origin "$new_tag"
58+
else
59+
echo "Tag created locally. Push it with: git push origin ${new_tag}"
60+
fi

0 commit comments

Comments
 (0)