Skip to content

Commit 97cd6ae

Browse files
committed
chore(release): add scripts/create_release_tag.sh to tag current version with optional --push
1 parent d564bee commit 97cd6ae

2 files changed

Lines changed: 96 additions & 1 deletion

File tree

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
logstruct (0.1.0)
4+
logstruct (0.0.2.pre.rc1)
55
lograge (>= 0.11)
66
rails (>= 7.0)
77
semantic_logger (~> 4.15)

scripts/create_release_tag.sh

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# Create a git tag for the current LogStruct version.
5+
# - Reads version from lib/log_struct/version.rb by default
6+
# - Validates that the working tree is clean (unless --allow-dirty)
7+
# - Validates that the tag does not already exist locally or on origin
8+
# - Creates an annotated tag: vX.Y.Z or vX.Y.Z-rcN
9+
# - Optional: --push to push the tag to origin
10+
11+
usage() {
12+
cat <<'USAGE'
13+
Usage: bash scripts/create_release_tag.sh [--version X.Y.Z[-rcN]] [--push] [--allow-dirty] [--force]
14+
15+
Options:
16+
--version Override version (default: read from version.rb)
17+
--push Push the created tag to origin
18+
--allow-dirty Allow running with uncommitted changes
19+
--force Skip version.rb vs --version check
20+
-h, --help Show this help
21+
22+
Examples:
23+
bash scripts/create_release_tag.sh # uses version.rb
24+
bash scripts/create_release_tag.sh --push # create + push
25+
bash scripts/create_release_tag.sh --version 0.0.2-rc1 --push
26+
USAGE
27+
}
28+
29+
VERSION_OVERRIDE=""
30+
PUSH=false
31+
ALLOW_DIRTY=false
32+
FORCE=false
33+
34+
while [[ $# -gt 0 ]]; do
35+
case "$1" in
36+
--version)
37+
VERSION_OVERRIDE="${2:-}"; shift 2 ;;
38+
--push)
39+
PUSH=true; shift ;;
40+
--allow-dirty)
41+
ALLOW_DIRTY=true; shift ;;
42+
--force)
43+
FORCE=true; shift ;;
44+
-h|--help)
45+
usage; exit 0 ;;
46+
*)
47+
echo "Unknown argument: $1" >&2; usage; exit 1 ;;
48+
esac
49+
done
50+
51+
# Read version from version.rb
52+
VERSION_RB=$(ruby -e 'print File.read("lib/log_struct/version.rb")[/VERSION\s*=\s*"([^"]+)"/,1]')
53+
if [[ -z "$VERSION_RB" ]]; then
54+
echo "Error: Could not read version from lib/log_struct/version.rb" >&2
55+
exit 1
56+
fi
57+
58+
VERSION="${VERSION_OVERRIDE:-$VERSION_RB}"
59+
TAG="v$VERSION"
60+
61+
if [[ -n "$VERSION_OVERRIDE" && "$FORCE" != true && "$VERSION_OVERRIDE" != "$VERSION_RB" ]]; then
62+
echo "Error: --version ($VERSION_OVERRIDE) does not match version.rb ($VERSION_RB). Use --force to skip." >&2
63+
exit 1
64+
fi
65+
66+
# Ensure clean working tree unless allowed
67+
if [[ "$ALLOW_DIRTY" != true ]]; then
68+
if [[ -n $(git status --porcelain) ]]; then
69+
echo "Error: Working tree has uncommitted changes. Commit or stash, or pass --allow-dirty." >&2
70+
git status --porcelain
71+
exit 1
72+
fi
73+
fi
74+
75+
# Ensure tag doesn't already exist
76+
if git rev-parse -q --verify "refs/tags/$TAG" >/dev/null; then
77+
echo "Error: Local tag $TAG already exists." >&2
78+
exit 1
79+
fi
80+
if git ls-remote --exit-code --tags origin "$TAG" >/dev/null 2>&1; then
81+
echo "Error: Remote tag $TAG already exists on origin." >&2
82+
exit 1
83+
fi
84+
85+
echo "Creating annotated tag $TAG"
86+
git tag -a "$TAG" -m "Release $TAG"
87+
88+
if [[ "$PUSH" == true ]]; then
89+
echo "Pushing tag $TAG to origin"
90+
git push origin "$TAG"
91+
else
92+
echo "Tag created locally: $TAG"
93+
echo "Push with: git push origin $TAG"
94+
fi
95+

0 commit comments

Comments
 (0)