View Source GitHubActions.Version (GitHubActions v0.2.26)

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

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"]

Summary

Functions

Returns the mayor version as string.

Checks if the given version matches the specification.

Returns the minor version as string.

Parses a version string into a GitHubActions.Version struct.

Parses a version string into a GitHubActions.Version struct.

Returns the patch version as string.

Returns the requiement for the given version and operator.

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()

Functions

Link to this function

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

View Source
@spec compare(version(), version(), :minor | :patch) :: :gt | :lt | :eq
@spec major(t()) :: String.t()

Returns the mayor version as string.

Examples

iex> "1.2.3" |> Version.parse!() |> Version.major()
"1"
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

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 minor(t()) :: String.t()
@spec minor(t()) :: String.t()

Returns the minor version as string.

Examples

iex> "1.2.3" |> Version.parse!() |> Version.minor()
"1.2"

iex> "1" |> Version.parse!() |> Version.minor()
"1.0"
@spec parse(String.t() | t()) :: {:ok, t()} | :error

Parses a version string into a GitHubActions.Version struct.

Examples

iex> {:ok, version} = Version.parse("1.2")
iex> version
%GitHubActions.Version{major: 1, minor: 2}

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

iex> {:ok, [v1, v2, v3]} = Version.parse("2.2/4")
iex> v1
%GitHubActions.Version{major: 2, minor: 2}
iex> v2
%GitHubActions.Version{major: 2, minor: 3}
iex> v3
%GitHubActions.Version{major: 2, minor: 4}

iex> {:ok, version} = Version.parse("1.2")
iex> {:ok, version} = Version.parse(version)
iex> version
%GitHubActions.Version{major: 1, minor: 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

iex> Version.parse!("1")
%GitHubActions.Version{major: 1}

iex> Version.parse!("1.2")
%GitHubActions.Version{major: 1, minor: 2}

iex> Version.parse!("1.2.3")
%GitHubActions.Version{major: 1, minor: 2, patch: 3}

iex> Version.parse!("invalid")
** (GitHubActions.InvalidVersionError) invalid version: "invalid"

Returns the patch version as string.

Examples

iex> "1.2.3" |> Version.parse!() |> Version.patch()
"1.2.3"

iex> "1" |> Version.parse!() |> Version.patch()
"1.0.0"
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

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"