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(cmd): injects version at build time #226

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bartoszmajsak
Copy link

@bartoszmajsak bartoszmajsak commented Jan 23, 2025

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] golang/go#50603 (comment)

Signed-off-by: bartoszmajsak [email protected]

@bartoszmajsak
Copy link
Author

bartoszmajsak commented Jan 23, 2025

This PR supersedes #218 #224

Fixes #217

@bartoszmajsak bartoszmajsak force-pushed the fix-version branch 2 times, most recently from a8472d2 to 44863bb Compare January 23, 2025 16:24
A couple of past releases missed aligning hardcoded `main.version` variable
with the current tag. This results in confusing output of `gci --version`,
where e.g. last release (tagged with `v0.13.5`) prints `0.13.4`.

```shell
❯ 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 that it was
built from (or `devel` if it's built from untagged commit).

```shell
❯ 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] golang/go#50603 (comment)

Signed-off-by: bartoszmajsak <[email protected]>
@xchacha20-poly1305
Copy link

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

@ccoVeille
Copy link
Contributor

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

Several projects faced this issue.

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.

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.

3 participants