aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/release.sh
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/release.sh')
-rwxr-xr-xscripts/release.sh225
1 files changed, 225 insertions, 0 deletions
diff --git a/scripts/release.sh b/scripts/release.sh
new file mode 100755
index 0000000..fcde1e3
--- /dev/null
+++ b/scripts/release.sh
@@ -0,0 +1,225 @@
+#!/usr/bin/env bash
+set -eou pipefail
+
+source "$(dirname "${BASH_SOURCE[0]}")/lib/log.sh"
+source "$(dirname "${BASH_SOURCE[0]}")/lib/path.sh"
+
+readonly VERSION_FILE="$PATH_PROJECT_DIR/internal/commands/version.go"
+readonly CHANGELOG_FILE="$PATH_PROJECT_DIR/CHANGELOG.md"
+readonly README_FILE="$PATH_PROJECT_DIR/README.md"
+readonly DOCS_INDEX_FILE="$PATH_PROJECT_DIR/docs/index.md"
+
+usage() {
+ echo "Usage: $0 <version>"
+ echo ""
+ echo "Create a new release by:"
+ echo " - Bumping version in all relevant files"
+ echo " - Updating CHANGELOG.md with new version and today's date"
+ echo " - Creating a release commit"
+ echo " - Tagging the commit with the new version"
+ echo ""
+ echo "Arguments:"
+ echo " version The new version (e.g., 0.11.0)"
+ echo ""
+ echo "Examples:"
+ echo " $0 0.11.0"
+}
+
+validate_version_format() {
+ local version="$1"
+ if ! [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
+ log_error "Invalid version format: $version"
+ log_info "Expected format: X.Y.Z (e.g., 0.11.0)"
+ exit 1
+ fi
+}
+
+check_git_status() {
+ if ! git rev-parse --git-dir > /dev/null 2>&1; then
+ log_error "Not in a git repository"
+ exit 1
+ fi
+
+ if ! git diff-index --quiet HEAD --; then
+ log_error "Working directory is not clean"
+ log_info "Please commit or stash your changes first"
+ exit 1
+ fi
+}
+
+check_branch() {
+ local current_branch
+ current_branch=$(git branch --show-current)
+
+ if [[ "$current_branch" != "main" ]]; then
+ log_warn "You are on branch '$current_branch', not 'main'"
+ read -p "Continue anyway? (y/N) " -r -n 1
+ echo
+ if [[ ! $REPLY =~ ^[Yy]$ ]]; then
+ log_info "Release aborted"
+ exit 0
+ fi
+ fi
+}
+
+get_current_version() {
+ local current_version
+ current_version=$(grep -o 'bolt v[0-9]\+\.[0-9]\+\.[0-9]\+' "$VERSION_FILE" | sed 's/bolt v//')
+
+ if [[ -z "$current_version" ]]; then
+ log_error "Could not extract current version from $VERSION_FILE"
+ exit 1
+ fi
+
+ echo "$current_version"
+}
+
+check_version_tag() {
+ local version="$1"
+ if git rev-parse "v$version" >/dev/null 2>&1; then
+ log_error "Version v$version is already tagged"
+ exit 1
+ fi
+}
+
+update_version_file() {
+ local old_version="$1"
+ local new_version="$2"
+
+ log_step "Updating version in $VERSION_FILE"
+ sed -i.bak "s/bolt v$old_version/bolt v$new_version/g" "$VERSION_FILE"
+ rm -f "$VERSION_FILE.bak"
+}
+
+update_readme() {
+ local old_version="$1"
+ local new_version="$2"
+
+ log_step "Updating version in $README_FILE"
+ sed -i.bak "s/version-$old_version-blue/version-$new_version-blue/g" "$README_FILE"
+ rm -f "$README_FILE.bak"
+}
+
+update_docs_index() {
+ local old_version="$1"
+ local new_version="$2"
+
+ log_step "Updating version in $DOCS_INDEX_FILE"
+ sed -i.bak "s/version-$old_version-blue/version-$new_version-blue/g" "$DOCS_INDEX_FILE"
+ rm -f "$DOCS_INDEX_FILE.bak"
+}
+
+update_changelog() {
+ local new_version="$1"
+ local today
+ today=$(date +%Y-%m-%d)
+
+ log_step "Updating $CHANGELOG_FILE"
+
+ if ! grep -q "## \[Unreleased\]" "$CHANGELOG_FILE"; then
+ log_error "No [Unreleased] section found in $CHANGELOG_FILE"
+ exit 1
+ fi
+
+ # Replace [Unreleased] with the new version and date, and add a new [Unreleased] section
+ awk -v version="$new_version" -v date="$today" '
+ /^## \[Unreleased\]/ {
+ print $0
+ print ""
+ print "## [" version "] - " date
+ next
+ }
+ { print }
+ ' "$CHANGELOG_FILE" > "$CHANGELOG_FILE.tmp"
+
+ mv "$CHANGELOG_FILE.tmp" "$CHANGELOG_FILE"
+}
+
+show_changes() {
+ log_newline
+ log_step "Changes to be committed:"
+ git diff "$VERSION_FILE" "$README_FILE" "$DOCS_INDEX_FILE" "$CHANGELOG_FILE"
+}
+
+confirm_release() {
+ local version="$1"
+ log_newline
+ read -p "Create release commit and tag for v$version? (y/N) " -r -n 1
+ echo
+ if [[ ! $REPLY =~ ^[Yy]$ ]]; then
+ log_info "Release aborted. Changes have been made but not committed."
+ exit 0
+ fi
+}
+
+create_release_commit() {
+ local version="$1"
+
+ log_step "Creating release commit"
+ git add "$VERSION_FILE" "$README_FILE" "$DOCS_INDEX_FILE" "$CHANGELOG_FILE"
+ git commit -m "Release v$version"
+}
+
+create_release_tag() {
+ local version="$1"
+
+ log_step "Creating git tag v$version"
+ git tag -a "v$version" -m "Release v$version"
+}
+
+show_next_steps() {
+ local version="$1"
+ local current_branch
+ current_branch=$(git branch --show-current)
+
+ log_newline
+ log_success "Release v$version created successfully!"
+ log_newline
+ log_info "Next steps:"
+ log_substep "Review the commit and tag:"
+ log_substep " git show v$version"
+ log_substep "Push the commit and tag:"
+ log_substep " git push origin $current_branch"
+ log_substep " git push origin v$version"
+ log_substep "Or push both at once:"
+ log_substep " git push origin $current_branch --follow-tags"
+}
+
+main() {
+ local new_version="${1:-}"
+
+ if [[ -z "$new_version" || "$new_version" == "-h" || "$new_version" == "--help" ]]; then
+ usage
+ exit 0
+ fi
+
+ log_header "Creating Release v$new_version"
+
+ validate_version_format "$new_version"
+ check_git_status
+ check_branch
+
+ local current_version
+ current_version=$(get_current_version)
+
+ log_info "Current version: $current_version"
+ log_info "New version: $new_version"
+ log_newline
+
+ check_version_tag "$new_version"
+
+ update_version_file "$current_version" "$new_version"
+ update_readme "$current_version" "$new_version"
+ update_docs_index "$current_version" "$new_version"
+ update_changelog "$new_version"
+
+ show_changes
+ confirm_release "$new_version"
+
+ create_release_commit "$new_version"
+ create_release_tag "$new_version"
+
+ show_next_steps "$new_version"
+}
+
+main "$@"