Skip to content

Commit

Permalink
Fix invalid version string for precompiled builds
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan-berkner-tilotech committed Jan 30, 2023
1 parent 301c1cf commit ebf1ebb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ builds:
main: ./
flags:
- -trimpath
ldflags: -s -w -X main.version={{.Version}} -X main.commit={{.ShortCommit}} -X main.date={{.Date}}
ldflags: -s -w -X main.version={{.Version}}

archives:
- format: tar.gz
Expand Down
8 changes: 7 additions & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,18 @@ func init() {
rootCmd.AddCommand(versionCmd)
}

// Version will hold the actual build version from main for precompiled binaries.
var Version = ""

func printVersion() error {
buildInfo, ok := debug.ReadBuildInfo()
if !ok {
return fmt.Errorf("could not read BuildInfo")
}
version := buildInfo.Main.Version
version := Version
if version == "" {
version = buildInfo.Main.Version
}
if version == "" {
version = "development"
}
Expand Down
3 changes: 3 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package main

import "github.com/tilotech/batch-graphql/cmd"

var version = ""

func main() {
cmd.Version = version
cmd.Execute()
}

0 comments on commit ebf1ebb

Please sign in to comment.