#!/usr/bin/env bash # Print the version for the next release: RELEASE_VERSION if set, otherwise # the highest X.Y.Z (or vX.Y.Z) tag plus one patch, or Cargo.toml's version # if that is higher. Tags are bare (e.g. 0.5.9), like on GitLab. set -euo pipefail cd "$(dirname "$0")/../.." if [[ -n "${RELEASE_VERSION:-}" ]]; then echo "${RELEASE_VERSION#v}"; exit; fi url="${CI_PROJECT_URL:-https://git.timfalken.com/timfa/posprint}.git" tags="$( { git tag -l 2>/dev/null || true; git ls-remote --tags "$url" 2>/dev/null | sed 's|.*refs/tags/||' || true; } )" last="$(printf '%s\n' "$tags" | sed 's/^v//' | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | sort -V | tail -n1 || true)" last="${last:-0.0.0}" IFS=. read -r maj min pat <<<"$last" next="${maj}.${min}.$((pat + 1))" cargo="$(grep -m1 '^version = ' Cargo.toml | sed -E 's/.*"([^"]+)"/\1/')" if [[ "$(printf '%s\n%s\n' "$next" "$cargo" | sort -V | tail -n1)" == "$cargo" && "$cargo" != "$last" ]]; then next="$cargo"; fi echo "$next"