Skip to content

attempt to handle --version even in untagged builds #161

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

Merged
merged 1 commit into from
Nov 19, 2024
Merged

attempt to handle --version even in untagged builds #161

merged 1 commit into from
Nov 19, 2024

Conversation

n-oden
Copy link
Contributor

@n-oden n-oden commented Jul 10, 2024

This addresses #155

If we are installed via go-install rather than downloading a tagged binary from github, the Tag etc variables will all be empty, and therefore the --version flag is diked out. But there is a way around this!

If the version info is not filled in via build-time flags, use debug.BuildInfo to introspect as much information as we can out of the module metadata:

$ go install github.com/odenio/goimports-reviser/[email protected]
go: downloading github.com/odenio/goimports-reviser/v3 v3.6.6-pre5

$ ~/go/bin/goimports-reviser --version
version: 3.6.6-pre5
built with: go1.22.4
tag: v3.6.6-pre5
commit: n/a
source: github.com/odenio/goimports-reviser/v3

Additionally, add a --version-only flag that prints only the version string itself, handy for use in shell pipelines. Can be used on its own or in combination with the --version flag:

$ ~/go/bin/goimports-reviser --version-only
3.6.6-pre5

@ccoVeille
Copy link

ccoVeille commented Jul 10, 2024

I would love that!

There are so many tools with the frustrating "Dev" version

@n-oden n-oden requested a review from ccoVeille July 12, 2024 14:56
@n-oden n-oden requested a review from ccoVeille July 12, 2024 17:23
@n-oden n-oden requested a review from ccoVeille July 12, 2024 21:44
If we are installed via `go-install` rather than downloading a
tagged binary from github, the `Tag` etc variables will all be
empty, and therefore the `--version` flag is diked out. But there
is a way around this!

If the version info is not filled in via build-time flags, use
`debug.BuildInfo` to introspect as much information as we can
out of the module metadata:

```
$ go install github.com/odenio/goimports-reviser/[email protected]
go: downloading github.com/odenio/goimports-reviser/v3 v3.6.6-pre5

$ ~/go/bin/goimports-reviser --version
version: 3.6.6-pre5
built with: go1.22.4
tag: v3.6.6-pre5
commit: n/a
source: github.com/odenio/goimports-reviser/v3
```

Additionally, add a `--version-only` flag that prints only the version
string itself, handy for use in shell pipelines. Can be used on its own
or in combination with the `--version` flag:

```
$ ./go/bin/goimports-reviser --version-only
3.6.6-pre5
```
@n-oden
Copy link
Contributor Author

n-oden commented Jul 15, 2024

Thanks for the approval! Can someone merge this? I cannot.

@ccoVeille
Copy link

I'm a random Gopher. You will have to wait for a maintainer review

@n-oden
Copy link
Contributor Author

n-oden commented Aug 13, 2024

For the record if anyone would like to kick the tires on this, #160 and #159, I've made a build containing all three patches available as github.com/odenio/goimports-reviser/[email protected].

I don't intend to maintain a long-lived fork here, but I understand that the maintainer may have bigger fish to fry at the moment, residing in Ukraine.

@alexandear
Copy link
Contributor

@incu6us would you mind reviewing this?

@incu6us incu6us merged commit da1c44e into incu6us:master Nov 19, 2024
9 checks passed
@n-oden n-oden deleted the version-handling branch November 20, 2024 21:09
@n-oden
Copy link
Contributor Author

n-oden commented Nov 20, 2024

Thank you!

@incu6us
Copy link
Owner

incu6us commented Nov 21, 2024

Thank you!

Thank you for your contribution!

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.

4 participants