-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnext-version.sh
More file actions
executable file
·42 lines (38 loc) · 1.73 KB
/
Copy pathnext-version.sh
File metadata and controls
executable file
·42 lines (38 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env bash
# next-version.sh — compute THIS repo's next release tag for release-on-upstream.yml.
#
# Single source of truth for the version math, exercised in CI by release-selftest.yml so the
# release automation cannot silently rot. Prints "v<MAJOR>.<MINOR>.<PATCH>" to stdout.
#
# Inputs (env, all optional):
# INPUT_VERSION explicit version to cut (leading "v" tolerated) -> used verbatim.
# INITIAL_VERSION first-release default when the repo has NO prior v* tag (default "1.0.0").
#
# Behaviour:
# * explicit INPUT_VERSION -> v<INPUT_VERSION>
# * no prior v* tag (brand-new repo) -> v<INITIAL_VERSION> (NEVER errors — first release)
# * otherwise -> patch-bump the highest existing v* tag
# Fully `set -u` safe: every variable is initialised before use, so no "unbound variable".
set -euo pipefail
input="${INPUT_VERSION:-}"
initial="${INITIAL_VERSION:-1.0.0}"
if [ -n "$input" ]; then
printf 'v%s\n' "${input#v}"
exit 0
fi
latest="$(git tag --list 'v*' | sort -V | tail -1 || true)"
if [ -z "${latest:-}" ]; then
# FIRST RELEASE: no prior v* tag. Default to the declared initial version instead of
# erroring, so a brand-new plugin is cuttable by the release train.
printf 'v%s\n' "${initial#v}"
exit 0
fi
base="${latest#v}"
major="${base%%.*}"; rest="${base#*.}"
minor="${rest%%.*}"; patch="${rest#*.}"
patch="${patch%%[-+]*}" # drop any -rc / +build suffix on the patch component
# Coerce every component to a non-negative integer so arithmetic under set -u never explodes.
case "$major" in ''|*[!0-9]*) major=0 ;; esac
case "$minor" in ''|*[!0-9]*) minor=0 ;; esac
case "$patch" in ''|*[!0-9]*) patch=0 ;; esac
printf 'v%s.%s.%s\n' "$major" "$minor" "$((patch + 1))"