Skip to content

Commit aff456d

Browse files
committed
Add bump.sh script for version tagging and release
1 parent fd73c0b commit aff456d

File tree

1 file changed

+194
-0
lines changed

1 file changed

+194
-0
lines changed

scripts/bump.sh

Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
#!/bin/bash
2+
#
3+
# Version Bump and Release Script for T-Ruby VS Code Extension
4+
#
5+
# Usage:
6+
# ./scripts/bump.sh <type>
7+
#
8+
# Arguments:
9+
# patch Bump patch version (0.1.0 -> 0.1.1)
10+
# minor Bump minor version (0.1.0 -> 0.2.0)
11+
# major Bump major version (0.1.0 -> 1.0.0)
12+
#
13+
# Options:
14+
# --dry-run Show what would happen without making changes
15+
# --help Show this help message
16+
#
17+
# Examples:
18+
# ./scripts/bump.sh patch
19+
# ./scripts/bump.sh minor --dry-run
20+
21+
set -e
22+
23+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
24+
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
25+
26+
# Colors for output
27+
RED='\033[0;31m'
28+
GREEN='\033[0;32m'
29+
YELLOW='\033[1;33m'
30+
BLUE='\033[0;34m'
31+
NC='\033[0m' # No Color
32+
33+
DRY_RUN=false
34+
BUMP_TYPE=""
35+
36+
print_help() {
37+
echo "Version Bump and Release Script for T-Ruby VS Code Extension"
38+
echo ""
39+
echo "Usage: $0 <type> [options]"
40+
echo ""
41+
echo "Arguments:"
42+
echo " patch Bump patch version (0.1.0 -> 0.1.1)"
43+
echo " minor Bump minor version (0.1.0 -> 0.2.0)"
44+
echo " major Bump major version (0.1.0 -> 1.0.0)"
45+
echo ""
46+
echo "Options:"
47+
echo " --dry-run Show what would happen without making changes"
48+
echo " --help Show this help message"
49+
echo ""
50+
echo "This script will:"
51+
echo " 1. Bump the version in package.json"
52+
echo " 2. Commit the version change"
53+
echo " 3. Create a git tag (v0.x.x)"
54+
echo " 4. Push the commit and tag to trigger GitHub Actions release"
55+
}
56+
57+
log_info() {
58+
echo -e "${BLUE}[INFO]${NC} $1"
59+
}
60+
61+
log_success() {
62+
echo -e "${GREEN}[SUCCESS]${NC} $1"
63+
}
64+
65+
log_warn() {
66+
echo -e "${YELLOW}[WARN]${NC} $1"
67+
}
68+
69+
log_error() {
70+
echo -e "${RED}[ERROR]${NC} $1"
71+
}
72+
73+
get_version() {
74+
cd "$PROJECT_ROOT"
75+
node -p "require('./package.json').version"
76+
}
77+
78+
bump_version() {
79+
local bump_type=$1
80+
cd "$PROJECT_ROOT"
81+
82+
OLD_VERSION=$(get_version)
83+
84+
# Parse version components
85+
IFS='.' read -r MAJOR MINOR PATCH <<< "$OLD_VERSION"
86+
87+
case $bump_type in
88+
patch)
89+
PATCH=$((PATCH + 1))
90+
;;
91+
minor)
92+
MINOR=$((MINOR + 1))
93+
PATCH=0
94+
;;
95+
major)
96+
MAJOR=$((MAJOR + 1))
97+
MINOR=0
98+
PATCH=0
99+
;;
100+
esac
101+
102+
NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}"
103+
echo "$NEW_VERSION"
104+
}
105+
106+
# Parse arguments
107+
while [[ $# -gt 0 ]]; do
108+
case $1 in
109+
patch|minor|major)
110+
BUMP_TYPE="$1"
111+
shift
112+
;;
113+
--dry-run)
114+
DRY_RUN=true
115+
shift
116+
;;
117+
--help|-h)
118+
print_help
119+
exit 0
120+
;;
121+
*)
122+
log_error "Unknown option: $1"
123+
print_help
124+
exit 1
125+
;;
126+
esac
127+
done
128+
129+
if [ -z "$BUMP_TYPE" ]; then
130+
log_error "Missing bump type (patch|minor|major)"
131+
print_help
132+
exit 1
133+
fi
134+
135+
cd "$PROJECT_ROOT"
136+
137+
# Check for uncommitted changes
138+
if [ -n "$(git status --porcelain)" ]; then
139+
log_error "Working directory is not clean. Please commit or stash changes first."
140+
exit 1
141+
fi
142+
143+
# Calculate versions
144+
OLD_VERSION=$(get_version)
145+
NEW_VERSION=$(bump_version "$BUMP_TYPE")
146+
147+
log_info "Version bump: $OLD_VERSION -> $NEW_VERSION"
148+
149+
if [ "$DRY_RUN" = true ]; then
150+
log_warn "Dry run mode - showing what would happen:"
151+
echo ""
152+
echo " 1. Update package.json version to $NEW_VERSION"
153+
echo " 2. git commit -m \"Bump version to $NEW_VERSION\""
154+
echo " 3. git tag v$NEW_VERSION"
155+
echo " 4. git push && git push --tags"
156+
echo ""
157+
echo "This would trigger GitHub Actions to publish:"
158+
echo " - VS Code Marketplace"
159+
echo " - Open VSX (Cursor)"
160+
exit 0
161+
fi
162+
163+
# Update package.json
164+
log_info "Updating package.json..."
165+
node -e "
166+
const fs = require('fs');
167+
const pkg = require('./package.json');
168+
pkg.version = '$NEW_VERSION';
169+
fs.writeFileSync('./package.json', JSON.stringify(pkg, null, 2) + '\n');
170+
"
171+
172+
# Commit
173+
log_info "Committing version change..."
174+
git add package.json
175+
git commit -m "Bump version to $NEW_VERSION"
176+
177+
# Tag
178+
log_info "Creating tag v$NEW_VERSION..."
179+
git tag "v$NEW_VERSION"
180+
181+
# Push
182+
log_info "Pushing to remote..."
183+
git push && git push --tags
184+
185+
echo ""
186+
log_success "Released v$NEW_VERSION!"
187+
echo ""
188+
echo "GitHub Actions will now:"
189+
echo " - Build and package the extension"
190+
echo " - Publish to VS Code Marketplace"
191+
echo " - Publish to Open VSX (Cursor)"
192+
echo " - Create a GitHub Release"
193+
echo ""
194+
echo "Monitor progress: https://github.com/type-ruby/t-ruby-vscode/actions"

0 commit comments

Comments
 (0)