Skip to content

Improve release script#565

Merged
Chemaclass merged 3 commits intomainfrom
chore/improve-release-script
Dec 15, 2025
Merged

Improve release script#565
Chemaclass merged 3 commits intomainfrom
chore/improve-release-script

Conversation

@Chemaclass
Copy link
Copy Markdown
Member

@Chemaclass Chemaclass commented Dec 15, 2025

📚 Description

Improves the release script with sandbox mode, pre-flight checks, automatic rollback capabilities, and code quality refactoring for safer, more testable, and automated releases.

🔖 Changes

New Features

  • Sandbox Mode (--sandbox): Test releases in an isolated temp directory with mocked git/gh commands
  • Force Mode (--force): Skip all interactive confirmations for CI automation
  • JSON Output (--json): Machine-readable output for CI pipelines (logs go to stderr, JSON to stdout)
  • Verbose Mode (--verbose): Detailed logging for debugging
  • Manual Rollback (--rollback): Restore files from the most recent backup

Safety & Resilience

  • Pre-flight checks: Validates environment before any modifications
    • gh CLI installed and authenticated
    • Git working directory clean
    • On main branch
    • Network connectivity
    • Required files present
    • CHANGELOG.md has Unreleased section with content
  • Automatic backup/rollback: Creates backups before modifications, auto-restores on failure via trap
  • Proper exit codes: 0=success, 1=validation error, 2=execution error

Code Quality Refactoring

  • DRY improvements:
    • Added release::update_file_pattern helper to consolidate version update functions
    • Added RELEASE_FILES constant to avoid repeating file lists
    • Added release::blank_line helper for consistent output formatting
  • Extracted constants:
    • GITHUB_REPO_PATH and GITHUB_REPO_URL for maintainability
  • Fixed inconsistencies:
    • All error exits now use $EXIT_VALIDATION_ERROR instead of hardcoded 1

📖 Usage Examples

Preview a release (dry-run)

./release.sh 0.31.0 --dry-run

Test release in sandbox (safe, isolated environment)

./release.sh 0.31.0 --sandbox

This creates a temp directory, copies the project, mocks git push and gh commands, and shows what would happen.

CI/CD automation

./release.sh 0.31.0 --force --json

Output:

{
  "status": "success",
  "version": "0.31.0",
  "current_version": "0.30.0",
  "sandbox_mode": false,
  "dry_run": false,
  "force_mode": true,
  "completed_steps": ["update_bashunit_version","update_install_version",...],
  "timestamp": "2025-12-15T10:30:00Z"
}

Rollback after a failed release

./release.sh --rollback

Full interactive release with GitHub release creation

./release.sh 0.31.0 --with-gh-release

✅ To-do list

  • I updated the CHANGELOG.md to reflect the new feature or fix
  • I updated the documentation to reflect the changes

  - Add --sandbox flag to test releases in isolated temp directory
  - Add --force flag to skip confirmations (for CI automation)
  - Add --json flag for machine-readable output
  - Add --verbose flag for detailed logging
  - Add --rollback flag to restore from backup
  - Add pre-flight checks (gh auth, git clean, required files, etc.)
  - Add automatic backup/rollback on failure
  - Add proper exit codes (0=success, 1=validation, 2=execution)
  - Redirect all logs to stderr, only JSON to stdout
  - Add tests for new functionality
@Chemaclass Chemaclass added the enhancement New feature or request label Dec 15, 2025
@Chemaclass Chemaclass self-assigned this Dec 15, 2025
  - Replace 'which' with 'command -v' for POSIX compliance
  - Simplify preflight::check_all using array iteration
  - Simplify backup::save_all using array iteration
@Chemaclass Chemaclass force-pushed the chore/improve-release-script branch from 7344494 to eafad66 Compare December 15, 2025 18:23
@Chemaclass Chemaclass merged commit 944bca3 into main Dec 15, 2025
16 checks passed
@Chemaclass Chemaclass deleted the chore/improve-release-script branch December 15, 2025 18:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant