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

Set all version flags at build time so they have correct values #593

Merged
merged 2 commits into from
Oct 15, 2021

Conversation

dvejmz
Copy link
Contributor

@dvejmz dvejmz commented Oct 14, 2021

Set all version flags at build time so they have correct values. This includes:

  • The current (latest git tag)
  • The current git commit
  • Build date
  • Where the build occurred (local build via Makefile or in CI via GoReleaser)

Since some of the information on display is long-winded, I decided to display each version flag in a new line for slightly better readability. If you'd like different wording or formatting using, let me know.

Example:

$ ./revive -version
Version:	v1.1.2-10-ga7e6f59
Commit:		a7e6f596f0f9b0a56dafa977e99630171bb0e84c
Built		2021-10-14 20:33 UTC by Makefile

This closes #560.

@dvejmz dvejmz changed the title Bugfix/560 print version Set all version flags at build time so they have correct values Oct 14, 2021
@chavacava chavacava merged commit b331445 into mgechev:master Oct 15, 2021
@chavacava
Copy link
Collaborator

Hi @dvejmz, thanks for the PR!

@invidian
Copy link

This PR does not fix #560

$ docker run -it golang:1.17-alpine sh -c 'go install github.com/mgechev/revive@master && revive -version'
go: downloading github.com/mgechev/revive v1.1.3-0.20211015083515-b331445a16a4
go: downloading github.com/mgechev/dots v0.0.0-20210922191527-e955255bf517
go: downloading github.com/fatih/color v1.13.0
go: downloading github.com/mitchellh/go-homedir v1.1.0
go: downloading golang.org/x/tools v0.1.7
go: downloading github.com/BurntSushi/toml v0.4.1
go: downloading github.com/chavacava/garif v0.0.0-20210405164556-e8a0a408d6af
go: downloading github.com/olekukonko/tablewriter v0.0.5
go: downloading github.com/fatih/structtag v1.2.0
go: downloading github.com/mattn/go-isatty v0.0.14
go: downloading github.com/mattn/go-colorable v0.1.9
go: downloading github.com/mattn/go-runewidth v0.0.9
go: downloading golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e
Version:        dev
Commit:         none
Built           unknown by unknown

@dvejmz
Copy link
Contributor Author

dvejmz commented Oct 15, 2021

Hi @invidian, I can see why that happened. This PR should ensure the version information is included in the binary when built via the Makefile, either manually or via CI. I didn't account for the go install scenario. I'll take a look at how we can make this work for this use case later today.

@invidian
Copy link

Sure. Maybe have a look at flexkube/libflexkube@c9ee296, it can be done this way.

@jefersonf
Copy link
Contributor

The goreleaser tool only sets the ldflags when building the assets. To get the same result using go install it would be necessary to manually set them up. Which doesn't make sense.

As mentioned in #560, we can get some information using the debug.ReadBuildInfo() function, however it is not possible to retrieve the other flags besides the version.

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.

Ambigous version information printed when installing with 'go install'
4 participants