Repository navigation
fix(rules): accept gh actions-lock format v0.0.3 (adds optional dependency hostname) #927
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
8c70197
22e9b49
e9040f0
cce739d
e1b7f51
2ee756e
d8c32dd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,6 +44,7 @@ defmodule Hypatia.Rules.ActionsLock do | |
| commit: String.t(), | ||
| owner_id: pos_integer(), | ||
| repo_id: pos_integer(), | ||
| hostname: String.t() | nil, | ||
| uses: MapSet.t(String.t()) | ||
| } | ||
| @type t :: %__MODULE__{ | ||
|
|
@@ -166,7 +167,10 @@ defmodule Hypatia.Rules.ActionsLock do | |
| [_, version] when version in @supported_versions -> | ||
| line_error(line_number, :duplicate_version) | ||
|
|
||
| [_, version] -> | ||
| version in @supported_versions -> | ||
| {:ok, %{state | version: version}} | ||
|
|
||
| true -> | ||
| line_error(line_number, {:unsupported_version, version}) | ||
| end | ||
|
|
||
|
|
@@ -244,6 +248,23 @@ defmodule Hypatia.Rules.ActionsLock do | |
| Regex.match?(~r/^ (?:owner_id|repo_id):/, line) -> | ||
| line_error(line_number, :malformed_dependency_identity) | ||
|
|
||
| match = Regex.run(~r/^ hostname: '([^']*)'$/, line) -> | ||
| [_, hostname] = match | ||
|
|
||
| cond do | ||
| state.version != "v0.0.3" -> | ||
| line_error(line_number, {:hostname_requires_v0_0_3, state.version}) | ||
|
|
||
| Regex.match?(@hostname, hostname) -> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
After the version-pattern compilation error is fixed, this reference still emits an Useful? React with 👍 / 👎. |
||
| put_dependency_field(state, :hostname, hostname, line_number) | ||
|
|
||
| true -> | ||
| line_error(line_number, {:malformed_dependency_hostname, hostname}) | ||
| end | ||
|
|
||
| Regex.match?(~r/^ hostname:/, line) -> | ||
| line_error(line_number, :malformed_dependency_hostname) | ||
|
|
||
| line == " uses:" -> | ||
| put_dependency_field(state, :uses, MapSet.new(), line_number) | ||
|
|
||
|
|
@@ -365,7 +386,7 @@ defmodule Hypatia.Rules.ActionsLock do | |
| :ok <- validate_dependency_consistency(key, ref, commit, header_line), | ||
| :ok <- | ||
| validate_repository_identity( | ||
| state.dependencies, | ||
| scope_to_host(state.dependencies, Map.get(dependency, :hostname)), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When one v0.0.3 dependency omits Useful? React with 👍 / 👎. |
||
| normalized, | ||
| owner_id, | ||
| repo_id, | ||
|
|
@@ -378,6 +399,7 @@ defmodule Hypatia.Rules.ActionsLock do | |
| commit: commit, | ||
| owner_id: owner_id, | ||
| repo_id: repo_id, | ||
| hostname: Map.get(dependency, :hostname), | ||
|
hyperpolymath marked this conversation as resolved.
|
||
| uses: Map.get(dependency, :uses, MapSet.new()) | ||
| } | ||
|
|
||
|
|
@@ -393,6 +415,16 @@ defmodule Hypatia.Rules.ActionsLock do | |
| end | ||
| end | ||
|
|
||
| # Owner and repository IDs are numbered per GitHub instance (the v0.0.3 | ||
| # schema defines them "on the recorded hostname"), so identity is compared | ||
| # only among pins recorded on the same host. An omitted hostname is its own | ||
| # scope (the lock's home host). | ||
| defp scope_to_host(dependencies, hostname) do | ||
| dependencies | ||
| |> Enum.filter(fn {_ref, dependency} -> dependency.hostname == hostname end) | ||
| |> Map.new() | ||
| end | ||
|
|
||
| defp validate_repository_identity(dependencies, normalized, owner_id, repo_id, line_number) do | ||
| [repository, _ref] = String.split(normalized, "@", parts: 2) | ||
| [owner, _repo] = String.split(repository, "/", parts: 2) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This clause is parsed as an invocation of
Kernel.in/2in match position rather than as a pattern, so compiling the module fails withcannot invoke remote function :erlang.=:=/2 inside a match. Consequently, every build or test command that compilesHypatia.Rules.ActionsLockstops before running; the unsupported-version fallback needs to retain a pattern that binds the version, such as[_, version].Useful? React with 👍 / 👎.