lucagrulla / cw

The best way to tail AWS CloudWatch Logs from your terminal
https://www.lucagrulla.com/cw
Apache License 2.0
791 stars 59 forks source link

Use ldflags to overwrite hard-coded version at build time #257

Closed kevinmichaelchen closed 1 year ago

kevinmichaelchen commented 1 year ago

I'm building a Tea package for this project here: https://github.com/teaxyz/pantry/pull/3085

Currently, cw --version reports an old version.

lucagrulla commented 1 year ago

Hi @kevinmichaelchen ,

I'm unsure about the issue you're flagging. Can you expand?

cw is built using ldflags. The current version reported from my installation is 4.1.3; that is the latest one.

kevinmichaelchen commented 1 year ago

Hey @lucagrulla --

I'm seeing the latest release as v4.1.3, but in the code I'm seeing 4.1.1 hard-coded.

lucagrulla commented 1 year ago

The code value is a placeholder, but the actual version is injected at build time with ldflags.

lucagrulla commented 1 year ago

I appreciate it might be confusing. I will set the variable to ''.

kevinmichaelchen commented 1 year ago

What is the name of the ldflag that overrides the version?

I couldn't find anything in this repo.

kevinmichaelchen commented 1 year ago

Ah, sorry, -X main.version was what I was looking for.

Thanks for bearing with me. I'm still learning ldflags.

lucagrulla commented 1 year ago

I'm not sure I understand your question.

ldflags can be passed at linking time to go build: go build -ldflags="-X main.version=x.y.z"

where x.y.z is the version you want to inject

cw uses goreleaser to create all the packages. goreleaser will inject the current git tag in the version variable. https://goreleaser.com/cookbooks/using-main.version/