github.com/SupersunnySea/draft@v0.16.0/pkg/version/version.go (about)

     1  package version
     2  
     3  // Version contains the semver release, git commit, and git tree state.
     4  type Version struct {
     5  	SemVer       string `json:"semver"`
     6  	GitCommit    string `json:"git-commit"`
     7  	GitTreeState string `json:"git-tree-state"`
     8  }
     9  
    10  func (v *Version) String() string {
    11  	return v.SemVer
    12  }
    13  
    14  var (
    15  	// Release is the current release of Draft.
    16  	// Update this whenever making a new release.
    17  	// The release is of the format Major.Minor.Patch[-Prerelease][+BuildMetadata]
    18  	//
    19  	// If it is a development build, the release name is called "canary".
    20  	//
    21  	// Increment major number for new feature additions and behavioral changes.
    22  	// Increment minor number for bug fixes and performance enhancements.
    23  	// Increment patch number for critical fixes to existing releases.
    24  	Release = "v0.16.0"
    25  
    26  	// BuildMetadata is extra build time data
    27  	BuildMetadata = ""
    28  	// GitCommit is the git sha1
    29  	GitCommit = ""
    30  	// GitTreeState is the state of the git tree
    31  	GitTreeState = ""
    32  )
    33  
    34  // getVersion returns the semver string of the version
    35  func getVersion() string {
    36  	if BuildMetadata == "" {
    37  		return Release
    38  	}
    39  	return Release + "+" + BuildMetadata
    40  }
    41  
    42  // New returns the semver interpretation of the version.
    43  func New() *Version {
    44  	return &Version{
    45  		SemVer:       getVersion(),
    46  		GitCommit:    GitCommit,
    47  		GitTreeState: GitTreeState,
    48  	}
    49  }