-
Notifications
You must be signed in to change notification settings - Fork 369
/
version.go
73 lines (65 loc) · 2.26 KB
/
version.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Copyright 2019 Antrea Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package version
import (
"fmt"
"runtime"
"github.com/blang/semver"
)
// These variables are set at build-time.
var (
// Must follow the rules in https://semver.org/
// Does not include git / build information
Version = ""
// Empty if git not available
GitSHA = ""
// Can be "dirty", "clean" or empty (if git not available)
GitTreeState = ""
// Can be "unreleased" or "released"; if it is "unreleased" then we add build information to
// the version in GetFullVersion
ReleaseStatus = "unreleased"
)
func GetVersion() semver.Version {
v, _ := semver.Parse(Version[1:])
return v
}
func GetGitSHA() string {
return GitSHA
}
// GetFullVersion returns the version string to be displayed by Antrea binaries. It will look like
// "<major>.<minor>.<patch>" for released versions and "<major>.<minor>.<patch>-<SHA>[.dirty]" for
// unreleased versions.
func GetFullVersion() string {
if Version == "" {
return "UNKNOWN"
}
if ReleaseStatus == "released" {
return Version
}
// add build information
if GitSHA == "" {
return fmt.Sprintf("%s-unknown", Version)
}
if GitTreeState == "dirty" {
return fmt.Sprintf("%s-%s.dirty", Version, GitSHA)
}
return fmt.Sprintf("%s-%s", Version, GitSHA)
}
// GetFullVersionWithRuntimeInfo returns the same version string as GetFullVersion but appends
// "<GOOS>/<GOARCH> <GOVERSION>", where GOOS is the running program's operating system target
// (e.g. darwin, linux), GOARCH is the the running program's architecture target (e.g. amd64), and
// GOVERSION is the Go version used to build the current binary.
func GetFullVersionWithRuntimeInfo() string {
return fmt.Sprintf("%s %s/%s %s", GetFullVersion(), runtime.GOOS, runtime.GOARCH, runtime.Version())
}