|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Usage: ./scripts/bump-version.sh <new-version> |
| 3 | +# ./scripts/bump-version.sh --next-patch |
| 4 | +# ./scripts/bump-version.sh --next-minor |
| 5 | +# ./scripts/bump-version.sh --next-major |
| 6 | +# |
| 7 | +# This script: |
| 8 | +# 1. Updates pluginVersion in gradle.properties |
| 9 | +# 2. Commits the change |
| 10 | +# 3. Creates a git tag vX.Y.Z |
| 11 | +# |
| 12 | +# When called via `make release/patch|minor|major`, the push happens automatically. |
| 13 | +# The tag push triggers the GitHub release workflow. |
| 14 | + |
| 15 | +set -euo pipefail |
| 16 | + |
| 17 | +PROPS_FILE="gradle.properties" |
| 18 | +CURRENT_VERSION=$(grep '^pluginVersion=' "$PROPS_FILE" | cut -d= -f2) |
| 19 | + |
| 20 | +# Parse current version parts |
| 21 | +IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_VERSION" |
| 22 | + |
| 23 | +if [ $# -ne 1 ]; then |
| 24 | + echo "Usage: $0 <new-version> | --next-patch | --next-minor | --next-major" |
| 25 | + exit 1 |
| 26 | +fi |
| 27 | + |
| 28 | +case "$1" in |
| 29 | + --next-patch) |
| 30 | + NEW_VERSION="${MAJOR}.${MINOR}.$((PATCH + 1))" |
| 31 | + ;; |
| 32 | + --next-minor) |
| 33 | + NEW_VERSION="${MAJOR}.$((MINOR + 1)).0" |
| 34 | + ;; |
| 35 | + --next-major) |
| 36 | + NEW_VERSION="$((MAJOR + 1)).0.0" |
| 37 | + ;; |
| 38 | + *) |
| 39 | + NEW_VERSION="$1" |
| 40 | + ;; |
| 41 | +esac |
| 42 | +TAG="v${NEW_VERSION}" |
| 43 | + |
| 44 | +# Validate version format (semver: X.Y.Z) |
| 45 | +if ! echo "$NEW_VERSION" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$'; then |
| 46 | + echo "Error: version must be in X.Y.Z format (e.g. 0.2.0)" |
| 47 | + exit 1 |
| 48 | +fi |
| 49 | + |
| 50 | +# Check for uncommitted changes |
| 51 | +if ! git diff --quiet || ! git diff --cached --quiet; then |
| 52 | + echo "Error: you have uncommitted changes. Commit or stash them first." |
| 53 | + exit 1 |
| 54 | +fi |
| 55 | + |
| 56 | +# Check the tag doesn't already exist |
| 57 | +if git rev-parse "$TAG" >/dev/null 2>&1; then |
| 58 | + echo "Error: tag $TAG already exists." |
| 59 | + exit 1 |
| 60 | +fi |
| 61 | + |
| 62 | +echo "Bumping $CURRENT_VERSION → $NEW_VERSION" |
| 63 | + |
| 64 | +# Update gradle.properties |
| 65 | +sed -i "s/^pluginVersion=.*/pluginVersion=${NEW_VERSION}/" "$PROPS_FILE" |
| 66 | + |
| 67 | +git add "$PROPS_FILE" |
| 68 | +git commit -m "chore: bump version to ${NEW_VERSION}" |
| 69 | +git tag "$TAG" |
| 70 | + |
| 71 | +echo "Done. Tag $TAG created." |
0 commit comments