version_bump/semver
Semantic Versioning (SemVer 2.0.0) over the foundation Version type.
This module is pure: parsing a string into a Version, rendering it back,
comparing two versions per the SemVer precedence rules (build metadata
ignored, prerelease identifiers compared field-by-field), and bumping a
version by a ReleaseType.
Types
The kind of release a set of commits warrants. Ordered Patch < Minor < Major
so the “highest type wins” rule is a simple max over release_type_rank.
pub type ReleaseType {
Patch
Minor
Major
}
Constructors
-
Patch -
Minor -
Major
A semantic version. build metadata is preserved but ignored in precedence.
pub type Version {
Version(
major: Int,
minor: Int,
patch: Int,
prerelease: List(String),
build: List(String),
)
}
Constructors
-
Version( major: Int, minor: Int, patch: Int, prerelease: List(String), build: List(String), )
Whether a package is in SemVer’s initial-development phase (0.y.z — spec
clause 4, where the public API is not yet stable) or has a stable public API.
pub type VersioningMode {
InitialDevelopment
Stable
}
Constructors
-
InitialDevelopment -
Stable
Values
pub fn bump(v: Version, t: ReleaseType) -> Version
Bump a version by a release type.
Clears any prerelease and build metadata. Major increments major and
resets minor and patch to 0. Minor increments minor and resets patch to 0.
Patch increments patch.
pub fn bump_with_prerelease(
v: Version,
t: ReleaseType,
id: String,
) -> Version
Bump a version by a release type, attaching a prerelease identifier.
The core version is bumped exactly as bump does, then a prerelease of
[id, "1"] is attached, e.g. bumping 1.1.0 by Minor with "beta"
yields 1.2.0-beta.1.
pub fn compare(a: Version, b: Version) -> order.Order
Compare two versions per SemVer 2.0.0 precedence.
Core version (major, minor, patch) is compared numerically. Build metadata is ignored. A version WITH a prerelease has LOWER precedence than the same version WITHOUT one. Prerelease identifiers are compared field-by-field: numeric identifiers compare numerically and always rank below alphanumeric ones; a longer set of identifiers wins when all preceding fields are equal.
pub fn effective_release_type(
version: Version,
t: ReleaseType,
mode: VersioningMode,
) -> ReleaseType
The release type to actually apply, given the versioning mode. In
InitialDevelopment while the major version is 0, a breaking change is
downshifted to a minor bump so it stays in 0.x instead of jumping to
1.0.0; features and fixes are unaffected, and once major >= 1 the mode has
no effect.
pub fn max(versions: List(Version)) -> option.Option(Version)
The greatest version in a list per compare, or None if the list is empty.
pub fn parse(s: String) -> Result(Version, error.ReleaseError)
Parse a SemVer string into a Version.
Accepts an optional leading v (e.g. v1.2.3), an optional -prerelease
section of dot-separated identifiers, and an optional +build metadata
section of dot-separated identifiers. The order of the optional sections is
core[-prerelease][+build] per the spec.
Returns a VersionError when the string is not a valid version.
pub fn release_type_rank(t: ReleaseType) -> Int
pub fn release_type_to_string(t: ReleaseType) -> String