-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelease.sh
More file actions
executable file
·1823 lines (1552 loc) · 58.3 KB
/
release.sh
File metadata and controls
executable file
·1823 lines (1552 loc) · 58.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
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
# Release management script for Python Script Runner
# Automates versioning, tagging, and release preparation
# Integrates with version.sh for semantic versioning and GitHub Actions CI/CD
set -euo pipefail
# Configuration
DEBUG_MODE="${DEBUG:-false}"
INTERACTIVE_MODE="${INTERACTIVE:-true}"
SKIP_TESTS="${SKIP_TESTS:-false}"
PARALLEL_BUILDS="${PARALLEL_BUILDS:-true}"
LOG_FILE="${LOG_FILE:-/tmp/release-$(date +%Y%m%d-%H%M%S).log}"
# Global error tracking
ERROR_COUNT=0
WARNING_COUNT=0
SUCCESS_COUNT=0
# Initialize log file
echo "Release script started at $(date)" > "$LOG_FILE"
echo "Command: $0 $*" >> "$LOG_FILE"
echo "" >> "$LOG_FILE"
# Error handling with better diagnostics and rollback
trap 'handle_error $? $LINENO $BASH_COMMAND' ERR
trap 'handle_interrupt' INT TERM
STATE_FILE="/tmp/release-state-$$.json"
ROLLBACK_ACTIONS=()
handle_error() {
local exit_code=$1
local line_number=$2
local command="${3:-unknown}"
ERROR_COUNT=$((ERROR_COUNT + 1))
log_error "Script failed at line $line_number with exit code $exit_code"
log_error "Failed command: $command"
print_error "Script failed at line $line_number with exit code $exit_code"
print_error "Failed command: $command"
print_error "Check log file: $LOG_FILE"
# Offer rollback if in interactive mode
if [ "$INTERACTIVE_MODE" = "true" ] && [ ${#ROLLBACK_ACTIONS[@]} -gt 0 ]; then
echo ""
print_warning "Rollback available. Do you want to rollback changes? (y/n)"
read -r response
if [[ "$response" =~ ^[Yy]$ ]]; then
perform_rollback
fi
fi
print_error "Use 'bash release.sh help' for usage information"
cleanup_on_exit
exit "$exit_code"
}
handle_interrupt() {
echo ""
print_warning "\nInterrupted by user"
log_warning "Script interrupted by user"
if [ "$INTERACTIVE_MODE" = "true" ]; then
print_warning "Do you want to rollback changes? (y/n)"
read -r response
if [[ "$response" =~ ^[Yy]$ ]]; then
perform_rollback
fi
fi
cleanup_on_exit
exit 130
}
perform_rollback() {
print_header "Rolling Back Changes"
log_info "Starting rollback"
local rollback_count=0
# Execute rollback actions in reverse order
for ((i=${#ROLLBACK_ACTIONS[@]}-1; i>=0; i--)); do
local action="${ROLLBACK_ACTIONS[$i]}"
print_warning "Rollback: $action"
log_info "Executing rollback: $action"
if eval "$action" >> "$LOG_FILE" 2>&1; then
((rollback_count++))
else
print_error "Rollback action failed: $action"
log_error "Rollback action failed: $action"
fi
done
print_success "Rolled back $rollback_count action(s)"
log_info "Completed rollback: $rollback_count actions"
}
register_rollback() {
local action="$1"
ROLLBACK_ACTIONS+=("$action")
log_debug "Registered rollback: $action"
}
cleanup_on_exit() {
# Clean up temporary files
[ -f "$STATE_FILE" ] && rm -f "$STATE_FILE"
log_info "Cleanup completed"
}
# Increment counters for progress tracking
increment_success() {
SUCCESS_COUNT=$((SUCCESS_COUNT + 1))
}
increment_warning() {
WARNING_COUNT=$((WARNING_COUNT + 1))
}
increment_error() {
ERROR_COUNT=$((ERROR_COUNT + 1))
}
# Print summary statistics
print_summary() {
echo ""
echo -e "${BLUE}════════════════════════════════════════${NC}"
echo -e "${GREEN}✅ Success: $SUCCESS_COUNT${NC}"
if [ $WARNING_COUNT -gt 0 ]; then
echo -e "${YELLOW}⚠️ Warnings: $WARNING_COUNT${NC}"
fi
if [ $ERROR_COUNT -gt 0 ]; then
echo -e "${RED}❌ Errors: $ERROR_COUNT${NC}"
fi
echo -e "${BLUE}════════════════════════════════════════${NC}"
echo ""
}
# Script directory and integration
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
VERSION_SCRIPT="${SCRIPT_DIR}/version.sh"
GITHUB_WORKFLOWS_DIR="${SCRIPT_DIR}/.github/workflows"
# Configuration
VERSION_FILE="pyproject.toml"
RUNNER_FILE="runner.py"
INIT_FILE="__init__.py"
RUNNERS_INIT="runners/__init__.py"
SETUP_FILE="setup.py"
PACKAGE_VERSION="${RELEASE_VERSION:-}"
# Known version file locations
VERSION_FILES=(
"pyproject.toml"
"runner.py"
"__init__.py"
"runners/__init__.py"
)
# Validate required files exist
check_files_exist() {
local files=("$@")
for file in "${files[@]}"; do
if [ ! -f "$file" ]; then
print_error "Required file not found: $file"
exit 1
fi
done
}
# Validate command exists
check_command_exists() {
if ! command -v "$1" &> /dev/null; then
print_error "Required command not found: $1"
exit 1
fi
}
# Color output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
MAGENTA='\033[0;35m'
CYAN='\033[0;36m'
NC='\033[0m'
# Logging functions
log_debug() {
[ "$DEBUG_MODE" = "true" ] && echo "[DEBUG $(date +%H:%M:%S)] $*" >> "$LOG_FILE"
}
log_info() {
echo "[INFO $(date +%H:%M:%S)] $*" >> "$LOG_FILE"
}
log_warning() {
echo "[WARNING $(date +%H:%M:%S)] $*" >> "$LOG_FILE"
}
log_error() {
echo "[ERROR $(date +%H:%M:%S)] $*" >> "$LOG_FILE"
}
print_header() {
echo -e "${BLUE}=== $1 ===${NC}"
log_info "=== $1 ==="
}
print_success() {
echo -e "${GREEN}✅ $1${NC}"
log_info "SUCCESS: $1"
increment_success
}
print_error() {
echo -e "${RED}❌ $1${NC}"
log_error "$1"
increment_error
}
print_warning() {
echo -e "${YELLOW}⚠️ $1${NC}"
log_warning "$1"
increment_warning
}
print_info() {
echo -e "${CYAN}ℹ️ $1${NC}"
log_info "$1"
}
print_step() {
echo -e "${MAGENTA}▶ $1${NC}"
log_info "STEP: $1"
}
# Auto-commit any uncommitted changes
auto_commit_changes() {
local commit_message="${1:-Auto-commit uncommitted changes before release}"
# Check if there are any uncommitted changes
if git diff-index --quiet HEAD -- 2>/dev/null; then
print_success "No uncommitted changes to commit"
return 0
fi
print_header "Auto-committing Uncommitted Changes"
# Check if we're in a git repository
if ! git rev-parse --is-inside-work-tree &> /dev/null; then
print_warning "Not in a git repository, skipping auto-commit"
return 0
fi
# Get list of changed files
echo "Uncommitted changes detected:"
git status -s
echo ""
# Stash current changes, commit them
print_warning "Automatically staging and committing changes..."
# Add all changes
git add -A
# Check if there's anything staged
if git diff-index --quiet --cached HEAD -- 2>/dev/null; then
print_warning "No changes to commit after staging"
return 0
fi
# Configure git if needed (for CI/CD environments)
if ! git config user.email &> /dev/null; then
git config user.email "automation@localhost"
git config user.name "Automation Script"
fi
# Commit the changes
if git commit -m "$commit_message" 2>&1; then
print_success "Auto-committed changes: $commit_message"
echo "Committed files:"
git log -1 --name-status --pretty=format:""
return 0
else
print_error "Failed to auto-commit changes"
git reset HEAD .
return 1
fi
}
show_help() {
cat << EOF
Python Script Runner - Release Management
INTEGRATED TOOLS:
• version.sh - Semantic versioning (bump, set, validate, sync)
• release.sh - Release orchestration (workflow integration)
• GitHub Actions - Automated testing and publishing
Features:
• Automatic uncommitted changes detection and commit before release
• Semantic versioning with major/minor/patch bumping
• Cross-platform executable building (Windows EXE, Linux DEB)
• GitHub Actions CI/CD workflow integration
Usage: bash release.sh [command] [options]
Commands:
version Show current version and latest git tag
status Show comprehensive release status
bump (major|minor|patch) [dry-run]
Bump version using version.sh (auto-updates files)
⚠️ Auto-commits any uncommitted changes before bumping
validate Run pre-release validation checks
verify-versions Verify version consistency across all files
clean Remove build artifacts and temporary files
auto-release [type] 🚀 FULLY AUTOMATIC RELEASE - Does everything!
Bumps version, builds, tags, and publishes automatically
No prompts, no interaction required (CI/CD friendly)
Types: major|minor|patch (default: patch)
Example: bash release.sh auto-release patch
build-bundles Build Python source bundles (tar.gz, zip)
build-exe VER Build Windows EXE executable using PyInstaller
build-deb VER Build Linux DEB package
prepare-release VER Prepare release: update files, create git tag
⚠️ Auto-commits any uncommitted changes before preparing
publish VER Push tag to GitHub (triggers GitHub Actions workflow)
full-release VER Execute complete release workflow (all steps)
help Show this help message
Environment Variables:
DEBUG=true Enable debug logging
INTERACTIVE=false Disable interactive prompts
SKIP_TESTS=true Skip test execution during validation
PARALLEL_BUILDS=false Disable parallel bundle building
LOG_FILE=path Custom log file location
Workflow:
# ONE-COMMAND AUTOMATIC RELEASE (Recommended):
bash release.sh auto-release patch # Does everything automatically!
# OR Manual step-by-step:
1. bash release.sh bump patch # Auto-bump version (auto-commits)
2. bash release.sh build-exe X.Y.Z # Build Windows executable (optional)
3. bash release.sh build-deb X.Y.Z # Build Linux DEB package (optional)
4. bash release.sh prepare-release X.Y.Z # Create and tag release (auto-commits)
5. bash release.sh publish X.Y.Z # Push tag to GitHub
6. GitHub Actions will auto-build and publish to PyPI & GitHub Packages
Options:
X.Y.Z Version in semantic versioning format
dry-run Preview changes without applying them
Examples:
# Automatic Release (Easiest!):
bash release.sh auto-release # Auto patch release (7.0.1 → 7.0.2)
bash release.sh auto-release minor # Auto minor release (7.0.2 → 7.1.0)
bash release.sh auto-release major # Auto major release (7.1.0 → 8.0.0)
# Manual Commands:
bash release.sh version # Show current version
bash release.sh status # Show comprehensive status
bash release.sh bump patch # Bump to next patch (auto-commits changes)
bash release.sh bump minor dry-run # Preview minor bump
bash release.sh validate # Run validation checks
bash release.sh clean # Clean build artifacts
bash release.sh build-bundles # Build source bundles
bash release.sh build-exe 7.0.1 # Build Windows EXE
bash release.sh build-deb 7.0.1 # Build Linux DEB
bash release.sh prepare-release 7.0.1 # Prepare v7.0.1 release
bash release.sh publish 7.0.1 # Trigger GitHub Actions
Integration Points:
• version.sh is used for version management
• PyInstaller for Windows EXE compilation
• dpkg-deb for Linux DEB packaging
• GitHub Actions triggers on tag push (v*)
• PyPI_API_TOKEN secret required in GitHub Secrets
• GITHUB_TOKEN auto-provided for GitHub Packages
See RELEASING.md for detailed guide and troubleshooting.
EOF
}
get_version() {
local version
if [ -f "$VERSION_FILE" ]; then
version=$(grep '^version = ' "$VERSION_FILE" 2>/dev/null | head -1 | sed 's/version = "\(.*\)"/\1/' || echo "")
if [ -n "$version" ]; then
echo "$version"
return 0
fi
fi
if [ -n "$PACKAGE_VERSION" ]; then
echo "$PACKAGE_VERSION"
return 0
fi
print_error "Unable to determine version"
return 1
}
# Update version in all known locations
update_all_versions() {
local new_version="$1"
local updated_count=0
local failed_count=0
print_step "Updating version to $new_version in all files..."
log_info "Starting automatic version update to $new_version"
# Update pyproject.toml
if [ -f "pyproject.toml" ]; then
if sed -i.bak "s/^version = \".*\"/version = \"$new_version\"/" pyproject.toml 2>/dev/null; then
rm -f pyproject.toml.bak
print_info " ✓ Updated pyproject.toml"
((updated_count++))
else
print_warning " ✗ Failed to update pyproject.toml"
((failed_count++))
fi
fi
# Update runner.py
if [ -f "runner.py" ]; then
if sed -i.bak "s/^__version__ = \".*\"/__version__ = \"$new_version\"/" runner.py 2>/dev/null; then
rm -f runner.py.bak
print_info " ✓ Updated runner.py"
((updated_count++))
else
print_warning " ✗ Failed to update runner.py"
((failed_count++))
fi
fi
# Update __init__.py (root)
if [ -f "__init__.py" ]; then
if sed -i.bak "s/__version__ = \".*\"/__version__ = \"$new_version\"/" __init__.py 2>/dev/null; then
rm -f __init__.py.bak
print_info " ✓ Updated __init__.py"
((updated_count++))
else
print_warning " ✗ Failed to update __init__.py"
((failed_count++))
fi
fi
# Update runners/__init__.py
if [ -f "runners/__init__.py" ]; then
if sed -i.bak "s/^__version__ = \".*\"/__version__ = \"$new_version\"/" runners/__init__.py 2>/dev/null; then
rm -f runners/__init__.py.bak
print_info " ✓ Updated runners/__init__.py"
((updated_count++))
else
print_warning " ✗ Failed to update runners/__init__.py"
((failed_count++))
fi
fi
# Update setup.py fallback version
if [ -f "setup.py" ]; then
if sed -i.bak "s/version_match.group(1) if version_match else \".*\"/version_match.group(1) if version_match else \"$new_version\"/" setup.py 2>/dev/null; then
rm -f setup.py.bak
print_info " ✓ Updated setup.py fallback version"
((updated_count++))
else
print_warning " ✗ Failed to update setup.py"
((failed_count++))
fi
fi
# Summary
if [ $updated_count -gt 0 ]; then
print_success "Updated version in $updated_count file(s)"
fi
if [ $failed_count -gt 0 ]; then
print_warning "Failed to update $failed_count file(s)"
return 1
fi
log_info "Version update completed: $updated_count files updated, $failed_count failed"
return 0
}
# Verify versions are consistent across all files
verify_versions() {
print_step "Verifying version consistency..."
log_info "Starting version consistency check"
local versions=()
local files=()
# Check pyproject.toml
if [ -f "pyproject.toml" ]; then
local v=$(grep '^version = ' pyproject.toml 2>/dev/null | head -1 | sed 's/version = "\(.*\)"/\1/')
if [ -n "$v" ]; then
versions+=("$v")
files+=("pyproject.toml")
print_info " pyproject.toml: $v"
fi
fi
# Check runner.py
if [ -f "runner.py" ]; then
local v=$(grep '^__version__ = ' runner.py 2>/dev/null | sed 's/__version__ = "\(.*\)"/\1/')
if [ -n "$v" ]; then
versions+=("$v")
files+=("runner.py")
print_info " runner.py: $v"
fi
fi
# Check __init__.py
if [ -f "__init__.py" ]; then
local v=$(grep '__version__ = ' __init__.py 2>/dev/null | grep -v 'from\|import' | sed 's/.*__version__ = "\(.*\)".*/\1/' | head -1)
if [ -n "$v" ]; then
versions+=("$v")
files+=("__init__.py")
print_info " __init__.py: $v"
fi
fi
# Check runners/__init__.py
if [ -f "runners/__init__.py" ]; then
local v=$(grep '^__version__ = ' runners/__init__.py 2>/dev/null | sed 's/__version__ = "\(.*\)"/\1/')
if [ -n "$v" ]; then
versions+=("$v")
files+=("runners/__init__.py")
print_info " runners/__init__.py: $v"
fi
fi
# Check if all versions are the same
local unique_versions=($(printf '%s\n' "${versions[@]}" | sort -u))
if [ ${#unique_versions[@]} -eq 1 ]; then
print_success "All versions are consistent: ${unique_versions[0]}"
log_info "Version consistency check passed: ${unique_versions[0]}"
return 0
else
print_error "Version mismatch detected!"
for i in "${!versions[@]}"; do
print_warning " ${files[$i]}: ${versions[$i]}"
done
log_error "Version consistency check failed: found ${#unique_versions[@]} different versions"
return 1
fi
}
validate_version() {
local version=$1
if [[ ! $version =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
print_error "Invalid version format: $version"
echo "Expected format: MAJOR.MINOR.PATCH (e.g., 3.0.1)"
exit 1
fi
}
cmd_version() {
print_header "Python Script Runner Version Info"
local version
if [ -f "pyproject.toml" ]; then
version=$(grep '^version = ' pyproject.toml | sed 's/version = "\(.*\)"/\1/' 2>/dev/null) || version="unknown"
if [ -z "$version" ]; then
version="unknown"
fi
echo "Current Version: $version"
else
if [ -n "$PACKAGE_VERSION" ]; then
echo "Current Version: $PACKAGE_VERSION"
else
echo "Current Version: unknown"
fi
fi
if git rev-parse --git-dir > /dev/null 2>&1; then
local git_tag
if git_tag=$(git describe --tags --abbrev=0 2>/dev/null); then
echo "Latest Git Tag: $git_tag"
else
echo "Latest Git Tag: None"
fi
else
echo "Latest Git Tag: Not a git repository"
fi
}
cmd_bump() {
local bump_type=$1
local dry_run=${2:-}
if [ -z "$bump_type" ]; then
print_error "Bump type required (major|minor|patch)"
exit 1
fi
if [ "$bump_type" != "major" ] && [ "$bump_type" != "minor" ] && [ "$bump_type" != "patch" ]; then
print_error "Invalid bump type: $bump_type"
exit 1
fi
print_header "Automatic Version Bump ($bump_type)"
log_info "Starting version bump: $bump_type (dry_run=$dry_run)"
# Get current version for display
local current_version
current_version=$(get_version || echo "unknown")
print_info "Current version: $current_version"
# Safety check for major version bump
if [ "$bump_type" = "major" ] && [ "$INTERACTIVE_MODE" = "true" ] && [ "$dry_run" != "dry-run" ]; then
print_warning "Major version bump detected!"
print_warning "This indicates breaking changes. Are you sure? (y/n)"
read -r response
if [[ ! "$response" =~ ^[Yy]$ ]]; then
print_info "Version bump cancelled"
exit 0
fi
fi
# Auto-commit any uncommitted changes before bumping (only for actual bump, not dry-run)
if [ "$dry_run" != "dry-run" ]; then
auto_commit_changes "Auto-commit: uncommitted changes before version bump ($bump_type)"
register_rollback "git reset --hard HEAD~1"
fi
# Check if version.sh exists
if [ ! -f "$VERSION_SCRIPT" ]; then
print_error "version.sh not found at $VERSION_SCRIPT"
exit 1
fi
# Validate before bump
if [ "$dry_run" != "dry-run" ]; then
print_warning "Running pre-bump validation..."
cmd_validate || exit 1
fi
# Use version.sh to bump version
print_warning "Delegating to version.sh for version bump..."
if [ "$dry_run" = "dry-run" ]; then
if bash "$VERSION_SCRIPT" bump "$bump_type" dry-run > /dev/null 2>&1; then
print_success "Dry-run completed successfully"
bash "$VERSION_SCRIPT" bump "$bump_type" dry-run
else
print_error "Dry-run failed"
exit 1
fi
else
if bash "$VERSION_SCRIPT" bump "$bump_type" > /dev/null 2>&1; then
print_success "Version bump successful via version.sh"
else
print_error "Version bump failed"
exit 1
fi
# Get new version
local new_version
new_version=$(bash "$VERSION_SCRIPT" current) || { print_error "Failed to get version"; exit 1; }
# Stage all version files
print_warning "Staging version files..."
for file in "$VERSION_FILE" "$RUNNER_FILE" "$INIT_FILE"; do
if [ -f "$file" ]; then
git add "$file" || { print_error "Failed to stage $file"; exit 1; }
fi
done
# Commit changes
print_warning "Committing version bump..."
if git commit -m "chore: bump version to $new_version" > /dev/null 2>&1; then
print_success "Committed version bump to git"
else
print_warning "No version changes to commit"
fi
echo ""
echo "Next step: bash release.sh prepare-release $new_version"
fi
}
cmd_validate() {
print_header "Pre-Release Validation"
log_info "Starting validation"
local validation_errors=0
# Check required commands
print_step "Checking required commands..."
local required_commands=("python3" "git" "pip")
for cmd in "${required_commands[@]}"; do
if command -v "$cmd" &> /dev/null; then
print_info " ✓ $cmd found"
else
print_error " ✗ $cmd not found"
((validation_errors++))
fi
done
# Check required files
print_step "Checking for required files..."
local required_files=("runner.py" "requirements.txt" "LICENSE" "README.md")
for file in "${required_files[@]}"; do
if [ -f "$file" ]; then
print_info " ✓ $file exists"
else
print_error " ✗ $file missing"
((validation_errors++))
fi
done
if [ $validation_errors -gt 0 ]; then
print_error "Validation failed: $validation_errors error(s) found"
return 1
fi
# Check Python version
print_step "Checking Python version..."
local py_version=$(python3 --version 2>&1 | awk '{print $2}')
print_info " Python version: $py_version"
# Check Python compilation
print_step "Checking code quality..."
local compile_output
if compile_output=$(python3 -m py_compile runner.py examples/sample_script.py 2>&1); then
print_success "Compilation successful"
else
print_error "Python compilation failed:"
echo "$compile_output"
((validation_errors++))
fi
# Check dependencies with better error handling
print_step "Checking Python dependencies..."
local dep_check_output
if dep_check_output=$(python3 -c "import psutil, yaml, requests" 2>&1); then
print_success "Core dependencies available"
else
print_warning "Some dependencies missing - attempting installation..."
log_info "Dependency check output: $dep_check_output"
# Try to install missing dependencies
local install_output
if install_output=$(python3 -m pip install --user -q psutil pyyaml requests 2>&1); then
print_success "Dependencies installed successfully"
else
print_warning "Could not auto-install dependencies"
print_info "You may need to run: pip install -r requirements.txt"
log_warning "Dependency installation output: $install_output"
# Don't fail validation for dependency issues in user mode
fi
fi
# Check for development artifacts
print_step "Checking for development artifacts..."
local dev_files=("PRODUCTION_CHECKLIST.md" "RELEASE_NOTES.md" ".DS_Store")
local dev_found=0
for file in "${dev_files[@]}"; do
if [ -f "$file" ]; then
print_warning " Development file found: $file"
((dev_found++))
fi
done
if [ $dev_found -gt 0 ]; then
print_warning "Found $dev_found development file(s) - consider cleanup"
else
print_success "No development artifacts found"
fi
# Check git status
print_step "Checking git repository..."
if ! git rev-parse --git-dir > /dev/null 2>&1; then
print_error "Not a git repository"
((validation_errors++))
else
local branch=$(git branch --show-current)
print_info " Current branch: $branch"
local commit_count=$(git rev-list --count HEAD 2>/dev/null || echo "0")
print_info " Total commits: $commit_count"
if [ -n "$(git status --porcelain)" ]; then
if [ "$INTERACTIVE_MODE" = "true" ]; then
print_warning "Uncommitted changes detected:"
git status --short
echo ""
print_warning "Continue anyway? (y/n)"
read -r response
if [[ ! "$response" =~ ^[Yy]$ ]]; then
print_error "Validation cancelled by user"
exit 1
fi
else
print_warning "Uncommitted changes detected (will be auto-committed)"
fi
else
print_success "Git working directory clean"
fi
fi
# Run tests if available and not skipped
if [ "$SKIP_TESTS" != "true" ] && [ -f "pytest.ini" ]; then
print_step "Running tests..."
if command -v pytest &> /dev/null; then
local test_output
if test_output=$(pytest tests/ -q --tb=short 2>&1); then
print_success "Tests passed"
else
print_warning "Some tests failed:"
echo "$test_output" | head -20
if [ "$INTERACTIVE_MODE" = "true" ]; then
print_warning "Continue despite test failures? (y/n)"
read -r response
if [[ ! "$response" =~ ^[Yy]$ ]]; then
exit 1
fi
fi
fi
else
print_info "pytest not available, skipping tests"
fi
fi
if [ $validation_errors -gt 0 ]; then
print_error "Validation failed with $validation_errors error(s)"
return 1
fi
print_success "All validation checks passed!"
return 0
}
build_bundle_parallel() {
local bundle_type="$1"
local bundle_name="$2"
log_info "Building $bundle_name bundle in parallel"
case "$bundle_type" in
python3)
build_python3_bundle
;;
pypy3)
build_pypy3_bundle
;;
*)
log_error "Unknown bundle type: $bundle_type"
return 1
;;
esac
}
build_python3_bundle() {
log_info "Building Python3 bundle"
mkdir -p dist/python3-runner || return 1
cp runner.py requirements.txt LICENSE README.md dist/python3-runner/ || return 1
cp config.example.yaml dist/python3-runner/ 2>/dev/null || true
cat > dist/python3-runner/INSTALL.sh << 'INSTALL_SCRIPT' || return 1
#!/bin/bash
set -e
echo "Installing Python Script Runner (Python 3)..."
python3 -m pip install -r requirements.txt
chmod +x runner.py
echo "✅ Installation complete!"
echo "Usage: python3 runner.py <script.py> [options]"
INSTALL_SCRIPT
chmod +x dist/python3-runner/INSTALL.sh || return 1
cd dist || return 1
tar -czf python3-runner.tar.gz python3-runner/ 2>/dev/null || { cd ..; return 1; }
zip -q -r python3-runner.zip python3-runner/ 2>/dev/null || { cd ..; return 1; }
cd .. || return 1
log_info "Python3 bundle completed"
return 0
}
build_pypy3_bundle() {
log_info "Building PyPy3 bundle"
mkdir -p dist/pypy3-runner || return 1
cp runner.py requirements.txt LICENSE README.md dist/pypy3-runner/ || return 1
cp config.example.yaml requirements-pypy3.txt dist/pypy3-runner/ 2>/dev/null || true
cat > dist/pypy3-runner/INSTALL.sh << 'INSTALL_SCRIPT' || return 1
#!/bin/bash
set -e
echo "Installing Python Script Runner (PyPy3)..."
if ! command -v pypy3 &> /dev/null; then
echo "PyPy3 not found. Installing..."
if command -v apt-get &> /dev/null; then
sudo apt-get update && sudo apt-get install -y pypy3 pypy3-dev
elif command -v brew &> /dev/null; then
brew install pypy3
else
echo "Please install PyPy3 manually"
exit 1
fi
fi
pypy3 -m pip install -r requirements.txt
pypy3 -m pip install -r requirements-pypy3.txt 2>/dev/null || true
chmod +x runner.py
echo "✅ Installation complete!"
echo "Usage: pypy3 runner.py <script.py> [options]"
INSTALL_SCRIPT
chmod +x dist/pypy3-runner/INSTALL.sh || return 1
cd dist || return 1
tar -czf pypy3-runner.tar.gz pypy3-runner/ 2>/dev/null || { cd ..; return 1; }
zip -q -r pypy3-runner.zip pypy3-runner/ 2>/dev/null || { cd ..; return 1; }
cd .. || return 1
log_info "PyPy3 bundle completed"
return 0
}
cmd_build_bundles() {
print_header "Building Release Bundles"
log_info "Starting bundle build"
# Check required files exist
if ! check_files_exist "runner.py" "requirements.txt" "LICENSE" "README.md"; then
print_error "Missing required files for bundle build"
exit 1
fi
# Create dist directory
if ! mkdir -p dist; then
print_error "Failed to create dist directory"
exit 1
fi
if [ ! -d "dist" ]; then
print_error "dist directory does not exist or is not accessible"
exit 1
fi
# Build bundles in parallel if enabled
if [ "$PARALLEL_BUILDS" = "true" ]; then
print_step "Building bundles in parallel..."
build_python3_bundle &
local py3_pid=$!
build_pypy3_bundle &
local pypy3_pid=$!
# Wait for both builds
local py3_status=0
local pypy3_status=0
wait $py3_pid || py3_status=$?
wait $pypy3_pid || pypy3_status=$?
if [ $py3_status -eq 0 ]; then
print_success "Python 3 bundle created"
else
print_error "Python 3 bundle failed"
exit 1
fi
if [ $pypy3_status -eq 0 ]; then
print_success "PyPy3 bundle created"
else
print_error "PyPy3 bundle failed"
exit 1
fi
else
# Sequential build
print_step "Building Python 3 bundle..."
if build_python3_bundle; then
print_success "Python 3 bundle created"
else
print_error "Python 3 bundle failed"
exit 1
fi
print_step "Building PyPy3 bundle..."
if build_pypy3_bundle; then
print_success "PyPy3 bundle created"
else
print_error "PyPy3 bundle failed"
exit 1
fi
fi
# Remove old sequential code - now using functions above
# Build Python3 bundle
# print_warning "Building Python 3 bundle..."