#!/usr/bin/env bash # Prepare a release IN THE WORKING TREE only — no commit, no tag. Regenerates CHANGELOG.md # ([Unreleased] -> the target version) and writes the VERSION file. The commit/tag/push is # the caller's job, so this is shared by: # - scripts/release.sh (local: prepare -> commit -> tag) # - the release-PR CI step (prepare -> commit onto chore/release -> force-push) # # Usage: ./scripts/prepare-release.sh [X.Y.Z] # No arg -> next version is computed from conventional commits since the last tag via # `git-cliff --bumped-version` (SemVer 0.x rules: feat/fix -> patch, # breaking -> minor). A leading `v` is tolerated on an explicit arg. # # Prints the resolved version (no leading `v`) to stdout. All diagnostics go to stderr, so # callers can capture the version with `ver="$(scripts/prepare-release.sh)"`. set -euo pipefail command -v git-cliff >/dev/null || { echo "error: git-cliff not installed (brew install git-cliff)" >&2; exit 1; } ver="${1:-}" if [ -z "$ver" ]; then # git-cliff prints the bumped version (e.g. v0.3.4) to stdout; warnings go to stderr. ver="$(git-cliff --bumped-version)" fi ver="${ver#v}" tag="v${ver}" # [Unreleased] -> [] in the changelog, and bump the VERSION file (the publish trigger). git-cliff --tag "$tag" -o CHANGELOG.md >&2 printf '%s\n' "$ver" > VERSION echo "$ver"