#!/usr/bin/env bash # # Release script: bump version, generate changelog, commit, and tag. # # Usage: # ./scripts/release.sh # ./scripts/release.sh 2.0.0 # explicit version # set -euo pipefail VERSION_FILE="version" current_version=$(cat "$VERSION_FILE") echo "Current version: $current_version" IFS='.' read -r major minor patch <<< "$current_version" case "${1:-}" in major) new_version="$((major + 1)).0.0" ;; minor) new_version="${major}.$((minor + 1)).0" ;; patch) new_version="${major}.${minor}.$((patch + 1))" ;; "") echo "Usage: $0 " exit 1 ;; *) # Validate explicit semver if [[ ! "$1" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then echo "Error: '$1' is not a valid semver (X.Y.Z)" exit 1 fi new_version="$1" ;; esac echo "Bumping to: $new_version" # Update version file echo "$new_version" > "$VERSION_FILE" # Generate changelog git-cliff --tag "v${new_version}" --output CHANGELOG.md # Commit and tag git add "$VERSION_FILE" CHANGELOG.md git commit -m "chore(release): v${new_version}" git tag "v${new_version}" echo "" echo "Released v${new_version}" echo "Don't forget to push: git push && git push --tags"