github.com/pingcap/ticdc@v0.0.0-20220526033649-485a10ef2652/pkg/version/version.go (about) 1 // Copyright 2020 PingCAP, Inc. 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 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package version 15 16 import ( 17 "fmt" 18 19 "github.com/coreos/go-semver/semver" 20 "github.com/pingcap/log" 21 "github.com/pingcap/ticdc/pkg/util" 22 "go.uber.org/zap" 23 ) 24 25 // Version information. 26 var ( 27 ReleaseVersion = "None" 28 BuildTS = "None" 29 GitHash = "None" 30 GitBranch = "None" 31 GoVersion = "None" 32 ) 33 34 // ReleaseSemver returns a valid Semantic Versions or an empty if the 35 // ReleaseVersion is not set at compile time. 36 func ReleaseSemver() string { 37 s := removeVAndHash(ReleaseVersion) 38 v, err := semver.NewVersion(s) 39 if err != nil { 40 return "" 41 } 42 return v.String() 43 } 44 45 // LogVersionInfo prints the CDC version information. 46 func LogVersionInfo() { 47 log.Info("Welcome to Change Data Capture (CDC)", 48 zap.String("release-version", ReleaseVersion), 49 zap.String("git-hash", GitHash), 50 zap.String("git-branch", GitBranch), 51 zap.String("utc-build-time", BuildTS), 52 zap.String("go-version", GoVersion), 53 zap.Bool("failpoint-build", util.FailpointBuild), 54 ) 55 } 56 57 // GetRawInfo returns basic version information string. 58 func GetRawInfo() string { 59 var info string 60 info += fmt.Sprintf("Release Version: %s\n", ReleaseVersion) 61 info += fmt.Sprintf("Git Commit Hash: %s\n", GitHash) 62 info += fmt.Sprintf("Git Branch: %s\n", GitBranch) 63 info += fmt.Sprintf("UTC Build Time: %s\n", BuildTS) 64 info += fmt.Sprintf("Go Version: %s\n", GoVersion) 65 info += fmt.Sprintf("Failpoint Build: %t\n", util.FailpointBuild) 66 return info 67 }