GitHubActions.Versions (GitHubActions v0.1.4) View Source

Functions to select and filter lists and tables of versions.

The list of versions can have the following two forms.

  • A simple list:
    ["1", "2.0", "2.1", "3", "3.1", "3.1.1"]
  • A table as list of keyword lists with compatible versions:
    [
      [a: ["1.0.0"], b: ["1.0", "1.1", "1.2"]],
      [a: ["2.0.0"], b: ["1.2", "2.0"]]
    ]

Link to this section Summary

Functions

Returns the versions of key that are compatible with to.

Returns true if the given version1 is compatible to version2.

Expands the given versions.

Filters the list of versions by the given requirement.

Returns the versions from the config.

Returns all versions for key from a list of compatible versions.

Returns the incompatible versions between versions1 and versions2.

Returns true if versions1 has an intersection with versions2.

Returns the latest version from the configured versions list.

Returns the latest version from the configured versions table by the given key or from the given versions list.

Returns the latest version from a versions table by the given key.

Returns the latest major versions from the configured versions list.

Returns the latest major versions from the configured versions table by the given key or from the given versions list.

Returns the latest major versions from a versions table by the given key.

Returns the latest minor versions from the configured versions list.

Returns the latest minor versions from the configured versions table by the given key or from the given versions list.

Returns the latest minor versions from a versions table by the given key.

Returns the versions matrix for the given requirements.

Returns true if versions contains the given version.

Sorts the given versions.

Removes all duplicated versions.

Link to this section Types

Specs

key() :: atom()

Specs

versions() :: versions_list() | versions_table()

Specs

versions_list() :: [GitHubActions.Version.version()]

Specs

versions_table() :: [keyword(GitHubActions.Version.version())]

Link to this section Functions

Link to this function

compatible(versions \\ from_config(), key, list)

View Source

Specs

Returns the versions of key that are compatible with to.

Examples

iex> otp = Versions.compatible(:otp, elixir: "1.6.6")
iex> Enum.map(otp, &to_string/1)
["19.0", "19.1", "19.2", "19.3", "20.0", "20.1", "20.2", "20.3", "21.0",
 "21.1", "21.2", "21.3"]

iex> elixir = Versions.compatible(:elixir, otp: "20.3")
iex> Enum.map(elixir, &to_string/1)
["1.4.5", "1.5.0", "1.5.1", "1.5.2", "1.5.3", "1.6.0", "1.6.1", "1.6.2",
 "1.6.3", "1.6.4", "1.6.5", "1.6.6", "1.7.0", "1.7.1", "1.7.2", "1.7.3",
 "1.7.4", "1.8.0", "1.8.1", "1.8.2", "1.9.0", "1.9.1", "1.9.2", "1.9.3",
 "1.9.4"]

iex> :otp |> Versions.compatible(elixir: "1.10.0") |> Enum.count()
8

iex> :otp |> Versions.compatible(elixir: "1.10.0/4") |> Enum.count()
12

iex> :otp |> Versions.compatible(elixir: ["1.10.0/4", "1.11.0/4"]) |> Enum.count()
14

iex> Versions.compatible([], :otp, elixir: "1.6.6")
** (ArgumentError) compatible/3 expected a table of versions as first argument, got: []
Link to this function

compatible?(versions \\ from_config(), list)

View Source

Specs

compatible?(versions(), [{key(), GitHubActions.Version.version()}]) :: boolean()

Returns true if the given version1 is compatible to version2.

Examples

iex> Versions.compatible?(elixir: "1.12.3", otp: "24.0")
true

iex> Versions.compatible?(elixir: "1.6.0", otp: "24.0")
false

iex> versions = [
...>   [a: ["1.0.0"], b: ["1.0", "1.1", "1.2"]],
...>   [a: ["2.0.0"], b: ["1.2", "2.0"]]
...> ]
iex> Versions.compatible?(versions, a: "1", b: "1.2")
true
iex> Versions.compatible?(versions, a: "2", b: "1.2")
true
iex> Versions.compatible?(versions, a: "2", b: "1")
false

iex> Versions.compatible?([], a: "1", b: "2")
** (ArgumentError) compatible?/2 expected a table of versions as first argument, got: []

Specs

expand(versions()) :: versions()

Expands the given versions.

Examples

iex> versions = Versions.expand(["1.0/2"])
iex> Enum.map(versions, &to_string/1)
["1.0", "1.1", "1.2"]

iex> versions = Versions.expand([
...>  [a: ["1.0/2"], b: ["1.0.0/2"]],
...>  [a: ["1.1.0/1"], b: ["2.0.0/2"]]
...> ])
iex> versions |> Enum.at(1) |> Keyword.get(:a) |> Enum.map(&to_string/1)
["1.1.0", "1.1.1"]
iex> versions |> Enum.at(1) |> Keyword.get(:b) |> Enum.map(&to_string/1)
["2.0.0", "2.0.1", "2.0.2"]

iex> Versions.expand([:a])
** (ArgumentError) expand/1 expected a list of versions, or tabel of versions got: [:a]
Link to this function

filter(versions, requirement)

View Source

Specs

Filters the list of versions by the given requirement.

Examples

iex> versions = ["1", "1.1.0/5", "1.2.0/1", "1.3", "2.0/1"]
iex> Versions.filter(versions, "~> 1.2")
[
  %Version{major: 1, minor: 2, patch: 0},
  %Version{major: 1, minor: 2, patch: 1},
  %Version{major: 1, minor: 3}
]
iex> Versions.filter(versions, ">= 1.3.0")
[
  %Version{major: 1, minor: 3},
  %Version{major: 2, minor: 0},
  %Version{major: 2, minor: 1}
]

iex> Versions.filter([:b, :a], "> 1.0.0")
** (ArgumentError) filter/2 expected a list of versions, got: [:b, :a]

iex> Versions.filter(["1", "2", "3"], "> 1")
** (Version.InvalidRequirementError) invalid requirement: "> 1"

Specs

from_config() :: versions()

Returns the versions from the config.

Link to this function

get(versions \\ from_config(), key)

View Source

Specs

Returns all versions for key from a list of compatible versions.

This function raises a GitHubActions.InvalidVersionError for an invalid version.

Examples

iex> versions = [
...>   [a: ["1.0.0"], b: ["1.0", "1.1", "1.2"]],
...>   [a: ["2.0.0"], b: ["1.2", "2.0"]]
...> ]
iex> versions = Versions.get(versions, :b)
iex> hd versions
#Version<1.0>
iex> Enum.map(versions, &to_string/1)
["1.0", "1.1", "1.2", "2.0"]

iex> Versions.get([a: "1"], :a)
** (ArgumentError) get/2 expected a table of versions, got: [a: "1"]
Link to this function

incompatible(versions \\ from_config(), list)

View Source

Returns the incompatible versions between versions1 and versions2.

Examples

iex> versions = Versions.incompatible(
...>   elixir: ["1.9.4", "1.10.4", "1.11.4", "1.12.3"],
...>   otp: ["21.3", "22.3", "23.3", "24.0"]
...> )
iex> for [{k1, v1}, {k2, v2}] <- versions do
...>   [{k1, to_string(v1)}, {k2, to_string(v2)}]
...> end
[
  [elixir: "1.9.4", otp: "23.3"],
  [elixir: "1.9.4", otp: "24.0"],
  [elixir: "1.10.4", otp: "24.0"],
  [elixir: "1.12.3", otp: "21.3"]
]
Link to this function

intersection?(versions1, versions2)

View Source

Specs

intersection?(versions_list(), versions_list()) :: boolean()

Returns true if versions1 has an intersection with versions2.

Examples

iex> Versions.intersection?(["1.0.0/5"], ["1.0.4/7"])
true

iex> Versions.intersection?(["1.0.0/5"], ["2.0.0/7"])
false

iex> Versions.intersection?(["1.0.0/5"], [:a])
** (ArgumentError) intersection?/2 expected two list of versions, got: ["1.0.0/5"], [:a]

Specs

latest() :: GitHubActions.Version.t()

Returns the latest version from the configured versions list.

Examples

iex> Config.config(:versions, ["1.0.0/2", "1.1.0/3"])
iex> Versions.latest()
#Version<1.1.3>

Specs

latest(versions() | key()) :: GitHubActions.Version.t()

Returns the latest version from the configured versions table by the given key or from the given versions list.

Examples

iex> Versions.latest(["1.0.0/2", "1.1.0/3"])
#Version<1.1.3>

iex> Config.config(:versions, [
...>   [a: ["1.0.0/2", "1.1.0/3"], b: ["2.0/5"]],
...>   [a: ["1.2.0/1", "1.3.0/4"], b: ["3.0/5"]]
...> ])
iex> Versions.latest(:a)
#Version<1.3.4>

iex> Versions.latest(["foo"])
** (GitHubActions.InvalidVersionError) invalid version: "foo"

iex> Versions.latest([a: "1"])
** (ArgumentError) latest/1 expected a list or table of versions or a key, got: [a: "1"]

iex> Versions.latest(:elixir)
#Version<1.13.1>

iex> Versions.latest(:otp)
#Version<24.1>

Specs

Returns the latest version from a versions table by the given key.

Examples

iex> Versions.latest([
...>   [a: ["1.0.0/2"], b: ["1.0.0/3"]],
...>   [a: ["1.1.0/3"], b: ["1.1.0/4"]]
...> ], :a)
#Version<1.1.3>

iex> Versions.latest([a: "1"], :a)
** (ArgumentError) latest/1 expected a table of versions,  got: [a: "1"]

Specs

latest_major() :: [GitHubActions.Version.t()]

Returns the latest major versions from the configured versions list.

Examples

iex> Config.config(:versions, ["1.0.0/2", "1.1.0/4", "2.0.0/3"])
iex> Versions.latest_major() |> Enum.map(&to_string/1)
["1.1.4", "2.0.3"]
Link to this function

latest_major(versions_or_key)

View Source

Specs

latest_major(versions_list() | key()) :: [GitHubActions.Version.t()]

Returns the latest major versions from the configured versions table by the given key or from the given versions list.

Examples

iex> major_versions = Versions.latest_major(["1.0.0/2", "1.1.0/3", "2.0.0/2"])
iex> Enum.map(major_versions, &to_string/1)
["1.1.3", "2.0.2"]

iex> Config.config(:versions, [
...>   [a: ["1.0.0/2", "1.1.0/3"], b: ["2.0/5"]],
...>   [a: ["2.2.0/1", "2.3.0/4"], b: ["3.0/5"]]
...> ])
iex> major_versions = Versions.latest_major(:a)
iex> Enum.map(major_versions, &to_string/1)
["1.1.3", "2.3.4"]

iex> Versions.latest_major(["foo"])
** (GitHubActions.InvalidVersionError) invalid version: "foo"

iex> Versions.latest_major([a: "1"])
** (ArgumentError) latest_major/1 expected a list or table of versions or a key, got: [a: "1"]

iex> major_versions = Versions.latest_major(:elixir)
iex> Enum.map(major_versions, &to_string/1)
["1.13.1"]

iex> major_versions = Versions.latest_major(:otp)
iex> Enum.map(major_versions, &to_string/1)
["17.5", "18.3", "19.3", "20.3", "21.3", "22.3", "23.3", "24.1"]
Link to this function

latest_major(versions, key)

View Source

Specs

latest_major(versions_table(), key()) :: [GitHubActions.Version.t()]

Returns the latest major versions from a versions table by the given key.

Examples

iex> major_versions = Versions.latest_major([
...>   [a: ["1.0.0/2"], b: ["1.0.0/3"]],
...>   [a: ["2.0.0/3"], b: ["2.0.0/4"]]
...> ], :a)
iex> Enum.map(major_versions, &to_string/1)
["1.0.2", "2.0.3"]

iex> Versions.latest_major([a: "1"], :a)
** (ArgumentError) latest_major/1 expected a table of versions,  got: [a: "1"]

Specs

latest_minor() :: [GitHubActions.Version.t()]

Returns the latest minor versions from the configured versions list.

Examples

iex> Config.config(:versions, ["1.0.0/2", "1.1.0/4", "2.0.0/3"])
iex> Versions.latest_minor() |> Enum.map(&to_string/1)
["1.0.2", "1.1.4", "2.0.3"]
Link to this function

latest_minor(versions_or_key)

View Source

Specs

latest_minor(versions_list() | key()) :: [GitHubActions.Version.t()]

Returns the latest minor versions from the configured versions table by the given key or from the given versions list.

Examples

iex> minor_versions = Versions.latest_minor(["1.0.0/2", "1.1.0/3"])
iex> Enum.map(minor_versions, &to_string/1)
["1.0.2", "1.1.3"]

iex> Config.config(:versions, [
...>   [a: ["1.0.0/2", "1.1.0/3"], b: ["2.0/5"]],
...>   [a: ["1.2.0/1", "1.3.0/4"], b: ["3.0/5"]]
...> ])
iex> minor_versions = Versions.latest_minor(:a)
iex> Enum.map(minor_versions, &to_string/1)
["1.0.2", "1.1.3", "1.2.1", "1.3.4"]

iex> Versions.latest_minor(["foo"])
** (GitHubActions.InvalidVersionError) invalid version: "foo"

iex> Versions.latest_minor([a: "1"])
** (ArgumentError) latest_minor/1 expected a list or table of versions or a key, got: [a: "1"]

iex> minor_versions = Versions.latest_minor(:elixir)
iex> Enum.map(minor_versions, &to_string/1)
["1.0.5", "1.1.1", "1.2.6", "1.3.4", "1.4.5", "1.5.3", "1.6.6", "1.7.4",
 "1.8.2", "1.9.4", "1.10.4", "1.11.4", "1.12.3", "1.13.1"]

iex> minor_versions = Versions.latest_minor(:otp)
iex> Enum.map(minor_versions, &to_string/1)
["17.0", "17.1", "17.2", "17.3", "17.4", "17.5", "18.0", "18.1", "18.2",
 "18.3", "19.0", "19.1", "19.2", "19.3", "20.0", "20.1", "20.2", "20.3",
 "21.0", "21.1", "21.2", "21.3", "22.0", "22.1", "22.2", "22.3", "23.0",
 "23.1", "23.2", "23.3", "24.0", "24.1"]
Link to this function

latest_minor(versions, key)

View Source

Specs

latest_minor(versions_table(), key()) :: [GitHubActions.Version.t()]

Returns the latest minor versions from a versions table by the given key.

Examples

iex> minor_versions = Versions.latest_minor([
...>   [a: ["1.0.0/2"], b: ["1.0.0/3"]],
...>   [a: ["1.1.0/3"], b: ["1.1.0/4"]]
...> ], :a)
iex> Enum.map(minor_versions, &to_string/1)
["1.0.2", "1.1.3"]

iex> Versions.latest_minor([a: "1"], :a)
** (ArgumentError) latest_minor/1 expected a table of versions,  got: [a: "1"]
Link to this function

matrix(versions \\ from_config(), opts)

View Source

Returns the versions matrix for the given requirements.

Examples

iex> matrix = Versions.matrix(elixir: ">= 1.9.0", otp: ">= 22.0.0")
iex> Enum.map(matrix[:elixir], &to_string/1)
["1.9.4", "1.10.4", "1.11.4", "1.12.3", "1.13.1"]
iex> Enum.map(matrix[:otp], &to_string/1)
["22.3", "23.3", "24.1"]
iex> for [{k1, v1}, {k2, v2}] <- matrix[:exclude] do
...>   [{k1, to_string(v1)}, {k2, to_string(v2)}]
...> end
[
  [elixir: "1.9.4", otp: "23.3"],
  [elixir: "1.9.4", otp: "24.1"],
  [elixir: "1.10.4", otp: "24.1"]
]

iex> Versions.matrix([], elixir: ">= 1.9.0", otp: ">= 22.0.0")
** (ArgumentError) matrix/1 expected a table of versions as first argument, got: []
Link to this function

member?(versions, version)

View Source

Specs

Returns true if versions contains the given version.

Examples

iex> versions = ["1.0.0", "1.1.0", "1.1.1"]
iex> Versions.member?(versions, "1.1")
true
iex> Versions.member?(versions, "1.0.1")
false

iex> Versions.member?([a: "1"], "1.0.0")
** (ArgumentError) member?/2 expected a list of versions, got: [a: "1"]

Specs

Sorts the given versions.

Examples

iex> versions = ["1.1", "11.1", "1.0", "2.1", "2.0.1", "2.0.0"]
iex> versions = Versions.sort(versions)
iex> Enum.map(versions, &to_string/1)
["1.0", "1.1", "2.0.0", "2.0.1", "2.1", "11.1"]

iex> Versions.sort([a: ["1", "2"]])
** (ArgumentError) sort/2 expected a list or table of versions, got: [a: ["1", "2"]]

Specs

uniq(versions()) :: versions()

Removes all duplicated versions.

Examples

iex> versions = Versions.expand(["1.0.0/4", "1.0.2/5"])
iex> versions |> Versions.uniq() |> Enum.map(&to_string/1)
["1.0.0", "1.0.1", "1.0.2", "1.0.3", "1.0.4", "1.0.5"]

iex> Versions.uniq([:a])
** (ArgumentError) uniq/1 expected a list or table of versions, got: [:a]