Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions tools/version.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,34 @@
#!/usr/bin/env bash
# Compute the rolling project version: YY.MM.NN
# YY.MM : year.month of the current date (e.g. 26.09)
# NN : number of commits since the version tag vYY.MM (e.g. v26.09).
# 00 when the tag does not exist yet.
# Output: 26.09.00
# NN : number of commits since the monthly version tag (e.g. 26.09).
# 00 when no such tag exists yet.
# The monthly tag is looked up without a "v" prefix (the project
# convention -- the raw tag name is what sas_py's
# setuptools-git-versioning turns into the PyPI version); a "v"-prefixed
# tag is accepted as a fallback.
# Output: 26.09.05
set -euo pipefail

YYMM="$(date +%y.%m)"
TAG="v${YYMM}"

# Echo the first existing monthly tag (bare YY.MM, then v-prefixed).
find_version_tag() {
local t
for t in "${YYMM}" "v${YYMM}"; do
if git rev-parse --verify "refs/tags/${t}" >/dev/null 2>&1; then
printf '%s\n' "${t}"
return 0
fi
done
return 1
}

NN=0
if command -v git >/dev/null 2>&1 && git rev-parse --git-dir >/dev/null 2>&1; then
if git rev-parse --verify "refs/tags/${TAG}" >/dev/null 2>&1; then
if TAG="$(find_version_tag)"; then
NN="$(git rev-list "${TAG}..HEAD" --count 2>/dev/null || echo 0)"
else
NN=0
fi
else
NN=0
fi

printf '%s.%02d\n' "${YYMM}" "${NN:-0}"
Loading