-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathrelease.sh
More file actions
executable file
·208 lines (171 loc) · 5.29 KB
/
release.sh
File metadata and controls
executable file
·208 lines (171 loc) · 5.29 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#!/bin/bash
set -e
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
show_usage() {
echo "Usage: ./release.sh <component> <version>"
echo ""
echo "Components:"
echo " cli - CLI + Python package (tag: v*)"
echo " node - Node.js client (tag: node-*)"
echo ""
echo "Version:"
echo " X.Y.Z - Explicit version (e.g., 1.0.0)"
echo " patch - Bump patch version (0.1.0 -> 0.1.1)"
echo " minor - Bump minor version (0.1.0 -> 0.2.0)"
echo " major - Bump major version (0.1.0 -> 1.0.0)"
echo ""
echo "Examples:"
echo " ./release.sh cli 0.1.0"
echo " ./release.sh cli patch"
echo " ./release.sh node 1.0.0"
echo " ./release.sh node patch"
echo ""
echo "Note: 'cli' releases both the CLI binaries and Python package together"
}
get_cli_version() {
grep '^version = ' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/'
}
get_py_version() {
grep '^version = ' sdk/python/pyproject.toml | head -1 | sed 's/version = "\(.*\)"/\1/'
}
get_node_version() {
grep '"version"' sdk/node/package.json | head -1 | sed 's/.*"version": "\(.*\)".*/\1/'
}
bump_version() {
local current=$1
local bump_type=$2
IFS='.' read -r MAJOR MINOR PATCH <<< "$current"
case $bump_type in
patch)
PATCH=$((PATCH + 1))
;;
minor)
MINOR=$((MINOR + 1))
PATCH=0
;;
major)
MAJOR=$((MAJOR + 1))
MINOR=0
PATCH=0
;;
esac
echo "${MAJOR}.${MINOR}.${PATCH}"
}
validate_version() {
local version=$1
if ! echo "$version" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$'; then
echo -e "${RED}Error: Invalid version format '$version'${NC}"
echo "Version must be in semantic format: X.Y.Z (e.g., 1.0.0)"
exit 1
fi
}
check_clean_git() {
if ! git diff --quiet || ! git diff --staged --quiet; then
echo -e "${RED}Error: You have uncommitted changes. Please commit or stash them first.${NC}"
git status --short
exit 1
fi
}
check_tag_exists() {
local tag=$1
if git rev-parse "$tag" >/dev/null 2>&1; then
echo -e "${RED}Error: Tag $tag already exists${NC}"
exit 1
fi
}
release_cli() {
local version=$1
local current_cli=$(get_cli_version)
local current_py=$(get_py_version)
echo -e "${BLUE}CLI + Python Release${NC}"
echo "Current CLI version: $current_cli"
echo "Current Python version: $current_py"
# Handle version bump (based on CLI version)
if [ "$version" = "patch" ] || [ "$version" = "minor" ] || [ "$version" = "major" ]; then
version=$(bump_version "$current_cli" "$version")
fi
validate_version "$version"
local tag="v$version"
check_clean_git
check_tag_exists "$tag"
echo -e "${YELLOW}Preparing release $tag (CLI + Python)${NC}"
# Update version in Cargo.toml
echo "Updating Cargo.toml version to $version..."
sed -i.bak "s/^version = \".*\"/version = \"$version\"/" Cargo.toml
rm -f Cargo.toml.bak
# Sync Cargo.lock so the committed lockfile matches Cargo.toml.
# --offline avoids network and skips build.rs entirely.
echo "Syncing Cargo.lock to $version..."
cargo update -p pg0 --offline
# Update version in pyproject.toml
echo "Updating pyproject.toml version to $version..."
sed -i.bak "s/^version = \".*\"/version = \"$version\"/" sdk/python/pyproject.toml
rm -f sdk/python/pyproject.toml.bak
# Commit and tag
git add Cargo.toml Cargo.lock sdk/python/pyproject.toml
git commit -m "chore: bump CLI version to $version"
git tag -a "$tag" -m "Release $version"
# Push
git push
git push origin "$tag"
echo -e "${GREEN}Release $tag pushed!${NC}"
echo ""
echo "This will release:"
echo " - CLI binaries to GitHub Releases"
echo " - Python package to PyPI (pg0-embedded)"
}
release_node() {
local version=$1
local current=$(get_node_version)
echo -e "${BLUE}Node.js Release${NC}"
echo "Current version: $current"
# Handle version bump
if [ "$version" = "patch" ] || [ "$version" = "minor" ] || [ "$version" = "major" ]; then
version=$(bump_version "$current" "$version")
fi
validate_version "$version"
local tag="node-$version"
check_clean_git
check_tag_exists "$tag"
echo -e "${YELLOW}Preparing Node.js release $tag${NC}"
# Update version in package.json
echo "Updating package.json version to $version..."
cd sdk/node
npm version "$version" --no-git-tag-version
cd ../..
# Commit and tag
git add sdk/node/package.json
git commit -m "chore: bump Node.js client version to $version"
git tag -a "$tag" -m "Node.js Client Release $version"
# Push
git push
git push origin "$tag"
echo -e "${GREEN}Node.js release $tag pushed!${NC}"
echo "Package will be published to npm as: @vectorize-io/pg0"
}
# Main
if [ -z "$1" ] || [ -z "$2" ]; then
show_usage
exit 1
fi
COMPONENT=$1
VERSION=$2
case $COMPONENT in
cli)
release_cli "$VERSION"
;;
node|nodejs)
release_node "$VERSION"
;;
*)
echo -e "${RED}Error: Unknown component '$COMPONENT'${NC}"
echo ""
show_usage
exit 1
;;
esac