Documentation
¶
Overview ¶
Package semver provides functionality for parsing, comparing, and manipulating semantic version strings according to the SemVer 1.0.0 and 2.0.0 spec.
Index ¶
- Constants
- func DeriveNext(changeLevel ChangeLevel, currentVersion string, opts DeriveNextOptions) (string, error)
- func DeriveNextPreview(previewVersion, stableVersion string, opts DeriveNextOptions) (string, error)
- func MaxVersion(versionStrings ...string) string
- func ValidateNext(currentVersion, nextVersion string) error
- type ChangeLevel
- type DeriveNextOptions
Constants ¶
const ( // SemVerSpecV2 corresponds to SemVer spec version 2.0.0 // https://semver.org/spec/v2.0.0.html. SemVerSpecV2 = "2.0.0" // SemVerSpecV1 corresponds to SemVer spec version 1.0.0 // https://semver.org/spec/v1.0.0.html. SemVerSpecV1 = "1.0.0" )
Variables ¶
This section is empty.
Functions ¶
func DeriveNext ¶
func DeriveNext(changeLevel ChangeLevel, currentVersion string, opts DeriveNextOptions) (string, error)
DeriveNext determines the appropriate SemVer version bump based on the provided ChangeLevel and the provided DeriveNextOptions.
func DeriveNextPreview ¶ added in v0.8.0
func DeriveNextPreview(previewVersion, stableVersion string, opts DeriveNextOptions) (string, error)
DeriveNextPreview determines the next appropriate SemVer version bump for the preview version relative to the provided stable version. Previews always lead the stable version, so when the preview is equal with or behind the stable version, it must be caught up. When the preview version is ahead, a prerelease number bump is all that is necessary. Every change is treated as a Minor change. The provided preview version must have a prerelease segment.
func MaxVersion ¶
MaxVersion returns the largest semantic version string among the provided version strings.
func ValidateNext ¶ added in v0.8.0
ValidateNext checks that nextVersion is a valid version to follow after currentVersion. The nextVersion must always be valid, and if currentVersion is not empty, then nextVersion must be a later version than currentVersion. ValidateNext returns nil if nextVersion is a valid version to follow after currentVersion, or a descriptive error otherwise.
Types ¶
type ChangeLevel ¶
type ChangeLevel int
ChangeLevel represents the level of change, corresponding to semantic versioning.
const ( // None indicates no change. None ChangeLevel = iota // Patch is for backward-compatible bug fixes. Patch // Minor is for backward-compatible new features. Minor // Major is for incompatible API changes. Major )
func (ChangeLevel) String ¶
func (c ChangeLevel) String() string
String converts a ChangeLevel to its string representation.
type DeriveNextOptions ¶ added in v0.8.0
type DeriveNextOptions struct {
// BumpVersionCore forces the version bump to occur in the version core,
// as opposed to the prerelease number, if one was present. If true, and
// the version has a prerelease number, that number will be reset to 1.
//
// Default behavior is to prefer bumping the prerelease number or adding one
// when the version is a prerelease without a number.
BumpVersionCore bool
// DowngradePreGAChanges specifically forces [Minor] changes to be treated
// as [Patch] changes when the current version is pre-1.0.0. [Major] changes
// are always downgraded to [Minor] changes when the current version is
// pre-1.0.0 regardless of if this is enabled. This is primarily for Rust.
//
// This has no effect on prerelease versions unless BumpVersionCore is also
// enabled.
DowngradePreGAChanges bool
}
DeriveNextOptions contains options for controlling SemVer version derivation.