-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathversion.go
63 lines (53 loc) · 1.54 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
// SPDX-License-Identifier: Apache-2.0
package version
import (
"fmt"
"runtime"
"github.com/go-vela/types/version"
"github.com/Masterminds/semver/v3"
"github.com/sirupsen/logrus"
)
var (
// Arch represents the architecture information for the package.
Arch = runtime.GOARCH
// Commit represents the git commit information for the package.
Commit string
// Compiler represents the compiler information for the package.
Compiler = runtime.Compiler
// Date represents the build date information for the package.
Date string
// Go represents the golang version information for the package.
Go string
// OS represents the operating system information for the package.
OS = runtime.GOOS
// Tag represents the git tag information for the package.
Tag string
)
// New creates a new version object for Vela that is used throughout the application.
func New() *version.Version {
// check if a semantic tag was provided
if len(Tag) == 0 {
logrus.Warning("no semantic tag provided - defaulting to v0.0.0")
// set a fallback default for the tag
Tag = "v0.0.0"
}
v, err := semver.NewVersion(Tag)
if err != nil {
fmt.Println(fmt.Errorf("unable to parse semantic version for %s: %w", Tag, err))
}
return &version.Version{
Canonical: Tag,
Major: v.Major(),
Minor: v.Minor(),
Patch: v.Patch(),
PreRelease: v.Prerelease(),
Metadata: version.Metadata{
Architecture: Arch,
BuildDate: Date,
Compiler: Compiler,
GitCommit: Commit,
GoVersion: Go,
OperatingSystem: OS,
},
}
}