#!/usr/bin/env sh set -eu tag=$(git describe --tags --match 'v[0-9]*.[0-9]*.[0-9]*' --abbrev=0 2>/dev/null || true) sha=$(git rev-parse --short=8 HEAD 2>/dev/null || printf 'nogit000') if [ -n "$tag" ] && git tag --points-at HEAD | grep -Fxq "$tag"; then [ "${1:-}" = "--release-needed" ] && { printf 'false\n'; exit 0; } [ "${1:-}" = "--next-release" ] && { printf '%s\n' "${tag#v}"; exit 0; } printf '%s\n' "${tag#v}" exit 0 fi if [ -n "$tag" ]; then has_tag=true base=${tag#v} range="$tag..HEAD" commits=$(git rev-list --count "$range") log_range=$range else has_tag=false base=0.1.0 log_range=HEAD commits=$(git rev-list --count HEAD 2>/dev/null || printf '0') fi major=${base%%.*} remainder=${base#*.} minor=${remainder%%.*} patch=${remainder#*.} bump=0 log_file=$(mktemp) trap 'rm -f "$log_file"' EXIT git log --format=%B "$log_range" 2>/dev/null > "$log_file" || : if grep -Eq '^(BREAKING CHANGE:|BREAKING-CHANGE:)|^[a-z]+(\([^)]*\))?!:' "$log_file"; then bump=3 elif grep -Eq '^feat(\([^)]*\))?:' "$log_file"; then bump=2 elif grep -Eq '^(fix|perf|refactor)(\([^)]*\))?:' "$log_file"; then bump=1 fi case "$bump" in 3) major=$((major + 1)); minor=0; patch=0 ;; 2) minor=$((minor + 1)); patch=0 ;; 1) patch=$((patch + 1)) ;; esac next="$major.$minor.$patch" case "${1:-}" in --release-needed) [ "$bump" -gt 0 ] && printf 'true\n' || printf 'false\n' ;; --next-release) printf '%s\n' "$next" ;; *) if [ "$has_tag" = false ]; then printf '0.1.0-SNAPSHOT.%s+%s\n' "$commits" "$sha"; else printf '%s-SNAPSHOT.%s+%s\n' "$next" "$commits" "$sha"; fi ;; esac