fix: release script auto-bumps patch by default
Release script now supports: patch (default), minor, major, or explicit version. Auto-updates Cargo.toml and flake.nix before building. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -5,7 +5,11 @@ set -euo pipefail
|
|||||||
# Builds a static binary, generates changelog, and creates a Gitea release.
|
# Builds a static binary, generates changelog, and creates a Gitea release.
|
||||||
#
|
#
|
||||||
# Usage:
|
# Usage:
|
||||||
# ./scripts/release.sh [version]
|
# ./scripts/release.sh # auto-bump patch (0.2.0 → 0.2.1)
|
||||||
|
# ./scripts/release.sh patch # same as above
|
||||||
|
# ./scripts/release.sh minor # bump minor (0.2.0 → 0.3.0)
|
||||||
|
# ./scripts/release.sh major # bump major (0.2.0 → 1.0.0)
|
||||||
|
# ./scripts/release.sh v1.2.3 # explicit version
|
||||||
#
|
#
|
||||||
# Environment:
|
# Environment:
|
||||||
# GITEA_TOKEN - API token for git.qrty.ink (prompted if not set)
|
# GITEA_TOKEN - API token for git.qrty.ink (prompted if not set)
|
||||||
@@ -34,14 +38,33 @@ warn() { printf "${YELLOW}!!${NC} %s\n" "$1"; }
|
|||||||
err() { printf "${RED}error:${NC} %s\n" "$1" >&2; exit 1; }
|
err() { printf "${RED}error:${NC} %s\n" "$1" >&2; exit 1; }
|
||||||
|
|
||||||
# --- Determine version ---
|
# --- Determine version ---
|
||||||
VERSION="${1:-}"
|
CURRENT=$(grep '^version' Cargo.toml | head -1 | sed 's/.*"\(.*\)".*/\1/')
|
||||||
if [ -z "$VERSION" ]; then
|
BUMP="${1:-patch}"
|
||||||
VERSION=$(grep '^version' Cargo.toml | head -1 | sed 's/.*"\(.*\)".*/\1/')
|
|
||||||
info "Version from Cargo.toml: v$VERSION"
|
bump_version() {
|
||||||
fi
|
local ver="$1" part="$2"
|
||||||
# Ensure v prefix
|
IFS='.' read -r major minor patch <<< "$ver"
|
||||||
[[ "$VERSION" == v* ]] || VERSION="v$VERSION"
|
case "$part" in
|
||||||
TAG="$VERSION"
|
major) echo "$((major + 1)).0.0" ;;
|
||||||
|
minor) echo "$major.$((minor + 1)).0" ;;
|
||||||
|
patch) echo "$major.$minor.$((patch + 1))" ;;
|
||||||
|
*) echo "$part" ;; # treat as explicit version
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
case "$BUMP" in
|
||||||
|
major|minor|patch)
|
||||||
|
VERSION=$(bump_version "$CURRENT" "$BUMP")
|
||||||
|
info "Bumping $BUMP: $CURRENT → $VERSION"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
# Explicit version — strip v prefix if present
|
||||||
|
VERSION="${BUMP#v}"
|
||||||
|
info "Explicit version: $VERSION"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
TAG="v$VERSION"
|
||||||
|
|
||||||
# --- Check for clean working tree ---
|
# --- Check for clean working tree ---
|
||||||
if [ -n "$(git status --porcelain)" ]; then
|
if [ -n "$(git status --porcelain)" ]; then
|
||||||
@@ -54,7 +77,18 @@ fi
|
|||||||
|
|
||||||
# --- Check if tag already exists ---
|
# --- Check if tag already exists ---
|
||||||
if git rev-parse "$TAG" >/dev/null 2>&1; then
|
if git rev-parse "$TAG" >/dev/null 2>&1; then
|
||||||
err "Tag $TAG already exists. Bump version in Cargo.toml or choose a different version."
|
err "Tag $TAG already exists. Choose a different version."
|
||||||
|
fi
|
||||||
|
|
||||||
|
# --- Update version in source files ---
|
||||||
|
if [ "$VERSION" != "$CURRENT" ]; then
|
||||||
|
info "Updating version in Cargo.toml and flake.nix..."
|
||||||
|
sed -i "0,/^version = \"$CURRENT\"/s//version = \"$VERSION\"/" Cargo.toml
|
||||||
|
sed -i "s/version = \"$CURRENT\";/version = \"$VERSION\";/g" flake.nix
|
||||||
|
sed -i "s/v$CURRENT/v$VERSION/g" flake.nix
|
||||||
|
git add Cargo.toml flake.nix
|
||||||
|
git commit --no-gpg-sign -m "chore: bump version to $VERSION"
|
||||||
|
ok "Version updated and committed"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# --- Generate changelog ---
|
# --- Generate changelog ---
|
||||||
|
|||||||
Reference in New Issue
Block a user