-
Notifications
You must be signed in to change notification settings - Fork 73
Expand file tree
/
Copy pathrelease.sh
More file actions
executable file
·426 lines (351 loc) · 11.3 KB
/
release.sh
File metadata and controls
executable file
·426 lines (351 loc) · 11.3 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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
#!/bin/bash
# release.sh - Version bumping and tagging script
set -e
# Status tracking (compatible with older bash)
python_status=false
javascript_status=false
rust_status=false
go_status=false
usage() {
echo "Usage: $0 <version>"
echo "Version: semantic version (e.g., 1.2.3)"
echo ""
echo "This will:"
echo " 1. Check for git-cliff installation"
echo " 2. Update version in all SDK package files"
echo " 3. Generate changelog with git-cliff"
echo " 4. Commit the changes"
echo " 5. Create a git tag v<version>"
echo " 6. Push everything to current branch"
echo ""
echo "Example:"
echo "bash ./release.sh 1.2.3"
}
check_git_cliff() {
echo "🔍 Checking for git-cliff..."
if ! command -v git-cliff &> /dev/null; then
echo ""
echo "❌ Error: git-cliff is not installed!"
echo ""
echo "📥 Installation options:"
echo ""
echo "1. Using Cargo (Rust):"
echo " cargo install git-cliff"
echo ""
echo "2. Using Homebrew (macOS):"
echo " brew install git-cliff"
echo ""
echo "3. Using package managers:"
echo " # Arch Linux"
echo " pacman -S git-cliff"
echo ""
echo " # Fedora"
echo " dnf install git-cliff"
echo ""
echo "4. Download binary from GitHub:"
echo " https://github.com/orhun/git-cliff/releases"
echo ""
echo "5. Quick install script:"
echo " curl -L https://github.com/orhun/git-cliff/releases/latest/download/git-cliff-\$(uname -m)-unknown-linux-gnu.tar.gz | tar -xz"
echo " sudo mv git-cliff-*/git-cliff /usr/local/bin/"
echo ""
echo "Please install git-cliff and run this script again."
exit 1
fi
local cliff_version
cliff_version=$(git-cliff --version 2>/dev/null | head -1)
echo "✅ Found: $cliff_version"
# Check if cliff.toml exists
if [[ ! -f "cliff.toml" ]]; then
echo ""
echo "⚠️ Warning: cliff.toml configuration file not found!"
echo " git-cliff will use default configuration."
echo " Consider creating cliff.toml for better changelog formatting."
echo ""
echo "📝 To create a basic cliff.toml:"
echo " git-cliff --init"
echo ""
read -p "Continue without cliff.toml? [y/N]: " -r
echo ""
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "Release cancelled. Please create cliff.toml first."
exit 0
fi
fi
}
validate_version() {
local version=$1
if [[ ! $version =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Error: Version must be in format X.Y.Z (e.g., 1.2.3)"
return 1
fi
return 0
}
verify_version_update() {
local file=$1
local version=$2
local pattern=$3
if [[ -f "$file" ]] && grep -q "$pattern" "$file" 2>/dev/null; then
return 0
fi
return 1
}
update_python_version() {
local version=$1
local pyproject_file="pyproject.toml"
local version_file="runagent/__version__.py"
local init_file="runagent/__init__.py"
local success=false
# Update pyproject.toml
if [[ -f "$pyproject_file" ]]; then
if [[ "$OSTYPE" == "darwin"* ]]; then
sed -i '' "s/version = \".*\"/version = \"$version\"/" "$pyproject_file"
else
sed -i "s/version = \".*\"/version = \"$version\"/" "$pyproject_file"
fi
if verify_version_update "$pyproject_file" "$version" "version = \"$version\""; then
success=true
fi
fi
# Update __version__.py
if [[ -f "$version_file" ]]; then
if [[ "$OSTYPE" == "darwin"* ]]; then
sed -i '' "s/__version__ = \".*\"/__version__ = \"$version\"/" "$version_file"
else
sed -i "s/__version__ = \".*\"/__version__ = \"$version\"/" "$version_file"
fi
else
mkdir -p "$(dirname "$version_file")"
echo "__version__ = \"$version\"" > "$version_file"
fi
# Also update __init__.py version
if [[ -f "$init_file" ]]; then
if [[ "$OSTYPE" == "darwin"* ]]; then
sed -i '' "s/__version__ = \".*\"/__version__ = \"$version\"/" "$init_file"
else
sed -i "s/__version__ = \".*\"/__version__ = \"$version\"/" "$init_file"
fi
fi
if verify_version_update "$version_file" "$version" "__version__ = \"$version\""; then
success=true
fi
python_status=$success
}
update_javascript_version() {
local version=$1
local file="runagent-ts/package.json"
if [[ ! -f "$file" ]]; then
javascript_status=false
return
fi
if command -v npm &> /dev/null; then
(
cd runagent-ts
npm version "$version" --no-git-tag-version --allow-same-version &>/dev/null
)
else
if [[ "$OSTYPE" == "darwin"* ]]; then
sed -i '' "s/\"version\": \".*\"/\"version\": \"$version\"/" "$file"
else
sed -i "s/\"version\": \".*\"/\"version\": \"$version\"/" "$file"
fi
fi
if verify_version_update "$file" "$version" "\"version\": \"$version\""; then
javascript_status=true
else
javascript_status=false
fi
}
update_rust_version() {
local version=$1
local file="runagent-rust/runagent/Cargo.toml"
if [[ ! -f "$file" ]]; then
rust_status=false
return
fi
if [[ "$OSTYPE" == "darwin"* ]]; then
sed -i '' "s/^version = \".*\"/version = \"$version\"/" "$file"
else
sed -i "s/^version = \".*\"/version = \"$version\"/" "$file"
fi
if verify_version_update "$file" "$version" "version = \"$version\""; then
rust_status=true
else
rust_status=false
fi
}
update_go_version() {
local version=$1
local version_file="runagent-go/version.go"
local go_mod_file="runagent-go/go.mod"
if [[ ! -f "$version_file" ]]; then
cat > "$version_file" << EOF
package runagent
// Version represents the current version of the RunAgent Go SDK
const Version = "$version"
EOF
else
if [[ "$OSTYPE" == "darwin"* ]]; then
sed -i '' "s/const Version = \".*\"/const Version = \"$version\"/" "$version_file"
else
sed -i "s/const Version = \".*\"/const Version = \"$version\"/" "$version_file"
fi
fi
if [[ ! -f "$go_mod_file" ]]; then
cat > "$go_mod_file" << EOF
module github.com/runagent-dev/runagent-go
go 1.20
// Dependencies will be added here
EOF
fi
if verify_version_update "$version_file" "$version" "const Version = \"$version\""; then
go_status=true
else
go_status=false
fi
}
generate_changelog() {
git-cliff --output CHANGELOG.md --latest
echo "✅ Changelog generated successfully"
}
show_update_summary() {
echo ""
echo "📋 Update Summary:"
echo "-------------------"
if [[ "$python_status" == "true" ]]; then
echo "✅ python"
else
echo "❌ python"
fi
if [[ "$javascript_status" == "true" ]]; then
echo "✅ javascript"
else
echo "❌ javascript"
fi
if [[ "$rust_status" == "true" ]]; then
echo "✅ rust"
else
echo "❌ rust"
fi
if [[ "$go_status" == "true" ]]; then
echo "✅ go"
else
echo "❌ go"
fi
echo ""
}
check_prerequisites() {
local current_branch
current_branch=$(git branch --show-current 2>/dev/null || git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "unknown")
if [[ "$current_branch" == "unknown" ]]; then
echo "❌ Error: Could not determine current branch"
exit 1
fi
if ! git status &>/dev/null; then
echo "❌ Error: Not in a git repository or git is not working"
exit 1
fi
}
handle_existing_tag() {
local version=$1
local tag_name="v$version"
if git tag -l | grep -q "^$tag_name$"; then
echo ""
echo "⚠️ Tag $tag_name already exists"
echo ""
echo "Do you want to move this tag to the current commit?"
echo "This will update the existing tag (potentially dangerous if already published)"
echo ""
read -p "Move tag to current commit? [y/N]: " -r
echo ""
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "Release cancelled. Tag $tag_name remains unchanged."
exit 0
fi
echo "Moving tag $tag_name to current commit..."
git tag -f -a "$tag_name" -m "Release $tag_name (moved)
RunAgent Universal Release $tag_name
All SDKs updated to version $version"
return 0
fi
return 1
}
# Main script
if [[ $# -ne 1 ]]; then
usage
exit 1
fi
VERSION=$1
if ! validate_version "$VERSION"; then
exit 1
fi
echo "🚀 RunAgent Version Bump to v$VERSION"
# FIRST: Check git-cliff before making any changes
check_git_cliff
check_prerequisites
# Update all package files
update_python_version "$VERSION"
update_javascript_version "$VERSION"
update_rust_version "$VERSION"
update_go_version "$VERSION"
show_update_summary
# Check if any updates succeeded
any_success=false
if [[ "$python_status" == "true" ]] || [[ "$javascript_status" == "true" ]] || [[ "$rust_status" == "true" ]] || [[ "$go_status" == "true" ]]; then
any_success=true
fi
if [[ "$any_success" == "false" ]]; then
echo "❌ No version updates succeeded. Aborting release."
exit 1
fi
# Show git changes
if ! git diff --name-only --quiet 2>/dev/null; then
echo "Changes detected:"
git diff --name-only 2>/dev/null | sed 's/^/ /'
else
echo "⚠️ No git changes detected"
fi
echo ""
read -p "Continue with commit and tag? [y/N]: " -r
echo ""
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "Release cancelled."
git checkout -- . 2>/dev/null || true
exit 0
fi
# Handle existing tag FIRST (before generating changelog)
if handle_existing_tag "$VERSION"; then
echo "✅ Tag v$VERSION updated successfully!"
exit 0
fi
# Stage and commit version changes FIRST (without changelog)
git add .
if git diff --staged --quiet; then
echo "⚠️ No changes to commit."
exit 1
fi
# Commit version changes first
git commit -m "chore: bump version to v$VERSION
- Updated all SDK versions to $VERSION" -q
# Create tag BEFORE generating changelog (so git-cliff knows about it)
git tag -a "v$VERSION" -m "Release v$VERSION
RunAgent Universal Release v$VERSION
All SDKs updated to version $VERSION"
# NOW generate changelog (tag exists, so git-cliff can reference it properly)
generate_changelog
# Stage and commit changelog separately
git add CHANGELOG.md
if ! git diff --staged --quiet; then
git commit -m "docs: update changelog for v$VERSION" -q
fi
CURRENT_BRANCH=$(git branch --show-current 2>/dev/null || git rev-parse --abbrev-ref HEAD 2>/dev/null)
# Push commit first, then tag (to prevent orphaned tags)
echo "📤 Pushing commit to origin/$CURRENT_BRANCH..."
git push origin "$CURRENT_BRANCH"
echo "📤 Pushing tag v$VERSION..."
git push origin "v$VERSION"
echo "✅ Release v$VERSION completed successfully!"
echo ""
echo "📋 Next steps:"
echo " 1. Monitor workflows at: https://github.com/runagent-dev/runagent/actions"
echo " 2. Verify release at: https://github.com/runagent-dev/runagent/releases"