fix(cmd): injects version at build time
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]
This PR supersedes #218 #224
Fixes #217
If install gci by go install, injecting version is cumbersome.
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.
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 thanks for great contribution!
Could you find a way to use CI to do release?