View Source GitHubActions.Version (GitHubActions v0.2.1)

Functions for parsing and matching versions against requirements.

A version is a string in a specific format or a GitHubActions.Version generated after parsing via GitHubActions.Version.parse/1.

This module is similar to Version except that minor and patch may be missing and pre are not supported.

The Version module can also parse a range of versions.

examples

Examples

iex> "2.0/2" |> Version.parse!() |> Enum.map(&to_string/1)
["2.0", "2.1", "2.2"]

iex> "1/3" |> Version.parse!() |> Enum.map(&to_string/1)
["1", "2", "3"]

Link to this section Summary

Functions

Checks if the given version matches the specification.

Parses a version string into a GitHubActions.Version struct.

Parses a version string into a GitHubActions.Version struct.

Returns the requiement for the given version and operator.

Link to this section Types

@type major() :: non_neg_integer() | nil
@type minor() :: non_neg_integer() | nil
@type patch() :: non_neg_integer() | nil
@type requirement() :: String.t() | Version.Requirement.t()
@type t() :: %GitHubActions.Version{major: major(), minor: minor(), patch: patch()}
@type version() :: String.t() | t()

Link to this section Functions

Link to this function

compare(a, b, precision \\ :patch)

View Source
@spec compare(version(), version(), :minor | :patch) :: :gt | :lt | :eq
Link to this function

match?(version, requirement)

View Source
@spec match?(version(), requirement()) :: boolean()

Checks if the given version matches the specification.

Returns true if version satisfies requirement, false otherwise. Raises a Version.InvalidRequirementError exception if requirement is not parsable, or a GitHubActions.InvalidVersionError exception if version is not parsable.

examples

Examples

iex> Version.match?("2.0", "> 1.0.0")
true

iex> Version.match?("2.0", "== 1.0.0")
false

iex> Version.match?("2.2.6", "~> 2.2.2")
true

iex> Version.match?("2.3", "~> 2.2")
true

iex> Version.match?("2", "~> 2.1.2")
false

iex> Version.match?("a.b.c", "~> 2.1.2")
** (GitHubActions.InvalidVersionError) invalid version: "a.b.c"

iex> Version.match?("2", "~~~> 2.1.2")
** (Version.InvalidRequirementError) invalid requirement: "~~~> 2.1.2"
@spec parse!(String.t() | t()) :: t()

Parses a version string into a GitHubActions.Version struct.

If string is an invalid version, a GitHubActions.InvalidVersionError is raised.

examples

Examples

iex> Version.parse!("1")
#Version<1>

iex> Version.parse!("1.2")
#Version<1.2>

iex> Version.parse!("1.2.3")
#Version<1.2.3>

iex> Version.parse!("invalid")
** (GitHubActions.InvalidVersionError) invalid version: "invalid"
@spec parse(String.t() | t()) :: {:ok, t()} | :error

Parses a version string into a GitHubActions.Version struct.

examples

Examples

iex> {:ok, version} = Version.parse("1.2")
iex> version
#Version<1.2>

iex> Version.parse("1-2")
:error

iex> {:ok, [v1, v2, v3]} = Version.parse("2.2/4")
iex> v1
#Version<2.2>
iex> v2
#Version<2.3>
iex> v3
#Version<2.4>

iex> {:ok, version} = Version.parse("1.2")
iex> {:ok, version} = Version.parse(version)
iex> version
#Version<1.2>
Link to this function

to_requirement(version, operator)

View Source
@spec to_requirement(version(), String.t()) :: String.t()

Returns the requiement for the given version and operator.

examples

Examples

iex> Version.to_requirement("1", "==")
"== 1.0.0"
iex> Version.to_requirement("1.1", ">=")
">= 1.1.0"
iex> Version.to_requirement("1.1", "~>")
"~> 1.1"
iex> Version.to_requirement("1.1.1", "~>")
"~> 1.1.1"