#!/usr/bin/env bash # Makes a release: tags the current commit `vMAJOR.MINOR.PATCH` and builds the package for it (package.sh). # Usage: deploy/release.sh patch|minor|major|X.Y.Z [--push] # patch/minor/major count up from the latest release tag (v0.0.0 if there is none yet). # --push also pushes the tag to origin. set -euo pipefail root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" deploy="$root/deploy" bump="${1:-}" push="${2:-}" if [[ -z "$bump" ]]; then echo "Usage: deploy/release.sh patch|minor|major|X.Y.Z [--push]" >&2 exit 1 fi if [[ -n "$(git -C "$root" status --porcelain)" ]]; then echo "The working tree has uncommitted changes; commit or stash them first." >&2 exit 1 fi latest="$(git -C "$root" describe --tags --abbrev=0 --match 'v[0-9]*' 2>/dev/null || echo v0.0.0)" IFS=. read -r major minor patch <<< "${latest#v}" case "$bump" in major) next="$((major + 1)).0.0" ;; minor) next="$major.$((minor + 1)).0" ;; patch) next="$major.$minor.$((patch + 1))" ;; *) if [[ ! "$bump" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then echo "'$bump' is neither patch, minor, major nor a version like 1.2.3." >&2 exit 1 fi next="$bump" ;; esac if git -C "$root" rev-parse -q --verify "refs/tags/v$next" > /dev/null; then echo "The tag v$next exists already." >&2 exit 1 fi echo "Releasing $next (latest was ${latest#v})." git -C "$root" tag -a "v$next" -m "Release $next" if [[ "$push" == "--push" ]]; then git -C "$root" push origin "v$next" fi "$deploy/package.sh" "$next"