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

cmd/skipper: fix version and commit for go install #2954

Merged
merged 1 commit into from Feb 23, 2024

Conversation

AlexanderYastrebov
Copy link
Member

When skipper is installed via go install it has empty version and commit values:

~$ go install github.com/zalando/skipper/cmd/skipper@latest
go: downloading github.com/zalando/skipper v0.21.2
~$ skipper -version
Skipper version  (commit: , runtime: go1.22.0)

Current build process of binaries specifies version and commit via -ldflags.

This change uses debug buildinfo to get version and commit if they are not specified by -ldflags which is compatible with the current build process but should also work for go install case.

If this change fixes go install case (which can only be tested after package version is published) then we can add the same snippet to other binaries and get rid of COMMIT_HASH ldflag.

We can not get rid of -ldflags fully though because go build does not stamp version (see golang/go#50603).

When skipper is installed via `go install` it has empty version and
commit values:
```
~$ go install github.com/zalando/skipper/cmd/skipper@latest
go: downloading github.com/zalando/skipper v0.21.2
~$ skipper -version
Skipper version  (commit: , runtime: go1.22.0)
```

Current build process of binaries specifies version and commit via `-ldflags`.

This change uses debug buildinfo to get version and commit if they are
not specified by `-ldflags` which is compatible with the current build process
but should also work for `go install` case.

If this change fixes `go install` case (which can only be tested after
package version is published) then we can add the same snippet
to other binaries and get rid of COMMIT_HASH ldflag.

We can not get rid of `-ldflags` fully though because `go build` does
not stamp version (see golang/go#50603).

Signed-off-by: Alexander Yastrebov <alexander.yastrebov@zalando.de>
@AlexanderYastrebov AlexanderYastrebov added the minor no risk changes, for example new filters label Feb 23, 2024
func init() {
if info, ok := debug.ReadBuildInfo(); ok {
if version == "" {
version = info.Main.Version
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

go install should populate this from the package version that matches git tag.

@szuecs
Copy link
Member

szuecs commented Feb 23, 2024

👍

@szuecs
Copy link
Member

szuecs commented Feb 23, 2024

let's try :)

@RomanZavodskikh
Copy link
Member

👍

@AlexanderYastrebov AlexanderYastrebov merged commit 8c03dfb into master Feb 23, 2024
14 checks passed
@AlexanderYastrebov AlexanderYastrebov deleted the buildinfo branch February 23, 2024 13:40
@AlexanderYastrebov
Copy link
Member Author

The version is set now but commit is not

~$ rm $(which skipper)
~$ go install github.com/zalando/skipper/cmd/skipper@latest
~$ skipper -version
Skipper version v0.21.3 (commit: , runtime: go1.22.0)

AlexanderYastrebov added a commit that referenced this pull request Feb 23, 2024
Binary installed via `go install github.com/zalando/skipper/cmd/skipper@latest`
does not contain `vcs.revision`, see golang/go#65904

Followup on #2954

Signed-off-by: Alexander Yastrebov <alexander.yastrebov@zalando.de>
AlexanderYastrebov added a commit that referenced this pull request Feb 23, 2024
Binary installed via `go install github.com/zalando/skipper/cmd/skipper@latest`
does not contain `vcs.revision`, see golang/go#65904

Followup on #2954

Signed-off-by: Alexander Yastrebov <alexander.yastrebov@zalando.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
minor no risk changes, for example new filters
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants