arp242 / goatcounter

Easy web analytics. No tracking of personal data.
https://www.goatcounter.com
Other
4.54k stars 190 forks source link

Remove the need to inject Version manually #768

Open maruel opened 1 month ago

maruel commented 1 month ago

Use debug.ReadBuildInfo() to generate Version.

Before:

$ CGO_ENABLED=0 go install ./cmd/goatcounter
$ goatcounter version
version=dev; go=go1.23.1; GOOS=linux; GOARCH=amd64; race=false; cgo=false

After:

$ CGO_ENABLED=0 go install ./cmd/goatcounter
$ goatcounter version
version=535cf676f9a3_2024-09-23T18:24:51Z; go=go1.23.1; GOOS=linux; GOARCH=amd64; race=false; cgo=false

After, with a locally modified file:

$ CGO_ENABLED=0 go install ./cmd/goatcounter
$ goatcounter version
version=8ab2fe057181_2024-09-23T18:49:30Z-dev; go=go1.23.1; GOOS=linux; GOARCH=amd64; race=false; cgo=false

Technically this variable should live inside cmd/goatcounter but that would be a more significant refactoring.

arp242 commented 1 month ago

Yeah, all of this was written before that was added to Go.

zli.GetVersion() actually does a lot of this. We can't use it for getting the tag name (I don't want people's existing -X zgo.at/goatcounter/v2.Version= to break), but it can be used for getting the commit hash. It doesn't return the vcs.modified, but the if dirty { Version += "-dev" } isn't that important IMHO.

maruel commented 1 month ago

I personally find the dirty check useful, to know if I had a local uncommitted modification. It doesn't hurt.

maruel commented 1 month ago

Is there a race condition in TestDBUser where the query isn't flushed yet? I double checked the github workflow and it doesn't use the testpg build flag that would enable testing with postgres.