#!/usr/bin/env bash # Print an auto-generated nightly version string derived from git history: # # +.g e.g., 26.8.0+14.gb1a2c3d4 # # When no release has been tagged yet, the base is 0.0.0 and the count is the # total number of commits: # # 0.0.0+.g e.g., 0.0.0+57.gb1a2c3d4 # # The `+...` part is SemVer build metadata, so the string stays a valid version # and never sorts ahead of the release it is based on. Needs full history and # tags (check out with fetch-depth: 0 and fetch-tags: true). Release tags are # matched as N.N.N; the moving `nightly` tag is ignored. set -euo pipefail sha="$(git rev-parse --short=8 HEAD)" if desc="$(git describe --tags --long \ --match '[0-9]*.[0-9]*.[0-9]*' --exclude nightly 2>/dev/null)"; then # desc is --g; the tag itself has no '-', so strip from the right. rest="${desc%-g*}" n="${rest##*-}" tag="${rest%-*}" echo "${tag}+${n}.g${sha}" else n="$(git rev-list --count HEAD)" echo "0.0.0+${n}.g${sha}" fi