Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

main: allow version metadata to be set #945

Merged
merged 1 commit into from
Jun 10, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions version.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package main

import (
"fmt"

goversion "github.com/hashicorp/go-version"
)

Expand All @@ -12,7 +10,10 @@ var version = "0.0.0"
// A pre-release marker for the version. If this is "" (empty string)
// then it means that it is a final release. Otherwise, this is a pre-release
// such as "dev" (in development), "beta", "rc1", etc.
var prerelease = "dev"
var versionPrerelease = "dev"

// Version (build) metadata, such as homebrew
var versionMetadata = ""

func init() {
// Verify that the version is proper semantic version, which should always be the case.
Expand All @@ -24,8 +25,14 @@ func init() {

// VersionString returns the complete version string, including prerelease
func VersionString() string {
if prerelease != "" {
return fmt.Sprintf("%s-%s", version, prerelease)
v := version
if versionPrerelease != "" {
v += "-" + versionPrerelease
}
return version

if versionMetadata != "" {
v += "+" + versionMetadata
}

return v
}