Skip to content

Instantly share code, notes, and snippets.

@LeoBorai
Created May 31, 2026 15:56
Show Gist options
  • Select an option

  • Save LeoBorai/e064d513f6630ba8dc60d6c8406cb334 to your computer and use it in GitHub Desktop.

Select an option

Save LeoBorai/e064d513f6630ba8dc60d6c8406cb334 to your computer and use it in GitHub Desktop.
release.sh
#!/usr/bin/env bash
set -euo pipefail
if [[ $# -ne 1 ]] || [[ ! "$1" =~ ^(patch|minor|major)$ ]]; then
echo "Usage: $0 <patch|minor|major>" >&2
exit 1
fi
BUMP="$1"
LATEST=$(git tag --list 'v*' \
| grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' \
| sort -t. -k1,1V -k2,2n -k3,3n \
| tail -n1)
if [[ -z "$LATEST" ]]; then
CURRENT="0.0.0"
else
CURRENT="${LATEST#v}"
fi
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT"
case "$BUMP" in
major) MAJOR=$((MAJOR + 1)); MINOR=0; PATCH=0 ;;
minor) MINOR=$((MINOR + 1)); PATCH=0 ;;
patch) PATCH=$((PATCH + 1)) ;;
esac
VERSION="v${MAJOR}.${MINOR}.${PATCH}"
printf 'Tag "%s" will be created. (Y/n) ' "$VERSION"
read -r REPLY
if [[ "$REPLY" != "Y" && "$REPLY" != "y" ]]; then
echo "Aborted." >&2
exit 1
fi
git tag -a "$VERSION" -m "$VERSION"
git push origin "$VERSION"
echo "Tagged and pushed $VERSION"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment