Skip to content

Commit

Permalink
Fix reported version in --version output (#87)
Browse files Browse the repository at this point in the history
We were not using gorleaser correctly before. First it was updating a
set of values that do not exist in our dep tree and isn't used. Secondly
it wasn't a setting a very useful value `.Version` is only the commit
(with `-next` appended if we aren't building off of the tag). `.Summary`
gives equivalent output if building off of the tag but additional
details if not (example below). Finally, I got rid of the hard
coded/outdated version number and replaced with "devel" so that its less
misleading/confusing.

Here's an example of how things will look:
```
[13:53:26]-[~/p/g/m/vogelkop]-[manny@c3mv18nix]
git describe --tags 
v0.3.1-3-g8311843
[13:53:32]-[~/p/g/m/vogelkop]-[manny@c3mv18nix]
goreleaser build --snapshot --clean
  • starting build...
  • loading                                          path=.goreleaser.yml
  • skipping validate...
  • loading environment variables
  • getting and validating git state
    • git state                                      commit=8311843274235ab157c22ed21daeca54b83f27fd branch=fix-reported-version current_tag=v0.3.1 previous_tag=v0.3.0 dirty=false
    • pipe skipped                                   reason=disabled during snapshot mode
  • parsing tag
  • setting defaults
  • snapshotting
    • building snapshot...                           version=v0.3.1-next
  • running before hooks
    • running                                        hook=go mod download
  • checking distribution directory
    • cleaning dist
  • setting up metadata
  • storing release metadata
    • writing                                        file=dist/metadata.json
  • loading go mod information
  • build prerequisites
  • writing effective config file
    • writing                                        config=dist/config.yaml
  • building binaries
    • building                                       binary=dist/vogelkop_linux_arm64/vogelkop
    • building                                       binary=dist/vogelkop_linux_amd64_v1/vogelkop
  • storing artifacts metadata
    • writing                                        file=dist/artifacts.json
  • build succeeded after 0s
  • thanks for using goreleaser!
[13:53:34]-[~/p/g/m/vogelkop]-[manny@c3mv18nix]
./dist/vogelkop_linux_amd64_v1/vogelkop --version
vogelkop version v0.3.1-3-g8311843
[13:53:46]-[~/p/g/m/vogelkop]-[manny@c3mv18nix]
git tag -m v0.3.424242 v0.3.424242
[13:53:50]-[~/p/g/m/vogelkop]-[manny@c3mv18nix]
goreleaser build --snapshot --clean
  • starting build...
  • loading                                          path=.goreleaser.yml
  • skipping validate...
  • loading environment variables
  • getting and validating git state
    • git state                                      commit=8311843274235ab157c22ed21daeca54b83f27fd branch=fix-reported-version current_tag=v0.3.424242 previous_tag=v0.3.1 dirty=false
    • pipe skipped                                   reason=disabled during snapshot mode
  • parsing tag
  • setting defaults
  • snapshotting
    • building snapshot...                           version=v0.3.424242-next
  • running before hooks
    • running                                        hook=go mod download
  • checking distribution directory
    • cleaning dist
  • setting up metadata
  • storing release metadata
    • writing                                        file=dist/metadata.json
  • loading go mod information
  • build prerequisites
  • writing effective config file
    • writing                                        config=dist/config.yaml
  • building binaries
    • building                                       binary=dist/vogelkop_linux_arm64/vogelkop
    • building                                       binary=dist/vogelkop_linux_amd64_v1/vogelkop
  • storing artifacts metadata
    • writing                                        file=dist/artifacts.json
  • build succeeded after 0s
  • thanks for using goreleaser!
[13:53:52]-[~/p/g/m/vogelkop]-[manny@c3mv18nix]
./dist/vogelkop_linux_amd64_v1/vogelkop --version
vogelkop version v0.3.424242
```
  • Loading branch information
mmlb committed Jun 19, 2024
2 parents 452ef8e + b9e3497 commit 21126b7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
8 changes: 2 additions & 6 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ builds:
- "7"
ldflags:
- -s -w
- -X github.com/metal-toolbox/version.appName={{.ProjectName}}
- -X github.com/metal-toolbox/version.version={{.Version}}
- -X github.com/metal-toolbox/version.commit={{.Commit}}
- -X github.com/metal-toolbox/version.date={{.Date}}
- -X github.com/metal-toolbox/version.builtBy=goreleaser
- -X github.com/metal-toolbox/vogelkop/internal/version.version={{.Summary}}

dockers:
- use: buildx
Expand All @@ -36,7 +32,7 @@ dockers:
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.title={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- "--label=org.opencontainers.image.version={{.Summary}}"
extra_files:
- dependencies/.gitignore
- use: buildx
Expand Down
2 changes: 1 addition & 1 deletion internal/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package version

var (
name = "vogelkop"
version = "0.2.5"
version = "devel"
)

func Name() string {
Expand Down

0 comments on commit 21126b7

Please sign in to comment.