segmentio / golines

A golang formatter that fixes long lines
MIT License
903 stars 56 forks source link

Fix version formatting #118

Closed mckern closed 7 months ago

mckern commented 7 months ago

Hardcoded version numbers are easy to forget to update.

hans-bala-glean commented 2 weeks ago

@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 commented 2 weeks ago

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 commented 2 weeks ago

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 commented 1 week ago

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

mckern commented 1 week ago

@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 commented 1 week ago

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 commented 1 week ago

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.