1 // Copyright 2021 Chaos Mesh Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 // 15 16 package version 17 18 import ( 19 "fmt" 20 "runtime" 21 ) 22 23 var ( 24 gitVersion = "v0.0.0-master+$Format:%h$" 25 gitCommit = "$Format:%H$" // sha1 from git, output of $(git rev-parse HEAD) 26 27 buildDate = "1970-01-01T00:00:00Z" // build date in ISO8601 format, output of $(date -u +'%Y-%m-%dT%H:%M:%SZ') 28 ) 29 30 // PrintVersionInfo show version info to Stdout 31 func PrintVersionInfo(name string) { 32 fmt.Printf("%s Version: %#v\n", name, Get()) 33 } 34 35 // Get returns the overall codebase version. It's for detecting 36 // what code a binary was built from. 37 func Get() Info { 38 // These variables typically come from -ldflags settings 39 return Info{ 40 GitVersion: gitVersion, 41 GitCommit: gitCommit, 42 BuildDate: buildDate, 43 GoVersion: runtime.Version(), 44 Compiler: runtime.Compiler, 45 Platform: fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH), 46 } 47 } 48