Skip to content

Commit 7023b08

Browse files
committed
refactor(scripts): ♻️ Improve release script to handle version increments
- Add support for major, minor, and patch version increments - Ensure package-lock.json is updated alongside package.json
1 parent 49c3963 commit 7023b08

1 file changed

Lines changed: 30 additions & 4 deletions

File tree

scripts/release.sh

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
#!/bin/bash
22
set -e
33

4+
# Usage: ./release.sh [major|minor|patch]
5+
release_type=${1:-patch}
6+
if [[ "$release_type" != "major" && "$release_type" != "minor" && "$release_type" != "patch" ]]; then
7+
echo "Usage: $0 [major|minor|patch]"
8+
exit 1
9+
fi
10+
411
# Ensure jq is installed
512
if ! command -v jq &> /dev/null; then
613
echo "Error: jq is required but not installed."
@@ -21,16 +28,35 @@ git tag "v$current_version"
2128
# Split the current version into major, minor, and patch components
2229
IFS='.' read -r major minor patch <<< "$current_version"
2330

24-
# Increment the patch version
25-
new_patch=$((patch + 1))
26-
new_version="${major}.${minor}.${new_patch}"
31+
# Increment the version based on the release type
32+
case "$release_type" in
33+
major)
34+
major=$((major + 1))
35+
minor=0
36+
patch=0
37+
;;
38+
minor)
39+
minor=$((minor + 1))
40+
patch=0
41+
;;
42+
patch)
43+
patch=$((patch + 1))
44+
;;
45+
esac
46+
47+
new_version="${major}.${minor}.${patch}"
2748
echo "New version: $new_version"
2849

2950
# Update package.json with the new version
3051
jq --arg new_version "$new_version" '.version = $new_version' package.json > tmp.$$.json && mv tmp.$$.json package.json
3152

53+
# Update package-lock.json with the new version if it exists
54+
if [ -f package-lock.json ]; then
55+
jq --arg new_version "$new_version" '.version = $new_version' package-lock.json > tmp.$$.lock && mv tmp.$$.lock package-lock.json
56+
fi
57+
3258
# Stage and commit the version bump
33-
git add package.json
59+
git add package.json package-lock.json
3460
git commit -m "Bump version to $new_version"
3561

3662
# Push the commit and the tag to the remote repository (assuming main branch)

0 commit comments

Comments
 (0)