github.com/pachyderm/pachyderm@v1.13.4/src/client/version/client.go (about)

     1  package version
     2  
     3  import (
     4  	"fmt"
     5  	"regexp"
     6  	"strings"
     7  
     8  	pb "github.com/pachyderm/pachyderm/src/client/version/versionpb"
     9  )
    10  
    11  const (
    12  	// MajorVersion is the current major version for pachyderm.
    13  	MajorVersion = 1
    14  	// MinorVersion is the current minor version for pachyderm.
    15  	MinorVersion = 13
    16  	// MicroVersion is the patch number for pachyderm.
    17  	MicroVersion = 4
    18  )
    19  
    20  var (
    21  	// AdditionalVersion is the string provided at release time
    22  	// The value is passed to the linker at build time
    23  	//
    24  	// DO NOT set the value of this variable here. For some reason, if
    25  	// AdditionalVersion is set here, the go linker will not overwrite it.
    26  	AdditionalVersion string
    27  
    28  	// Version is the current version for pachyderm.
    29  	Version = &pb.Version{
    30  		Major:      MajorVersion,
    31  		Minor:      MinorVersion,
    32  		Micro:      MicroVersion,
    33  		Additional: AdditionalVersion,
    34  	}
    35  
    36  	// Custom release have a 40 character commit hash build into the version string
    37  	customReleaseRegex = regexp.MustCompile(`[0-9a-f]{40}`)
    38  )
    39  
    40  // IsUnstable will return true for alpha or beta builds, and false otherwise.
    41  func IsUnstable() bool {
    42  	return strings.Contains(Version.Additional, "beta") || strings.Contains(Version.Additional, "alpha")
    43  }
    44  
    45  // PrettyPrintVersion returns a version string optionally tagged with metadata.
    46  // For example: "1.2.3", or "1.2.3rc1" if version.Additional is "rc1".
    47  func PrettyPrintVersion(version *pb.Version) string {
    48  	result := PrettyPrintVersionNoAdditional(version)
    49  	if version.Additional != "" {
    50  		result += version.Additional
    51  	}
    52  	return result
    53  }
    54  
    55  // IsAtLeast returns true if Pachyderm is at least at the given version. This
    56  // allows us to gate backwards-incompatible features on release boundaries.
    57  func IsAtLeast(major, minor int) bool {
    58  	return MajorVersion > major || (MajorVersion == major && MinorVersion >= minor)
    59  }
    60  
    61  // IsCustomRelease returns true if versionAdditional is a hex commit hash that is
    62  // 40 characters long
    63  func IsCustomRelease(version *pb.Version) bool {
    64  	if version.Additional != "" && customReleaseRegex.MatchString(version.Additional) {
    65  		return true
    66  	}
    67  	return false
    68  }
    69  
    70  // BranchFromVersion returns version string for the release branch
    71  // patch release of .0 is always from the master. Others are from the M.m.x branch
    72  func BranchFromVersion(version *pb.Version) string {
    73  	if version.Micro == 0 {
    74  		return "master"
    75  	}
    76  	return fmt.Sprintf("%d.%d.x", version.Major, version.Minor)
    77  }
    78  
    79  // PrettyVersion calls PrettyPrintVersion on Version and returns the result.
    80  func PrettyVersion() string {
    81  	return PrettyPrintVersion(Version)
    82  }
    83  
    84  // PrettyPrintVersionNoAdditional returns a version string without
    85  // version.Additional.
    86  func PrettyPrintVersionNoAdditional(version *pb.Version) string {
    87  	return fmt.Sprintf("%d.%d.%d", version.Major, version.Minor, version.Micro)
    88  }