diff --git a/scripts/make-release.sh b/scripts/make-release.sh index 4f98b51..4943f94 100755 --- a/scripts/make-release.sh +++ b/scripts/make-release.sh @@ -4,27 +4,23 @@ set -euo pipefail -# -- Step 0: Determine bump type -- -BUMP_TYPE="${1:-patch}" # default to 'patch' if not set: patch|minor|major +# 1. Figure out the bump type +BUMP_TYPE="${1:-patch}" # one of: patch, minor, major -# -- Step 1: Read current version from Cargo.toml -- +# 2. Get the current version from Cargo.toml CURRENT_VERSION="$(cargo pkgid | cut -d# -f2 | cut -d: -f2)" echo "Current Cargo version: $CURRENT_VERSION" -# Validate version format -if ! echo "$CURRENT_VERSION" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$'; then - echo "Error: Invalid version format in Cargo.toml. Expected format: X.Y.Z" +# Quick format check (X.Y.Z) +if ! [[ "$CURRENT_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "Error: Invalid version format in Cargo.toml ($CURRENT_VERSION). Expected X.Y.Z" exit 1 fi -# Split into semver parts and validate +# Split out version parts IFS='.' read -r MAJOR MINOR PATCH <<<"$CURRENT_VERSION" -if ! [[ "$MAJOR" =~ ^[0-9]+$ ]] || ! [[ "$MINOR" =~ ^[0-9]+$ ]] || ! [[ "$PATCH" =~ ^[0-9]+$ ]]; then - echo "Error: Version components must be valid numbers" - exit 1 -fi -# -- Step 2: Bump version accordingly -- +# 3. Increment accordingly case "$BUMP_TYPE" in major) MAJOR=$((MAJOR + 1)) @@ -47,32 +43,33 @@ esac NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}" echo "Bumping version to: $NEW_VERSION" -# -- Step 3: Update CHANGELOG.md using git-cliff -- -git-cliff --config cliff.toml --tag "v${NEW_VERSION}" --output CHANGELOG.md +# 4. Generate/Update CHANGELOG using cargo-cliff +# Make sure cargo-cliff is installed (cargo install cargo-cliff) +cargo cliff --tag "v${NEW_VERSION}" --output CHANGELOG.md -# -- Step 4: Update Cargo.toml version -- +# 5. Update Cargo.toml sed -i.bak "s/^version *= *\"${CURRENT_VERSION}\"/version = \"${NEW_VERSION}\"/" Cargo.toml rm -f Cargo.toml.bak -# -- Step 5: Build artifacts and compute SHA -- -make build-artifacts +# 6. Update Cargo.lock (so that if your package references itself, it's updated) +cargo update -p "$(cargo pkgid | sed 's|.*#||')" -# -- Step 6: Stage all changes -- -git add Cargo.toml Cargo.lock CHANGELOG.md .gitignore - -# -- Step 7: Amend the last commit with version bump changes -- -if git log -1 --pretty=%B | grep -q "^release: v"; then - # If the last commit is already a release commit, amend it - git commit --amend --no-edit -else - # Create a new release commit - git commit -m "release: v${NEW_VERSION}" +# 7. Commit changes +git add Cargo.toml Cargo.lock CHANGELOG.md +if git diff --cached --quiet; then + echo "No changes to commit. Exiting." + exit 0 fi -# -- Step 8: Tag and push -- -git tag -f "v${NEW_VERSION}" # -f in case we're amending and the tag exists -git push -f origin HEAD # Push current branch, not necessarily main -git push -f origin "v${NEW_VERSION}" +git commit -m "release: v${NEW_VERSION}" + +# 8. Tag the commit (annotated) +git tag -a "v${NEW_VERSION}" -m "release: v${NEW_VERSION}" -echo "Done. Pushed tag v${NEW_VERSION}." -echo "CI should trigger on that tag to build & publish a release." +echo +echo "Local release commit and tag v${NEW_VERSION} created." +echo "Review your changes, then push if desired:" +echo " git push origin HEAD" +echo " git push origin v${NEW_VERSION}" +echo +echo "Done."