-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrelease.sh
More file actions
executable file
·428 lines (364 loc) · 12.1 KB
/
release.sh
File metadata and controls
executable file
·428 lines (364 loc) · 12.1 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
427
428
#!/bin/bash
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Helper functions
info() {
echo -e "${BLUE}ℹ️ $1${NC}"
}
success() {
echo -e "${GREEN}✅ $1${NC}"
}
warning() {
echo -e "${YELLOW}⚠️ $1${NC}"
}
error() {
echo -e "${RED}❌ $1${NC}"
exit 1
}
# Check if git repo is clean (only tracked files)
check_git_status() {
# Check for modified, staged, or deleted tracked files
if [ -n "$(git status --porcelain | grep -E '^[MADR]')" ]; then
error "Git working directory has uncommitted changes to tracked files. Please commit or stash your changes."
fi
# Show untracked files as info (but don't block)
untracked=$(git status --porcelain | grep '^??' || true)
if [ -n "$untracked" ]; then
warning "Untracked files present (will be ignored):"
echo "$untracked" | sed 's/^?? / - /'
echo ""
fi
}
# Check if we're on main branch
check_main_branch() {
current_branch=$(git branch --show-current)
if [ "$current_branch" != "main" ]; then
error "You must be on the main branch to create a release. Current branch: $current_branch"
fi
}
# Check code formatting
check_formatting() {
local component=$1
info "Checking code formatting for $component..."
cd "$component"
if [[ "$component" =~ ^(backend|sync|collect)$ ]]; then
# Go formatting check
local unformatted=$(gofmt -s -l . | wc -l)
if [ "$unformatted" -gt 0 ]; then
error "Code is not formatted properly in $component. Run 'make fmt' to fix it."
fi
elif [ "$component" = "frontend" ]; then
# Frontend formatting check
if ! npm run format; then
error "Code is not formatted properly in $component. Run 'npm run format-fix' to fix it."
fi
elif [[ "$component" =~ ^(proxy)$ ]]; then
success "Skipping code formatting for $component (no formatting configured)"
fi
cd ..
success "Code formatting OK for $component"
}
# Run linting
run_linting() {
local component=$1
info "Running linting for $component..."
cd "$component"
if [ "$component" = "backend" ] || [ "$component" = "collect" ]; then
# Check if golangci-lint is available
if command -v golangci-lint >/dev/null 2>&1; then
if ! golangci-lint run; then
error "Linting failed for $component"
fi
else
warning "golangci-lint not found, skipping linting for $component"
warning "Install with: https://golangci-lint.run/usage/install/"
fi
elif [ "$component" = "frontend" ]; then
# Run frontend linting and type checking
if ! npm run lint; then
error "Linting failed for $component"
fi
if ! npm run type-check; then
error "Type checking failed for $component"
fi
elif [[ "$component" =~ ^(proxy)$ ]]; then
success "Skipping linting for $component (no linting configured)"
else
if ! make lint; then
error "Linting failed for $component"
fi
fi
cd ..
success "Linting passed for $component"
}
# Run tests
run_tests() {
local component=$1
info "Running tests for $component..."
cd "$component"
if [ "$component" = "backend" ] || [ "$component" = "collect" ]; then
if ! go test ./...; then
error "Tests failed for $component"
fi
elif [ "$component" = "frontend" ]; then
# Run frontend tests
if ! npm run test -- --run; then
error "Tests failed for $component"
fi
elif [[ "$component" =~ ^(proxy)$ ]]; then
success "Skipping tests for $component (no test suite)"
else
if ! make test; then
error "Tests failed for $component"
fi
fi
cd ..
success "Tests passed for $component"
}
# Get current version from version.json
get_current_version() {
if [ ! -f "version.json" ]; then
error "version.json not found"
fi
current_version=$(jq -r '.version' version.json)
if [ "$current_version" = "null" ]; then
error "Could not read version from version.json"
fi
echo "$current_version"
}
# Bump version based on type (patch, minor, major)
bump_version() {
local current=$1
local type=$2
IFS='.' read -ra ADDR <<< "$current"
major=${ADDR[0]}
minor=${ADDR[1]}
patch=${ADDR[2]}
case $type in
"patch")
patch=$((patch + 1))
;;
"minor")
minor=$((minor + 1))
patch=0
;;
"major")
major=$((major + 1))
minor=0
patch=0
;;
*)
error "Invalid bump type: $type. Use patch, minor, or major"
;;
esac
echo "$major.$minor.$patch"
}
# Update version.json with new version
update_version_file() {
local new_version=$1
jq --arg version "$new_version" '
.version = $version |
.components.backend = $version |
.components.sync = $version |
.components.collect = $version |
.components.frontend = $version |
.components.proxy = $version |
.components."services/mimir" = $version
' version.json > version.json.tmp && mv version.json.tmp version.json
}
# Update individual VERSION files for Go components
update_component_versions() {
local new_version=$1
info "Updating component VERSION files..."
# Update backend VERSION file
if [ -f "backend/pkg/version/VERSION" ]; then
echo "$new_version" > "backend/pkg/version/VERSION"
success "Updated backend/pkg/version/VERSION"
else
warning "backend/pkg/version/VERSION not found"
fi
# Update collect VERSION file
if [ -f "collect/pkg/version/VERSION" ]; then
echo "$new_version" > "collect/pkg/version/VERSION"
success "Updated collect/pkg/version/VERSION"
else
warning "collect/pkg/version/VERSION not found"
fi
# Update sync VERSION file
if [ -f "sync/pkg/version/VERSION" ]; then
echo "$new_version" > "sync/pkg/version/VERSION"
success "Updated sync/pkg/version/VERSION"
else
warning "sync/pkg/version/VERSION not found"
fi
# Update services/mimir VERSION file
if [ -f "services/mimir/VERSION" ]; then
echo "$new_version" > "services/mimir/VERSION"
success "Updated services/mimir/VERSION"
else
warning "services/mimir/VERSION not found"
fi
}
# Update frontend package.json version
update_frontend_version() {
local new_version=$1
info "Updating frontend package.json version..."
if [ -f "frontend/package.json" ]; then
# Use jq to update the version in package.json
jq --arg version "$new_version" '.version = $version' frontend/package.json > frontend/package.json.tmp && mv frontend/package.json.tmp frontend/package.json
success "Updated frontend/package.json to version $new_version"
else
warning "frontend/package.json not found"
fi
}
# Update OpenAPI specification version
update_openapi_version() {
local new_version=$1
info "Updating OpenAPI specification version..."
if [ -f "backend/openapi.yaml" ]; then
# Use sed to update only the version line in the info block (after title line)
sed -i.bak '/^info:/,/^[a-zA-Z]/ s/^ version: .*/ version: '"$new_version"'/' backend/openapi.yaml
rm -f backend/openapi.yaml.bak
success "Updated backend/openapi.yaml version to $new_version"
else
warning "backend/openapi.yaml not found"
fi
}
# Update documentation version
update_docs_version() {
local new_version=$1
info "Updating documentation version..."
# English docs
if [ -f "docs/docs/intro.md" ]; then
sed -i.bak 's/Current version: \*\*[0-9.]*\*\*/Current version: **'"$new_version"'**/' docs/docs/intro.md
rm -f docs/docs/intro.md.bak
success "Updated docs/docs/intro.md version to $new_version"
else
warning "docs/docs/intro.md not found"
fi
# Italian docs
if [ -f "docs/i18n/it/docusaurus-plugin-content-docs/current/intro.md" ]; then
sed -i.bak 's/Versione corrente: \*\*[0-9.]*\*\*/Versione corrente: **'"$new_version"'**/' docs/i18n/it/docusaurus-plugin-content-docs/current/intro.md
rm -f docs/i18n/it/docusaurus-plugin-content-docs/current/intro.md.bak
success "Updated docs/i18n/it/docusaurus-plugin-content-docs/current/intro.md version to $new_version"
else
warning "docs/i18n/it/docusaurus-plugin-content-docs/current/intro.md not found"
fi
}
# Show usage
usage() {
echo "Usage: $0 [patch|minor|major]"
echo ""
echo "Bump version, commit, tag and push for release"
echo ""
echo "Options:"
echo " patch Bump patch version (0.0.1 -> 0.0.2)"
echo " minor Bump minor version (0.0.1 -> 0.1.0)"
echo " major Bump major version (0.0.1 -> 1.0.0)"
echo ""
echo "Examples:"
echo " $0 patch # For bug fixes"
echo " $0 minor # For new features"
echo " $0 major # For breaking changes"
exit 1
}
# Main function
main() {
# Check for jq dependency
if ! command -v jq &> /dev/null; then
error "jq is required but not installed. Install it with: brew install jq"
fi
# Parse arguments
if [ $# -eq 0 ]; then
usage
fi
bump_type=$1
if [[ ! "$bump_type" =~ ^(patch|minor|major)$ ]]; then
usage
fi
info "Starting release process..."
# Pre-flight checks
check_git_status
check_main_branch
# Quality checks
info "Running quality checks..."
check_formatting "backend"
check_formatting "sync"
check_formatting "collect"
check_formatting "frontend"
check_formatting "proxy"
run_linting "backend"
run_linting "sync"
run_linting "collect"
run_linting "frontend"
run_linting "proxy"
run_tests "backend"
run_tests "sync"
run_tests "collect"
run_tests "frontend"
run_tests "proxy"
success "All quality checks passed!"
# Get current version and calculate new version
current_version=$(get_current_version)
new_version=$(bump_version "$current_version" "$bump_type")
info "Current version: $current_version"
info "New version: $new_version"
# Confirm with user
echo ""
read -p "Do you want to create release v$new_version? [y/N] " -n 1 -r
echo ""
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
warning "Release cancelled"
exit 0
fi
# Update version file
info "Updating version.json..."
update_version_file "$new_version"
# Update component VERSION files
update_component_versions "$new_version"
# Update frontend package.json version
update_frontend_version "$new_version"
# Update OpenAPI specification version
update_openapi_version "$new_version"
# Update documentation version
update_docs_version "$new_version"
# Commit changes
info "Creating commit..."
release_files=(
version.json
backend/pkg/version/VERSION
collect/pkg/version/VERSION
sync/pkg/version/VERSION
services/mimir/VERSION
frontend/package.json
frontend/package-lock.json
backend/openapi.yaml
docs/docs/intro.md
docs/i18n/it/docusaurus-plugin-content-docs/current/intro.md
)
for f in "${release_files[@]}"; do
[ -f "$f" ] && git add "$f"
done
git commit -m "release: bump version to v$new_version"
# Create tag
info "Creating tag v$new_version..."
git tag -a "v$new_version" -m "Release v$new_version"
# Push to remote
info "Pushing to remote..."
git push origin main
git push origin "v$new_version"
success "Release v$new_version created successfully!"
success "GitHub Actions will now build and publish the release."
# Show useful links
echo ""
info "Useful links:"
info "- Actions: https://github.com/$(git config remote.origin.url | sed 's/.*://g' | sed 's/.git$//g')/actions"
info "- Releases: https://github.com/$(git config remote.origin.url | sed 's/.*://g' | sed 's/.git$//g')/releases"
}
# Run main function
main "$@"