chore: inject the version into main instead of a module path

The `-X` target carried the full module path in both the Makefile and
.goreleaser.yaml, so any change to the module path silently turned the
injection into a no-op and shipped a binary reporting "dev". Target
`main.version` instead, which no longer names the module, and fail
`make checks` when the injection stops taking effect.

Assisted-by: Codet:GPT-5.1-Codex
This commit is contained in:
Lunny Xiao
2026-08-07 11:14:30 -07:00
parent 9dd9204937
commit 3ea5134ac6
5 changed files with 42 additions and 4 deletions
+14
View File
@@ -11,3 +11,17 @@ func TestVersion(t *testing.T) {
t.Errorf("Version() = %q, want %q", got, version)
}
}
func TestSetVersion(t *testing.T) {
t.Cleanup(func() { version = "dev" })
SetVersion("v1.2.3")
if got := Version(); got != "v1.2.3" {
t.Errorf("Version() = %q, want %q", got, "v1.2.3")
}
SetVersion("")
if got := Version(); got != "v1.2.3" {
t.Errorf("Version() = %q, want %q", got, "v1.2.3")
}
}