Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the need to inject Version manually #768

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

maruel
Copy link

@maruel maruel commented Sep 23, 2024

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.

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.
@maruel maruel changed the title Simplify the building process for end users. Remove the need to inject Version manually Sep 23, 2024
@arp242
Copy link
Owner

arp242 commented Sep 25, 2024

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.

context.go Outdated Show resolved Hide resolved
context.go Outdated Show resolved Hide resolved
@maruel
Copy link
Author

maruel commented Sep 27, 2024

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

@maruel
Copy link
Author

maruel commented Sep 30, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants