Stamp the build version into the binary (closes #253)
All checks were successful
check / check (push) Successful in 3m12s

This commit was merged in pull request #260.
This commit is contained in:
2026-08-24 03:15:20 +02:00
parent 032f265d69
commit ee2276a912
9 changed files with 573 additions and 14 deletions

View File

@@ -1,8 +1,26 @@
.PHONY: bootstrap setup assets test lint fmt fmt-check check build run dev deps docker clean hooks css
.PHONY: bootstrap setup assets test lint fmt fmt-check check build run dev deps docker clean hooks css version
# Default target
.DEFAULT_GOAL := check
# Version stamped into the binary. Derived from git by script/version;
# override it (`make build VERSION=v1.2.3`) where git metadata is
# unavailable, which is how the Dockerfile passes its build arg in.
VERSION ?= $(shell script/version)
# An empty override (`make build VERSION=`, or a `--build-arg VERSION=`
# landing on the Dockerfile's `make build VERSION="$VERSION"`) means unset,
# exactly as it does in script/version -- stamping "" would leave the binary
# reporting no version and the footer back on its "dev" fallback. `override`
# is required: a plain assignment loses to the command-line definition it
# exists to correct.
override VERSION := $(or $(strip $(VERSION)),$(shell script/version))
# Extra linker flags for the build target. The static relink in the
# Dockerfile adds -extldflags here rather than passing its own -ldflags,
# so composing flags cannot drop the version stamp.
GO_LDFLAGS ?=
bootstrap:
@script/bootstrap
@@ -28,7 +46,7 @@ check:
@script/check
build:
go build -o bin/webhooker ./cmd/webhooker
go build -ldflags '$(strip -X main.version=$(VERSION) $(GO_LDFLAGS))' -o bin/webhooker ./cmd/webhooker
run: build
./bin/webhooker
@@ -40,6 +58,9 @@ deps:
go mod download
go mod tidy
version:
@echo $(VERSION)
docker:
@script/docker