Move version setting to goreleaser

This commit is contained in:
Juan Carlos Mejías Rodríguez 2019-08-09 01:28:31 -04:00
parent 535eada8ab
commit ea30e28261
2 changed files with 3 additions and 33 deletions

View File

@ -8,7 +8,7 @@ builds:
- main: main.go - main: main.go
binary: psu binary: psu
ldflags: ldflags:
- -X github.com/greenled/portainer-stack-utils/common.commitHash={{ .ShortCommit }} -X github.com/greenled/portainer-stack-utils/common.buildDate={{ .Date }} - -X github.com/greenled/portainer-stack-utils/common.version={{ .Version }} -X github.com/greenled/portainer-stack-utils/common.commitHash={{ .ShortCommit }} -X github.com/greenled/portainer-stack-utils/common.buildDate={{ .Date }}
env: env:
- CGO_ENABLED=0 - CGO_ENABLED=0
goos: goos:

View File

@ -7,13 +7,8 @@ import (
) )
var ( var (
// This is the current version of the client // This is the current version of the client. It is set by goreleaser.
CurrentVersion = Version{ version string
Major: 0,
Minor: 1,
Patch: 1,
Suffix: "",
}
// The program name // The program name
programName = "Portainer Stack Utils" programName = "Portainer Stack Utils"
@ -25,32 +20,7 @@ var (
buildDate string buildDate string
) )
type Version struct {
// Major version
Major uint32
// Minor version
Minor uint32
// Patch version
Patch uint32
// Suffix used in version string
// Will be blank for release versions
Suffix string
}
func (v Version) String() string {
if v.Suffix != "" {
return fmt.Sprintf("%d.%d.%d-%s", v.Major, v.Minor, v.Patch, v.Suffix)
} else {
return fmt.Sprintf("%d.%d.%d", v.Major, v.Minor, v.Patch)
}
}
func BuildVersionString() string { func BuildVersionString() string {
version := "v" + CurrentVersion.String()
if commitHash != "" { if commitHash != "" {
version += "-" + strings.ToUpper(commitHash) version += "-" + strings.ToUpper(commitHash)
} }