Skip to content

Commit de7552b

Browse files
committed
add release script
1 parent b9dde90 commit de7552b

File tree

1 file changed

+94
-0
lines changed

1 file changed

+94
-0
lines changed

tag-release.sh

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
FORCE=false
5+
VERSION=""
6+
7+
usage() {
8+
echo "Usage: ./tag-release.sh [-f] <version>"
9+
echo ""
10+
echo "Sets the project version, commits, and creates a git tag."
11+
echo ""
12+
echo "Arguments:"
13+
echo " version Release version (e.g. 0.2.0). Must not contain SNAPSHOT."
14+
echo ""
15+
echo "Options:"
16+
echo " -f Force update the tag if it already exists"
17+
echo " -h Show this help message"
18+
echo ""
19+
echo "Examples:"
20+
echo " ./tag-release.sh 0.2.0"
21+
echo " ./tag-release.sh -f 0.2.0 # overwrite existing v0.2.0 tag"
22+
}
23+
24+
while getopts ":fh" opt; do
25+
case $opt in
26+
f) FORCE=true ;;
27+
h) usage; exit 0 ;;
28+
*) echo "Error: Unknown option -$OPTARG"; echo ""; usage; exit 1 ;;
29+
esac
30+
done
31+
shift $((OPTIND - 1))
32+
33+
VERSION="${1:-}"
34+
35+
if [ -z "$VERSION" ]; then
36+
echo "Error: Version argument is required"
37+
echo ""
38+
usage
39+
exit 1
40+
fi
41+
42+
if [[ "$VERSION" == *SNAPSHOT* ]]; then
43+
echo "Error: Release version must not contain SNAPSHOT"
44+
exit 1
45+
fi
46+
47+
# Ensure working tree is clean
48+
if [ -n "$(git status --porcelain)" ]; then
49+
echo "Error: Working tree is not clean. Commit or stash changes first."
50+
exit 1
51+
fi
52+
53+
TAG="v${VERSION}"
54+
55+
if git rev-parse "$TAG" >/dev/null 2>&1; then
56+
if [ "$FORCE" = true ]; then
57+
echo "Warning: Tag $TAG already exists, will be overwritten (-f)"
58+
else
59+
echo "Error: Tag $TAG already exists (use -f to overwrite)"
60+
exit 1
61+
fi
62+
fi
63+
64+
echo "Releasing version $VERSION..."
65+
66+
# Update preflight-core/build.gradle.kts
67+
sed -i "s/^val PROJECT_VERSION = \".*\"/val PROJECT_VERSION = \"$VERSION\"/" preflight-core/build.gradle.kts
68+
69+
# Update preflight-spec/build.gradle.kts
70+
sed -i "s/^version = \".*\"/version = \"$VERSION\"/" preflight-spec/build.gradle.kts
71+
72+
echo "Updated preflight-core/build.gradle.kts"
73+
echo "Updated preflight-spec/build.gradle.kts"
74+
75+
git add preflight-core/build.gradle.kts preflight-spec/build.gradle.kts
76+
git commit -m "Release $VERSION"
77+
78+
if [ "$FORCE" = true ]; then
79+
git tag -f "$TAG"
80+
else
81+
git tag "$TAG"
82+
fi
83+
84+
echo ""
85+
echo "Release $VERSION complete."
86+
echo " Commit: $(git rev-parse --short HEAD)"
87+
echo " Tag: $TAG"
88+
echo ""
89+
echo "To publish:"
90+
if [ "$FORCE" = true ]; then
91+
echo " git push origin main $TAG --force"
92+
else
93+
echo " git push origin main $TAG"
94+
fi

0 commit comments

Comments
 (0)