BlueGit

timfa posprint

Files

posprint / scripts / ci / next-version.sh

next-version.sh

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