|
|
@ -15,7 +15,9 @@ import (
|
|
|
|
// using the -ldflags during compilation.
|
|
|
|
// using the -ldflags during compilation.
|
|
|
|
var Commit string
|
|
|
|
var Commit string
|
|
|
|
|
|
|
|
|
|
|
|
// semanticAlphabet
|
|
|
|
// semanticAlphabet is the allowed characters from the semantic versioning
|
|
|
|
|
|
|
|
// guidelines for pre-release version and build metadata strings. In particular
|
|
|
|
|
|
|
|
// they MUST only contain characters in semanticAlphabet.
|
|
|
|
const semanticAlphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-"
|
|
|
|
const semanticAlphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-"
|
|
|
|
|
|
|
|
|
|
|
|
// These constants define the application version and follow the semantic
|
|
|
|
// These constants define the application version and follow the semantic
|
|
|
@ -67,7 +69,7 @@ func semanticVersion() string {
|
|
|
|
// by the semantic versioning spec is automatically appended and should
|
|
|
|
// by the semantic versioning spec is automatically appended and should
|
|
|
|
// not be contained in the pre-release string. The pre-release version
|
|
|
|
// not be contained in the pre-release string. The pre-release version
|
|
|
|
// is not appended if it contains invalid characters.
|
|
|
|
// is not appended if it contains invalid characters.
|
|
|
|
preRelease := normalizeVerString(appPreRelease)
|
|
|
|
preRelease := normalizeVerString(appPreRelease, semanticAlphabet)
|
|
|
|
if preRelease != "" {
|
|
|
|
if preRelease != "" {
|
|
|
|
version = fmt.Sprintf("%s-%s", version, preRelease)
|
|
|
|
version = fmt.Sprintf("%s-%s", version, preRelease)
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -76,13 +78,11 @@ func semanticVersion() string {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// normalizeVerString returns the passed string stripped of all characters
|
|
|
|
// normalizeVerString returns the passed string stripped of all characters
|
|
|
|
// which are not valid according to the semantic versioning guidelines for
|
|
|
|
// which are not valid according to the given alphabet.
|
|
|
|
// pre-release version and build metadata strings. In particular they MUST
|
|
|
|
func normalizeVerString(str, alphabet string) string {
|
|
|
|
// only contain characters in semanticAlphabet.
|
|
|
|
|
|
|
|
func normalizeVerString(str string) string {
|
|
|
|
|
|
|
|
var result bytes.Buffer
|
|
|
|
var result bytes.Buffer
|
|
|
|
for _, r := range str {
|
|
|
|
for _, r := range str {
|
|
|
|
if strings.ContainsRune(semanticAlphabet, r) {
|
|
|
|
if strings.ContainsRune(alphabet, r) {
|
|
|
|
result.WriteRune(r)
|
|
|
|
result.WriteRune(r)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|