Semver (Semver Manager v1.1.1)

Copy Markdown View Source

Semver provides utilities to increment major, minor, or patch versions according to Semantic Versioning (SemVer) rules, and to read/write versions from/to mix.exs.

Usage

mix semver

mix semver.increment [options]

Examples

mix semver.increment patch
mix semver.increment major 2

Summary

Functions

Increments a specific field of a semantic version.

Reads a mix.exs file and returns the parsed %Version{}.

Writes a %Version{} into a mix.exs file in-place.

Types

semver_field()

@type semver_field() :: :major | :minor | :patch

Functions

increment(semver, field, amount \\ 1, opts \\ [])

Increments a specific field of a semantic version.

By default, incrementing a field resets all lower-priority fields to 0. For example, incrementing :minor resets :patch to 0.

Options

  • :preserve - A list of fields to keep their current values instead of resetting to 0. Example: [preserve: [:patch]] keeps the patch number when incrementing minor.

Examples

iex> Semver.increment(%Version{major: 1, minor: 0, patch: 0}, :patch)
%Version{major: 1, minor: 0, patch: 1}

iex> Semver.increment(%Version{major: 1, minor: 0, patch: 9}, :minor)
%Version{major: 1, minor: 1, patch: 0}

iex> Semver.increment(%Version{major: 1, minor: 0, patch: 9}, :minor, 1, preserve: [:patch])
%Version{major: 1, minor: 1, patch: 9}

read_version(path)

@spec read_version(Path.t()) :: Version.t()

Reads a mix.exs file and returns the parsed %Version{}.

write_version(path, version)

@spec write_version(Path.t(), Version.t()) :: :ok

Writes a %Version{} into a mix.exs file in-place.