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
binary: psu
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:
- CGO_ENABLED=0
goos:

View File

@ -7,13 +7,8 @@ import (
)
var (
// This is the current version of the client
CurrentVersion = Version{
Major: 0,
Minor: 1,
Patch: 1,
Suffix: "",
}
// This is the current version of the client. It is set by goreleaser.
version string
// The program name
programName = "Portainer Stack Utils"
@ -25,32 +20,7 @@ var (
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 {
version := "v" + CurrentVersion.String()
if commitHash != "" {
version += "-" + strings.ToUpper(commitHash)
}