Skip to content

Commit a527740

Browse files
committed
Update relese script
1 parent 9dccaa6 commit a527740

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

bin/release.sh

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,50 @@
11
#!/usr/bin/env bash
22
set -e # Exit immediately on error
33

4-
# Ask for version number
5-
read -p "Enter new version (e.g., 1.3.2-beta-0): " VERSION
6-
7-
# Check if input is empty
8-
if [ -z "$VERSION" ]; then
9-
echo "❌ Version cannot be empty."
4+
# Ensure package.json exists
5+
if [ ! -f package.json ]; then
6+
echo "❌ package.json not found!"
107
exit 1
118
fi
129

13-
# Check if package.json exists
14-
if [ ! -f package.json ]; then
15-
echo "❌ package.json not found!"
10+
# Read current version from package.json
11+
CURRENT_VERSION=$(grep '"version"' package.json | sed -E 's/.*"version": *"([^"]+)".*/\1/')
12+
13+
if [[ -z "$CURRENT_VERSION" ]]; then
14+
echo "❌ Could not read current version from package.json"
1615
exit 1
1716
fi
1817

19-
# Update version field in package.json
18+
# Auto-increment patch version
19+
IFS='.' read -r MAJOR MINOR PATCH <<< "$(echo "$CURRENT_VERSION" | sed 's/-.*//')" # strip prerelease suffix for bump
20+
PATCH=$((PATCH + 1))
21+
DEFAULT_VERSION="${MAJOR}.${MINOR}.${PATCH}"
22+
23+
echo "Current version: $CURRENT_VERSION"
24+
read -p "Enter new version (press Enter for ${DEFAULT_VERSION}): " VERSION
25+
26+
# If empty, use default patch bump
27+
if [ -z "$VERSION" ]; then
28+
VERSION="$DEFAULT_VERSION"
29+
fi
30+
2031
echo "🔧 Updating package.json to version $VERSION..."
32+
2133
# Works on macOS and Linux
2234
sed -i.bak -E "s/\"version\": *\"[^\"]+\"/\"version\": \"$VERSION\"/" package.json
2335
rm -f package.json.bak
2436

25-
# Show updated version line for confirmation
2637
grep '"version"' package.json
2738

2839
# Commit the change
2940
git add package.json
3041
git commit -m "chore(release): bump version to $VERSION"
3142

32-
# Create a new git tag
43+
# Create tag
3344
TAG="v$VERSION"
3445
git tag -a "$TAG" -m "Release $TAG"
3546

36-
# Push changes and tag
47+
# Push
3748
git push origin main
3849
git push origin "$TAG"
3950

0 commit comments

Comments
 (0)