Melkeydev / go-blueprint

Go-blueprint allows users to spin up a quick Go project using a popular framework
https://docs.go-blueprint.dev/
MIT License
5.9k stars 333 forks source link

fix: version command #135

Closed limesten closed 11 months ago

limesten commented 1 year ago

By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.

Problem/Feature

the command go-blueprint version works fine when downloading the pre-build binary from a release. However, if doing go install github.com/melkeydev/go-blueprint@latest it seems to result in an empty GoBlueprintVersion string.

Description of Changes:

lost a few hairs on my head investigating this but:

Checklist

limesten commented 1 year ago

I am trying out this branch and I am getting the following:

  ~/Documents/Personal/Go/test                                                                                                                                                             
❯ go-blueprint version
Go Blueprint CLI version (devel)

Is this expected? I am unsure what i did

For the info.Main.Version to embed the version from the git tag it needs to be installed like: go install github.com/melkeydev/go-blueprint@latest (or with the specific version instead of latest)

If we install like that and then run go version -m go-blueprint on the binary in the bin folder we get:

image



However, if we run go install locally with the source code we will get (devel)

image
muandane commented 1 year ago

i'm a bit confused to why it's not working also at build i tested the build locally

image
limesten commented 1 year ago

Thoughts on these changes?

Also for additional info about getting (devel) from local builds with debug.ReadBuildInfo() there are these related issues on the golang repo: https://github.com/golang/go/issues/29228 https://github.com/golang/go/issues/50603

Melkeydev commented 11 months ago

@limesten I am still investigating this but it seems it still does not work image

limesten commented 11 months ago

@limesten I am still investigating this but it seems it still does not work image

I assume you are checking out the pr and then running go install. I've not found a good way to include the version info in this case.

It will work if:

1) you make a release with goreleaser (for example goreleaser build --single-target --skip-validate --clean as a local test release) (or manually enter a ldflag when running go build as @muandane did)

2) you install like this: go install github.com/melkeydev/go-blueprint@latest or @v.0.4.1 etc In this case the part after the @ is what gets added to the buildinfo so it will be accessible from the version command

The weird thing with 2) is that u cant't rly test it locally beforehand (as far as I can see at least) cuz this PR first needs to be included in a release so we can install it with go install github.com/melkeydev/go-blueprint@latest 😅 Hope that makes sense

Ujstor commented 11 months ago

@Melkeydev This is working. I created a test repo, pushed the tag, the build passed and the version was correct. LGTM Screenshot from 2023-12-19 07-22-20