...

Source file src/helm.sh/helm/v3/internal/version/version.go

Documentation: helm.sh/helm/v3/internal/version

     1  /*
     2  Copyright The Helm Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package version // import "helm.sh/helm/v3/internal/version"
    18  
    19  import (
    20  	"flag"
    21  	"runtime"
    22  	"strings"
    23  )
    24  
    25  var (
    26  	// version is the current version of Helm.
    27  	// Update this whenever making a new release.
    28  	// The version is of the format Major.Minor.Patch[-Prerelease][+BuildMetadata]
    29  	//
    30  	// Increment major number for new feature additions and behavioral changes.
    31  	// Increment minor number for bug fixes and performance enhancements.
    32  	version = "v3.15"
    33  
    34  	// metadata is extra build time data
    35  	metadata = ""
    36  	// gitCommit is the git sha1
    37  	gitCommit = ""
    38  	// gitTreeState is the state of the git tree
    39  	gitTreeState = ""
    40  )
    41  
    42  // BuildInfo describes the compile time information.
    43  type BuildInfo struct {
    44  	// Version is the current semver.
    45  	Version string `json:"version,omitempty"`
    46  	// GitCommit is the git sha1.
    47  	GitCommit string `json:"git_commit,omitempty"`
    48  	// GitTreeState is the state of the git tree.
    49  	GitTreeState string `json:"git_tree_state,omitempty"`
    50  	// GoVersion is the version of the Go compiler used.
    51  	GoVersion string `json:"go_version,omitempty"`
    52  }
    53  
    54  // GetVersion returns the semver string of the version
    55  func GetVersion() string {
    56  	if metadata == "" {
    57  		return version
    58  	}
    59  	return version + "+" + metadata
    60  }
    61  
    62  // GetUserAgent returns a user agent for user with an HTTP client
    63  func GetUserAgent() string {
    64  	return "Helm/" + strings.TrimPrefix(GetVersion(), "v")
    65  }
    66  
    67  // Get returns build info
    68  func Get() BuildInfo {
    69  	v := BuildInfo{
    70  		Version:      GetVersion(),
    71  		GitCommit:    gitCommit,
    72  		GitTreeState: gitTreeState,
    73  		GoVersion:    runtime.Version(),
    74  	}
    75  
    76  	// HACK(bacongobbler): strip out GoVersion during a test run for consistent test output
    77  	if flag.Lookup("test.v") != nil {
    78  		v.GoVersion = ""
    79  	}
    80  	return v
    81  }
    82  

View as plain text