Skip to content

Commit 57f776d

Browse files
committed
Update version and improve release script
1 parent 88c5984 commit 57f776d

File tree

1 file changed

+82
-13
lines changed

1 file changed

+82
-13
lines changed

release.sh

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

4-
# Usage: ./release.sh 1.2.3
4+
# Usage: ./release.sh <version> [npm-tag] [--dry-run]
55
VERSION=$1
6+
DRY_RUN=false
7+
NPM_TAG_SPECIFIED=false
8+
NPM_TAG="latest"
9+
10+
# Set default tag based on version format
11+
if [[ "$VERSION" =~ -beta ]]; then
12+
NPM_TAG="beta"
13+
elif [[ "$VERSION" =~ -alpha ]]; then
14+
NPM_TAG="alpha"
15+
elif [[ "$VERSION" =~ -rc ]]; then
16+
NPM_TAG="rc"
17+
elif [[ "$VERSION" =~ -experimental ]]; then
18+
NPM_TAG="experimental"
19+
fi
20+
21+
# Check for arguments and set flags
22+
for arg in "$@"; do
23+
if [[ "$arg" == "--dry-run" ]]; then
24+
DRY_RUN=true
25+
elif [[ "$arg" != "$VERSION" && "$arg" != "--dry-run" ]]; then
26+
# If argument is not the version and not --dry-run, treat it as the npm tag
27+
NPM_TAG="$arg"
28+
NPM_TAG_SPECIFIED=true
29+
fi
30+
done
631

732
if [ -z "$VERSION" ]; then
8-
echo "Usage: $0 <version>"
33+
echo "Usage: $0 <version> [npm-tag] [--dry-run]"
934
exit 1
1035
fi
1136

37+
# Detect current branch
38+
BRANCH=$(git rev-parse --abbrev-ref HEAD)
39+
40+
# Enforce branch/tag policy (customize as needed)
41+
if [[ "$BRANCH" == "main" && "$NPM_TAG" != "latest" && "$NPM_TAG_SPECIFIED" == false ]]; then
42+
echo "⚠️ Warning: Publishing a non-latest tag from main branch."
43+
echo "Continue? (y/n)"
44+
read -r CONTINUE
45+
if [[ "$CONTINUE" != "y" ]]; then
46+
echo "❌ Release cancelled."
47+
exit 1
48+
fi
49+
fi
50+
51+
if [[ "$BRANCH" != "main" && "$NPM_TAG" == "latest" ]]; then
52+
echo "⚠️ Warning: Publishing with tag '$NPM_TAG' from non-main branch."
53+
echo "Continue? (y/n)"
54+
read -r CONTINUE
55+
if [[ "$CONTINUE" != "y" ]]; then
56+
echo "❌ Release cancelled."
57+
exit 1
58+
fi
59+
fi
60+
61+
run() {
62+
if $DRY_RUN; then
63+
echo "[dry-run] $*"
64+
else
65+
eval "$@"
66+
fi
67+
}
68+
69+
# Version update
70+
echo ""
1271
echo "🔧 Setting version to $VERSION..."
13-
npm version "$VERSION" --no-git-tag-version
72+
run "npm version \"$VERSION\" --no-git-tag-version"
1473

74+
# README update
75+
echo ""
1576
echo "📝 Updating version in README.md..."
16-
sed -i '' "s/@[0-9]*\.[0-9]*\.[0-9]*/@$VERSION/g" README.md
77+
run "sed -i '' -E \"s/@[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.]+)?/@$VERSION/g\" README.md"
1778

18-
echo "🛠 Running build..."
19-
npm run build
79+
# Build
80+
echo ""
81+
echo "🛠 Running build..."
82+
run "npm run build"
2083

84+
# Git operations
85+
echo ""
2186
echo "📦 Committing changes..."
22-
git add .
23-
git commit -m "Release v$VERSION"
24-
git tag "v$VERSION"
87+
run "git add ."
88+
run "git commit -m \"Release v$VERSION\""
89+
run "git tag \"v$VERSION\""
2590

91+
echo ""
2692
echo "🚀 Pushing to origin..."
27-
git push origin main --tags
93+
run "git push origin $BRANCH --tags"
2894

29-
echo "📤 Publishing to npm..."
30-
npm publish
95+
# npm publish
96+
echo ""
97+
echo "📤 Publishing to npm with tag '$NPM_TAG'..."
98+
run "npm publish --tag $NPM_TAG"
3199

32-
echo "✅ Release v$VERSION complete!"
100+
# Completion message
33101
echo ""
102+
echo "✅ Release v$VERSION complete!"
34103
echo "📝 Don't forget to update the changelog"

0 commit comments

Comments
 (0)