From 44d5fa3ce0479fa4d1b5f8c483f19977702811bc Mon Sep 17 00:00:00 2001 From: Xe Iaso Date: Thu, 4 Jun 2026 16:05:37 -0400 Subject: [PATCH] chore: use Go stdlib version stamping (#1665) * chore: use Go stdlib version stamping Signed-off-by: Xe Iaso * chore: spelling Signed-off-by: Xe Iaso --------- Signed-off-by: Xe Iaso --- .github/actions/spelling/allow.txt | 1 + .ko.yaml | 1 - anubis.go | 21 ++++++++++++++++++--- docs/docs/CHANGELOG.md | 1 + yeetfile.js | 4 ++-- 5 files changed, 22 insertions(+), 6 deletions(-) diff --git a/.github/actions/spelling/allow.txt b/.github/actions/spelling/allow.txt index 193c7f3b..2279616f 100644 --- a/.github/actions/spelling/allow.txt +++ b/.github/actions/spelling/allow.txt @@ -44,3 +44,4 @@ xou AWOO firewalls bindhosts +handrolled diff --git a/.ko.yaml b/.ko.yaml index 3be52db6..ddfcccf7 100644 --- a/.ko.yaml +++ b/.ko.yaml @@ -10,4 +10,3 @@ builds: ldflags: - -s -w - -extldflags "-static" - - -X github.com/TecharoHQ/anubis.Version={{.Env.VERSION}} diff --git a/anubis.go b/anubis.go index 853fb244..7793fb4d 100644 --- a/anubis.go +++ b/anubis.go @@ -1,12 +1,27 @@ // Package anubis contains the version number of Anubis. package anubis -import "time" +import ( + "runtime/debug" + "time" +) + +func init() { + bi, ok := debug.ReadBuildInfo() + if !ok { + return + } + + // XXX(Xe): many things in this repo assume that the development version + // of anubis is `devel` and ReadBuildInfo returns `(devel)`. Shim the gap. + if bi.Main.Version != "(devel)" { + Version = bi.Main.Version + } +} // Version is the current version of Anubis. // -// This variable is set at build time using the -X linker flag. If not set, -// it defaults to "devel". +// This is set from the Go module runtime version. var Version = "devel" // CookieName is the name of the cookie that Anubis uses in order to validate diff --git a/docs/docs/CHANGELOG.md b/docs/docs/CHANGELOG.md index e9227961..0647316c 100644 --- a/docs/docs/CHANGELOG.md +++ b/docs/docs/CHANGELOG.md @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Improve error messages and fix broken REDIRECT_DOMAINS link in docs ([#1193](https://github.com/TecharoHQ/anubis/issues/1193)) - Add Bulgarian locale ([#1394](https://github.com/TecharoHQ/anubis/pull/1394)) - Fixed case-sensitivity mismatch in geoipchecker.go +- Use [Go's native version stamping](https://michael.stapelberg.ch/posts/2026-04-05-stamp-it-all-programs-must-report-their-version/) instead of a handrolled variant. - Fix CEL internal errors when iterating `headers`/`query` map wrappers by implementing map iterators for `HTTPHeaders` and `URLValues` ([#1465](https://github.com/TecharoHQ/anubis/pull/1465)). - Enable [metrics serving via TLS](./admin/policies.mdx#tls), including [mutual TLS (mTLS)](./admin/policies.mdx#mtls). - Enable [HTTP basic auth](./admin/policies.mdx#http-basic-authentication) for the metrics server. diff --git a/yeetfile.js b/yeetfile.js index caab0a5e..3b8fcbd5 100644 --- a/yeetfile.js +++ b/yeetfile.js @@ -17,8 +17,8 @@ $`npm run assets`; }, build: ({ bin, etc, systemd, doc }) => { - $`go build -o ${bin}/anubis -ldflags '-s -w -extldflags "-static" -X "github.com/TecharoHQ/anubis.Version=${git.tag()}"' ./cmd/anubis`; - $`go build -o ${bin}/anubis-robots2policy -ldflags '-s -w -extldflags "-static" -X "github.com/TecharoHQ/anubis.Version=${git.tag()}"' ./cmd/robots2policy`; + $`go build -o ${bin}/anubis -ldflags '-s -w -extldflags "-static" ./cmd/anubis`; + $`go build -o ${bin}/anubis-robots2policy -ldflags '-s -w -extldflags "-static"' ./cmd/robots2policy`; file.install("./run/anubis@.service", `${systemd}/anubis@.service`); file.install("./run/default.env", `${etc}/default.env`);