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

Fix #108: Add version command #146

Merged
merged 10 commits into from
Feb 15, 2024
Merged

Conversation

hodgiwabi
Copy link
Contributor

@hodgiwabi hodgiwabi commented Feb 9, 2024

Adds a simple version command using ldflags on build and runtime package at runtime.

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]>
@hodgiwabi hodgiwabi mentioned this pull request Feb 9, 2024
Copy link
Collaborator

@nabuskey nabuskey left a 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.

@nabuskey nabuskey linked an issue Feb 9, 2024 that may be closed by this pull request
@hodgiwabi
Copy link
Contributor Author

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]>
@hodgiwabi hodgiwabi force-pushed the 108-add-version-command branch from 087ec36 to 82e8af9 Compare February 14, 2024 00:26
Signed-off-by: Toby Hodges <[email protected]>
Comment on lines +30 to +32
goVersion = runtime.Version()
goOs = runtime.GOOS
goArch = runtime.GOARCH
Copy link
Contributor Author

@hodgiwabi hodgiwabi Feb 14, 2024

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) \
Copy link
Contributor Author

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.

Comment on lines +15 to +18
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 }}
Copy link
Contributor Author

@hodgiwabi hodgiwabi Feb 14, 2024

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.

@hodgiwabi
Copy link
Contributor Author

hodgiwabi commented Feb 14, 2024

@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 create command?

local test results:
image

@hodgiwabi hodgiwabi force-pushed the 108-add-version-command branch from 2e5fe8d to 4380373 Compare February 14, 2024 01:10
Copy link
Collaborator

@nabuskey nabuskey left a 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.

@nabuskey nabuskey merged commit d3a24e2 into cnoe-io:main Feb 15, 2024
2 of 3 checks passed
@hodgiwabi hodgiwabi deleted the 108-add-version-command branch March 1, 2024 22:34
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.

add a Version command
2 participants