Version arithmetic and mix.exs rewriting behind the mix publish task.
These are the pure parts of a release: working out what the next version is, and
producing the new mix.exs source. Nothing here touches the filesystem, git or
Hex — Mix.Tasks.Publish does that, and only after every check has passed.
Summary
Functions
Returns the version that follows current under step.
Returns source with its declared version replaced by version.
Types
@type step() :: :major | :minor | :patch | {:version, String.t()}
Functions
Returns the version that follows current under step.
:major, :minor and :patch increment that segment and reset the ones below
it, dropping any pre-release and build metadata. {:version, string} takes
string verbatim and requires it to sort above current.
Returns {:error, message} when either version does not parse, or when an
explicit version is not greater than current.
Examples
iex> Plumb.Release.next_version("0.1.1", :patch)
{:ok, "0.1.2"}
iex> Plumb.Release.next_version("0.1.1", :minor)
{:ok, "0.2.0"}
iex> Plumb.Release.next_version("1.2.3-rc.1+build", :patch)
{:ok, "1.2.4"}
iex> Plumb.Release.next_version("0.1.1", {:version, "0.2.0"})
{:ok, "0.2.0"}
Returns source with its declared version replaced by version.
A @version "..." attribute is rewritten when there is one, and a literal
version: "..." in the project config otherwise. Only the first occurrence is
touched, and only when the version is a literal string — a version: @version
that points at an attribute is left for the attribute clause to handle.
Returns {:error, message} when neither form is present, which is the case for a
mix.exs that computes its version some other way. Such a project needs a
literal to rewrite before mix publish can release it.
Examples
iex> Plumb.Release.rewrite(~s|@version "0.1.1"|, "0.2.0")
{:ok, ~s|@version "0.2.0"|}
iex> Plumb.Release.rewrite(~s|version: "0.1.1"|, "0.2.0")
{:ok, ~s|version: "0.2.0"|}