-
Notifications
You must be signed in to change notification settings - Fork 65
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
Fix #108: Add version command #146
Conversation
Signed-off-by: Toby Hodges <[email protected]>
Signed-off-by: Toby Hodges <[email protected]>
Signed-off-by: Toby Hodges <[email protected]>
Signed-off-by: Toby Hodges <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this PR!
For the version command, the most relevant time and place is when executed at end users' local machines. So we need to make sure version information is propagated to released binaries.
There's a bit of complication here. We use go releaser to do the bulk of the work to cut releases, and It supports importing pre-built binaries to the workflow. e.g. Use make to build, then use built binaries for the rest of the steps of cutting a new release. This is a perfect use case for us.
Unfortunately, this is a paid feature and we currently do not pay for it.
This means we need to put these information in the go releaser configuration as well. https://github.com/cnoe-io/idpbuilder/blob/main/.goreleaser.yaml
It looks like it does have support for it ld flags. https://goreleaser.com/customization/builds/
I know it's a bit complicated. I would love for us to have a paid version of go releaser so we don't have to do this.
No worries! I'll update the goreleaser as well and see if I can test that out locally as well. |
Signed-off-by: Toby Hodges <[email protected]>
Signed-off-by: Toby Hodges <[email protected]>
Signed-off-by: Toby Hodges <[email protected]>
Signed-off-by: Toby Hodges <[email protected]>
087ec36
to
82e8af9
Compare
Signed-off-by: Toby Hodges <[email protected]>
goVersion = runtime.Version() | ||
goOs = runtime.GOOS | ||
goArch = runtime.GOARCH |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using the runtime
package here like Kind does
@@ -1,10 +1,15 @@ | |||
LD_FLAGS=-ldflags " \ | |||
-X github.com/cnoe-io/idpbuilder/pkg/cmd/version.idpbuilderVersion=$(shell git describe --always --tags --dirty --broken) \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--always
flag means that this won't fail with forks/local dev and not output anything for idpbuilderVersion
if there are no local tags.
Signed-off-by: Toby Hodges <[email protected]>
ldflags: | ||
- -X github.com/cnoe-io/idpbuilder/pkg/cmd/version.idpbuilderVersion={{ .Version }} | ||
- -X github.com/cnoe-io/idpbuilder/pkg/cmd/version.gitCommit={{ .FullCommit }} | ||
- -X github.com/cnoe-io/idpbuilder/pkg/cmd/version.buildDate={{ .CommitDate }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using the Template Fields provided by Goreleaser, for consistency.
@nabuskey Ready for review. locally, this works really well, and I believe this will work well in CI. I don't know if I can add tests for this command effectively... do you know where those might go if I could add them? or if there are any tests for the |
2e5fe8d
to
4380373
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Awesome work @hodgiwabi. Thank you very much.
Adds a simple version command using ldflags on build and
runtime
package at runtime.