Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ OS ?= $(shell uname)
ARCH ?= $(shell uname -m)

# Retrieve version from git history
VERSION ?= $(shell git describe --tags 2>/dev/null || echo unknown)
VERSION_SCRIPT := scripts/version
VERSION := $(shell $(VERSION_SCRIPT))

# Path to lint tool
GOLINTER ?= golangci-lint
Expand Down
23 changes: 23 additions & 0 deletions scripts/version
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/sh

# Use the nearest vMAJOR.MINOR.PATCH tag; fall back to "unknown" outside Git history.
describe=$(git describe --tags --long --match 'v[0-9]*.[0-9]*.[0-9]*' 2>/dev/null) || {
echo unknown
exit 0
}

tag=$(printf '%s\n' "$describe" | sed 's/-[0-9][0-9]*-g[0-9a-f][0-9a-f]*$//')
suffix=$(printf '%s\n' "$describe" | sed "s/^$tag-//")
distance=${suffix%%-g*}
commit=${suffix#*-g}

# Exact tags keep their version. Later commits use the next patch plus distance and commit ID.
if [ "$distance" -eq 0 ]; then
echo "$tag"
exit 0
fi

version=${tag#v}
IFS=.
set -- $version
printf 'v%s.%s.%s-%s+%s\n' "$1" "$2" "$(( $3 + 1 ))" "$distance" "$commit"
Loading