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 version formatting #118

Merged
merged 2 commits into from
Jan 20, 2024
Merged

Fix version formatting #118

merged 2 commits into from
Jan 20, 2024

Conversation

mckern
Copy link
Contributor

@mckern mckern commented Jan 20, 2024

Hardcoded version numbers are easy to forget to update.

Hardcoded version numbers are easy to forget to update.
@mckern mckern merged commit 22903f7 into master Jan 20, 2024
10 checks passed
@mckern mckern deleted the mckern/fixup-version-numbers branch January 20, 2024 00:51
@hans-bala-glean
Copy link

@mckern I'm trying to understand the new usage of the version flag.

After a global install of golines@latest (0.12.2), this is what golines --version outputs

golines vdev

build information:
	build date: unknown
	git commit ref: none

Same output for v0.12.1. How does one accurately get the tag version?

@telemachus
Copy link
Contributor

telemachus commented Aug 19, 2024

I'm trying to understand the new usage of the version flag.

@hans-bala-glean I get the same results as you, and based on this comment in the code, I am guessing that something about goreleaser has gone wrong.

Ping @mckern

@asaf-erlich
Copy link
Contributor

Just a heads up that Ryan is OOO for this week. but I'll try to remember to bring this up with him when he returns.

@mckern
Copy link
Contributor Author

mckern commented Aug 26, 2024

I'm back and will take a look; are y'all running into this running go install or a tagged release?

@mckern
Copy link
Contributor Author

mckern commented Aug 26, 2024

@telemachus @hans-bala-glean yeah, I'm guessing y'all are using go install and not the artifacts we ship?

This is from the artifacts:

golines_0.12.2_darwin_all $ ./golines --version
golines v0.12.2

build information:
	build date: 2024-01-22T20:57:21Z
	git commit ref: 8c46088b68194b24f8ffd27ad7c6f891a32c867c
golines_0.12.2_linux_amd64 $ ./golines --version
golines v0.12.2

build information:
	build date: 2024-01-22T20:57:21Z
	git commit ref: 8c46088b68194b24f8ffd27ad7c6f891a32c867c
golines_0.12.2_linux_arm64 $ ./golines --version
golines v0.12.2

build information:
	build date: 2024-01-22T20:57:21Z
	git commit ref: 8c46088b68194b24f8ffd27ad7c6f891a32c867c

I am not really sure there's a bug here -- if you're running go install, then you're compiling it yourself and from our perspective that is inherently a dev build.

@telemachus
Copy link
Contributor

Yes, I installed via go install. I understand that you offer precompiled binaries, but go install is a standard way to install go tools. It feels weird to me to say "take our binaries or get no version information." One further reason to support showing versions in go install builds is that (I would think) such builds are much easier to work with in scripted environments like CI. It would be a shame if you couldn't reliably (or easily) get version information back from bug reports in those environments.

@mckern
Copy link
Contributor Author

mckern commented Aug 27, 2024

Running go install is idiomatic and convenient, but it's not actually a good practice or particularly efficient for CI or automation. Hear me out:

  1. You need a complete Go runtime to run go install (yes, you're probably working with a complete Go runtime anyway in CI but the point stands)
  2. go install will then clone an entire source repository down
  3. The entire dependency chain will then be resolved, cloning down each of those repositories
  4. The tool will be compiled using whatever runtime defaults are defined by the toolchain and local environment, producing a statically linked binary intended for distribution

Compared to:

  1. Run wget or curl to retrieve a pre-compiled artifact
  2. Decompress the artifact if needed
    a. Verify the checksum if you're so inclined
  3. Use the same artifact every time

If we're talking about doing something in a scripted environment, yes, go install is one line. It's easier up front, but it's a lot more moving parts under the hood.

But! Here's some numbers instead of rhetoric:

time ( curl -L -O https://github.com/segmentio/golines/releases/download/v0.12.2/golines_0.12.2_linux_arm64.tar.gz &&
tar --strip-components=1 -C /usr/local/bin -xf golines_0.12.2_linux_arm64.tar.gz golines_0.12.2_linux_arm64/golines )
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100 2380k  100 2380k    0     0  2950k      0 --:--:-- --:--:-- --:--:-- 2950k

real	0m0.910s
user	0m0.228s
sys	0m0.041s

Or, including checksumming (since we provide a checksum list):

root@1b6942a65586:/# time ( curl --location --remote-name-all https://github.com/segmentio/golines/releases/download/v0.12.2/{golines_0.12.2_linux_arm64.tar.gz,golines_0.12.2_checksums.txt} &&
sha256sum -c --ignore-missing golines_0.12.2_checksums.txt &&
tar --strip-components=1 -C /usr/local/bin -xf golines_0.12.2_linux_arm64.tar.gz golines_0.12.2_linux_arm64/golines )
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100 2380k  100 2380k    0     0  3307k      0 --:--:-- --:--:-- --:--:-- 11.2M
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100   299  100   299    0     0   1308      0 --:--:-- --:--:-- --:--:--  1308
golines_0.12.2_linux_arm64.tar.gz: OK

real	0m1.063s
user	0m0.212s
sys	0m0.064s

Compared to running go install:

root@fbf505c4c3ef:/go# time ( go install github.com/segmentio/golines@latest )
go: downloading github.com/segmentio/golines v0.12.2
go: downloading github.com/pmezard/go-difflib v1.0.0
go: downloading github.com/dave/dst v0.27.3
go: downloading github.com/x-cray/logrus-prefixed-formatter v0.5.2
go: downloading github.com/fatih/structtag v1.2.0
go: downloading github.com/sirupsen/logrus v1.9.3
go: downloading golang.org/x/term v0.16.0
go: downloading gopkg.in/alecthomas/kingpin.v2 v2.2.6
go: downloading github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d
go: downloading golang.org/x/crypto v0.18.0
go: downloading golang.org/x/tools v0.17.0
go: downloading github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751
go: downloading github.com/alecthomas/units v0.0.0-20231202071711-9a357b53e9c9
go: downloading github.com/mattn/go-colorable v0.1.13
go: downloading golang.org/x/sys v0.16.0
go: downloading github.com/mattn/go-isatty v0.0.20
go: downloading golang.org/x/mod v0.14.0

real	0m7.809s
user	0m24.658s
sys	0m3.809s

So, this is not a bug. If you think the implementation is incomplete or needs refinement and you're so inclined to fix or refine it, then we look forward to reviewing your contribution.

@Panlq
Copy link

Panlq commented Sep 12, 2024

not working!

❯ go install github.com/segmentio/[email protected]                                           ▼
❯ golines --version                                                                         ▼
golines vdev

build information:
        build date: unknown
        git commit ref: none

@Panlq
Copy link

Panlq commented Sep 12, 2024

Running go install is idiomatic and convenient, but it's not actually a good practice or particularly efficient for CI or automation. Hear me out:

  1. You need a complete Go runtime to run go install (yes, you're probably working with a complete Go runtime anyway in CI but the point stands)
  2. go install will then clone an entire source repository down
  3. The entire dependency chain will then be resolved, cloning down each of those repositories
  4. The tool will be compiled using whatever runtime defaults are defined by the toolchain and local environment, producing a statically linked binary intended for distribution

Compared to:

  1. Run wget or curl to retrieve a pre-compiled artifact
  2. Decompress the artifact if needed
    a. Verify the checksum if you're so inclined
  3. Use the same artifact every time

If we're talking about doing something in a scripted environment, yes, go install is one line. It's easier up front, but it's a lot more moving parts under the hood.

But! Here's some numbers instead of rhetoric:

time ( curl -L -O https://github.com/segmentio/golines/releases/download/v0.12.2/golines_0.12.2_linux_arm64.tar.gz &&
tar --strip-components=1 -C /usr/local/bin -xf golines_0.12.2_linux_arm64.tar.gz golines_0.12.2_linux_arm64/golines )
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100 2380k  100 2380k    0     0  2950k      0 --:--:-- --:--:-- --:--:-- 2950k

real	0m0.910s
user	0m0.228s
sys	0m0.041s

Or, including checksumming (since we provide a checksum list):

root@1b6942a65586:/# time ( curl --location --remote-name-all https://github.com/segmentio/golines/releases/download/v0.12.2/{golines_0.12.2_linux_arm64.tar.gz,golines_0.12.2_checksums.txt} &&
sha256sum -c --ignore-missing golines_0.12.2_checksums.txt &&
tar --strip-components=1 -C /usr/local/bin -xf golines_0.12.2_linux_arm64.tar.gz golines_0.12.2_linux_arm64/golines )
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100 2380k  100 2380k    0     0  3307k      0 --:--:-- --:--:-- --:--:-- 11.2M
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100   299  100   299    0     0   1308      0 --:--:-- --:--:-- --:--:--  1308
golines_0.12.2_linux_arm64.tar.gz: OK

real	0m1.063s
user	0m0.212s
sys	0m0.064s

Compared to running go install:

root@fbf505c4c3ef:/go# time ( go install github.com/segmentio/golines@latest )
go: downloading github.com/segmentio/golines v0.12.2
go: downloading github.com/pmezard/go-difflib v1.0.0
go: downloading github.com/dave/dst v0.27.3
go: downloading github.com/x-cray/logrus-prefixed-formatter v0.5.2
go: downloading github.com/fatih/structtag v1.2.0
go: downloading github.com/sirupsen/logrus v1.9.3
go: downloading golang.org/x/term v0.16.0
go: downloading gopkg.in/alecthomas/kingpin.v2 v2.2.6
go: downloading github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d
go: downloading golang.org/x/crypto v0.18.0
go: downloading golang.org/x/tools v0.17.0
go: downloading github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751
go: downloading github.com/alecthomas/units v0.0.0-20231202071711-9a357b53e9c9
go: downloading github.com/mattn/go-colorable v0.1.13
go: downloading golang.org/x/sys v0.16.0
go: downloading github.com/mattn/go-isatty v0.0.20
go: downloading golang.org/x/mod v0.14.0

real	0m7.809s
user	0m24.658s
sys	0m3.809s

So, this is not a bug. If you think the implementation is incomplete or needs refinement and you're so inclined to fix or refine it, then we look forward to reviewing your contribution.

Can refer to the way of gofumpt, generally find the package version number downloaded in gopath to return the specific version number information, there is no need to hard-code

@mckern
Copy link
Contributor Author

mckern commented Oct 1, 2024

@Panlq we do not recommend you use go install to install golines (with or without a version tag). The reason why is already provided above.

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.

5 participants