Skip to content

Commit 052bbcc

Browse files
committed
add release script
1 parent b08e12a commit 052bbcc

1 file changed

Lines changed: 92 additions & 0 deletions

File tree

release.sh

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Colors for output
6+
RED='\033[0;31m'
7+
GREEN='\033[0;32m'
8+
YELLOW='\033[1;33m'
9+
NC='\033[0m' # No Color
10+
11+
# Function to display usage
12+
usage() {
13+
echo "Usage: $0 <major|minor|patch>"
14+
echo " major: Bump major version (1.0.0 -> 2.0.0)"
15+
echo " minor: Bump minor version (1.0.0 -> 1.1.0)"
16+
echo " patch: Bump patch version (1.0.0 -> 1.0.1)"
17+
exit 1
18+
}
19+
20+
# Check if argument is provided
21+
if [ $# -ne 1 ]; then
22+
usage
23+
fi
24+
25+
BUMP_TYPE=$1
26+
27+
# Validate bump type
28+
if [[ ! "$BUMP_TYPE" =~ ^(major|minor|patch)$ ]]; then
29+
echo -e "${RED}Error: Invalid bump type '$BUMP_TYPE'${NC}"
30+
usage
31+
fi
32+
33+
# Check if working directory is clean
34+
if [[ -n $(git status --porcelain) ]]; then
35+
echo -e "${RED}Error: Working directory is not clean. Please commit or stash your changes.${NC}"
36+
exit 1
37+
fi
38+
39+
# Get current version from package.json
40+
CURRENT_VERSION=$(node -p "require('./package.json').version")
41+
echo -e "${YELLOW}Current version: ${CURRENT_VERSION}${NC}"
42+
43+
# Parse version parts
44+
IFS='.' read -r -a VERSION_PARTS <<< "$CURRENT_VERSION"
45+
MAJOR="${VERSION_PARTS[0]}"
46+
MINOR="${VERSION_PARTS[1]}"
47+
PATCH="${VERSION_PARTS[2]}"
48+
49+
# Bump version based on type
50+
case "$BUMP_TYPE" in
51+
major)
52+
MAJOR=$((MAJOR + 1))
53+
MINOR=0
54+
PATCH=0
55+
;;
56+
minor)
57+
MINOR=$((MINOR + 1))
58+
PATCH=0
59+
;;
60+
patch)
61+
PATCH=$((PATCH + 1))
62+
;;
63+
esac
64+
65+
NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}"
66+
echo -e "${GREEN}New version: ${NEW_VERSION}${NC}"
67+
68+
# Update package.json
69+
echo -e "${YELLOW}Updating package.json...${NC}"
70+
node -e "
71+
const fs = require('fs');
72+
const pkg = require('./package.json');
73+
pkg.version = '${NEW_VERSION}';
74+
fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n');
75+
"
76+
77+
# Commit the version change
78+
echo -e "${YELLOW}Creating commit...${NC}"
79+
git add package.json
80+
git commit -m "Bump version to ${NEW_VERSION}"
81+
82+
# Create git tag
83+
echo -e "${YELLOW}Creating tag v${NEW_VERSION}...${NC}"
84+
git tag "v${NEW_VERSION}"
85+
86+
# Push commit and tag
87+
echo -e "${YELLOW}Pushing to remote...${NC}"
88+
git push origin $(git branch --show-current)
89+
git push origin "v${NEW_VERSION}"
90+
91+
echo -e "${GREEN}✓ Release ${NEW_VERSION} completed successfully!${NC}"
92+
echo -e "${GREEN}✓ Commit and tag pushed to remote${NC}"

0 commit comments

Comments
 (0)