github.com/GoogleContainerTools/skaffold/v2@v2.13.2/pkg/diag/version/version.go (about)

     1  /*
     2  Copyright 2020 The Skaffold 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
    18  
    19  import (
    20  	"strings"
    21  
    22  	"github.com/blang/semver"
    23  )
    24  
    25  // VersionPrefix is the prefix of the git tag for a version
    26  const VersionPrefix = "v"
    27  
    28  // The current version of the minikube
    29  
    30  // version is a private field and should be set when compiling with --ldflags="-X github.com/GoogleContainerTools/skaffold/v2/pkg/diag/version.version=vX.Y.Z"
    31  var version = "v0.0.0-unset"
    32  
    33  // GetVersion returns the current diag pkg version
    34  func GetVersion() string {
    35  	return version
    36  }
    37  
    38  // GetSemverVersion returns the current semantic version (semver)
    39  func GetSemverVersion() (semver.Version, error) {
    40  	return semver.Make(strings.TrimPrefix(GetVersion(), VersionPrefix))
    41  }