gci icon indicating copy to clipboard operation
gci copied to clipboard

fix(cmd): injects version at build time

Open bartoszmajsak opened this issue 11 months ago • 5 comments

A couple of past releases missed aligning hardcoded main.version variable with the current tag. This results in a confusing output of gci --version, where e.g. last release (tagged with v0.13.5) prints 0.13.4.

❯ go install github.com/daixiang0/[email protected]
❯ gci --version
gci version 0.13.4

With this change, main.Version is calculated at build time and injected. Therefore it will always contain the tag it was built from (or devel if it's built from untagged commit).

❯ make build
❯ ./dist/gci -v
gci version devel
❯ git tag v0.13.13
❯ make build
BIN_OUTPUT: dist/gci
❯ ./dist/gci -v
gci version 0.13.13

With the upcoming go1.24 release this information can be obtained from runtime/debug.BuildInfo.Main.Version [1].

This will simplify the process even further.

[1] https://github.com/golang/go/issues/50603#issuecomment-2181188811

Signed-off-by: bartoszmajsak [email protected]

bartoszmajsak avatar Jan 23 '25 16:01 bartoszmajsak

This PR supersedes #218 #224

Fixes #217

bartoszmajsak avatar Jan 23 '25 16:01 bartoszmajsak

If install gci by go install, injecting version is cumbersome.

xchacha20-poly1305 avatar Feb 02 '25 06:02 xchacha20-poly1305

I agree with you. The problem is the go install way.

Several projects faced this issue.

  • https://github.com/editorconfig-checker/editorconfig-checker/issues/220

Some are using strong CI, and PR validation.

Some are using google/release-please that can update version wherever needed.

Please note, I'm not saying your PR is bad, it's unfortunately not enough.

ccoVeille avatar Feb 06 '25 11:02 ccoVeille

Thanks for pointing out go install caveat. Somewhat I tunnel-visioned "release binary" path as the only possible way of consuming gci when working on this PR :)

This way or the other I think the fix is needed, as doing it by hand is not optimal. I can help with this work - just need to know the preferred way for the project.

bartoszmajsak avatar Mar 19 '25 10:03 bartoszmajsak

@bartoszmajsak thanks for great contribution!

Could you find a way to use CI to do release?

daixiang0 avatar Mar 21 '25 09:03 daixiang0