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