Skip to content

Commit

Permalink
feat: set correctly version on go install (#2516)
Browse files Browse the repository at this point in the history
  • Loading branch information
Codelax authored Sep 19, 2022
1 parent dcc9702 commit d6a83ca
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions cmd/scw/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (

var (
// Version is updated by goreleaser
Version = "v2-dev" // ${BUILD_VERSION:-`git describe --tags --dirty --always`}"
Version = "" // ${BUILD_VERSION:-`git describe --tags --dirty --always`}"

// These are initialized by the build script

Expand Down Expand Up @@ -44,9 +44,20 @@ func cleanup(buildInfo *core.BuildInfo) {
}
}

func buildVersion() string {
if Version == "" {
buildInfos, ok := debug.ReadBuildInfo()
if ok && buildInfos.Main.Version != "(devel)" {
return buildInfos.Main.Version
}
return "v2+dev"
}
return Version
}

func main() {
buildInfo := &core.BuildInfo{
Version: version.Must(version.NewSemver(Version)), // panic when version does not respect semantic versionning
Version: version.Must(version.NewSemver(buildVersion())), // panic when version does not respect semantic versioning
BuildDate: BuildDate,
GoVersion: GoVersion,
GitBranch: GitBranch,
Expand Down

0 comments on commit d6a83ca

Please sign in to comment.