Skip to content

Commit 86d7091

Browse files
committed
Add script for tagging and pushing new versions
1 parent dae5024 commit 86d7091

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

publish.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
3+
# Usage: ./publish.sh [major|minor|patch]
4+
5+
VERSION_TYPE=$1
6+
7+
if [[ -z "$VERSION_TYPE" ]]; then
8+
echo "Please provide a version type (major, minor, patch)"
9+
exit 1
10+
fi
11+
12+
# Check for uncommitted changes
13+
if [[ -n "$(git status --porcelain)" ]]; then
14+
echo "Uncommitted changes found. Commit or stash your changes before tagging."
15+
exit 1
16+
fi
17+
18+
# Get the latest version tag from git
19+
LATEST_TAG=$(git describe --tags $(git rev-list --tags --max-count=1))
20+
21+
# Increment version using semantic versioning
22+
NEW_VERSION=$(php -r "
23+
list(\$major, \$minor, \$patch) = explode('.', '$LATEST_TAG');
24+
switch ('$VERSION_TYPE') {
25+
case 'major': \$major++; \$minor = 0; \$patch = 0; break;
26+
case 'minor': \$minor++; \$patch = 0; break;
27+
case 'patch': \$patch++; break;
28+
default: exit(1);
29+
}
30+
echo \$major . '.' . \$minor . '.' . \$patch;
31+
")
32+
33+
if [[ -z "$NEW_VERSION" ]]; then
34+
echo "Invalid version type"
35+
exit 1
36+
fi
37+
38+
# Tag the new version and push to remote
39+
git tag $NEW_VERSION
40+
git push origin $NEW_VERSION
41+
42+
echo "Tagged and pushed version $NEW_VERSION"

0 commit comments

Comments
 (0)