Skip to content

Commit 44b83b5

Browse files
committed
Support Dependency Review Action
1 parent 3db4a67 commit 44b83b5

File tree

6 files changed

+80
-13
lines changed

6 files changed

+80
-13
lines changed

.github/actions/setup-runtime-env/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ runs:
1818
- name: "Cache Deps / Build"
1919
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
2020
with:
21-
path: >-
21+
path: |-
2222
deps
2323
_build
2424
key: "${{ format('{0}-{1}-{2}', inputs.mix-env, hashFiles('.tool-versions'), hashFiles('mix.exs')) }}"

.github/workflows/part_report_deps.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@ permissions:
88

99
jobs:
1010
binary:
11-
1211
permissions:
1312
contents: write
1413

1514
strategy:
1615
matrix:
1716
runner:
1817
- ubuntu-24.04 # X64
19-
- ubuntu-24.04-arm # ARM64
20-
- macos-13 # ARM64
21-
- macos-15 # X64
22-
- windows-2025 # X64
18+
# TODO: Re-enable
19+
# - ubuntu-24.04-arm # ARM64
20+
# - macos-13 # ARM64
21+
# - macos-15 # X64
22+
# - windows-2025 # X64
2323
# Not currently supported by Burrito
2424
# - windows-11-arm # ARM64
2525

.github/workflows/pr.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ jobs:
5656
dependency-review:
5757
name: "Dependency Review"
5858

59+
needs: ['report_deps']
60+
5961
runs-on: ubuntu-latest
6062

6163
steps:

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,32 @@ jobs:
5454
- uses: erlef/mix-dependency-submission@v1
5555
```
5656
57+
### Example Using `actions/dependency-review-action`
58+
59+
```yaml
60+
name: "Mix Dependency Submission"
61+
62+
on:
63+
push:
64+
branches:
65+
- "main"
66+
pull_request: {}
67+
68+
# The API requires write permission on the repository to submit dependencies
69+
permissions:
70+
contents: write
71+
72+
jobs:
73+
report_mix_deps:
74+
name: "Report Mix Dependencies"
75+
runs-on: ubuntu-latest
76+
steps:
77+
- uses: actions/checkout@v4
78+
- uses: erlef/mix-dependency-submission@v1
79+
- uses: actions/dependency-review-action@v4
80+
if: "${{ github.event_name == 'pull_request' }}"
81+
```
82+
5783
## Inputs
5884

5985
| Name | Description | Default |

lib/mix_dependency_submission/cli.ex

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ defmodule MixDependencySubmission.CLI do
1818
1919
iex> argv =
2020
...> ~w[--github-repository org/repo --github-job-id 123 --github-workflow build --sha sha --ref refs/heads/main --github-token ghp_xxx]
21-
...>
21+
...>
2222
...> result = MixDependencySubmission.CLI.parse!(argv)
2323
...> result.options.github_repository
2424
"org/repo"
@@ -81,7 +81,7 @@ defmodule MixDependencySubmission.CLI do
8181
help: "GitHub Actions Workflow Name"
8282
),
8383
sha:
84-
optimus_options_with_env_default("GITHUB_SHA",
84+
sha_option(
8585
value_name: "SHA",
8686
long: "--sha",
8787
help: "Current Git SHA"
@@ -140,4 +140,41 @@ defmodule MixDependencySubmission.CLI do
140140
:error -> [required: true]
141141
end ++ details
142142
end
143+
144+
@spec sha_option(Keyword.t()) :: Keyword.t()
145+
defp sha_option(base_opts) do
146+
# If the GitHub event is a pull request, we need to use the head SHA of the PR
147+
# instead of the commit SHA of the workflow run.
148+
# This is because the workflow run is triggered by the base commit of the PR,
149+
# and we want to report the dependencies of the head commit.
150+
# See: https://github.com/github/dependency-submission-toolkit/blob/72f5e31325b5e1bcc91f1b12eb7abe68e75b2105/src/snapshot.ts#L36-L61
151+
case load_pr_head_sha() do
152+
{:ok, sha} ->
153+
Keyword.put(base_opts, :sha, sha)
154+
155+
:error ->
156+
# If we can't load the PR head SHA, we fall back to the default behavior
157+
# of using the GITHUB_SHA environment variable.
158+
optimus_options_with_env_default("GITHUB_SHA", base_opts)
159+
end
160+
end
161+
162+
# Note that pull_request_target is omitted here.
163+
# That event runs in the context of the base commit of the PR,
164+
# so the snapshot should not be associated with the head commit.
165+
166+
@pr_events ~w[pull_request pull_request_comment pull_request_review pull_request_review_comment]
167+
168+
@spec load_pr_head_sha :: {:ok, <<_::320>>} | :error
169+
defp load_pr_head_sha do
170+
with {:ok, event} when event in @pr_events <- System.fetch_env("GITHUB_EVENT_NAME"),
171+
{:ok, event_path} <- System.fetch_env("GITHUB_EVENT_PATH") do
172+
event_details_json = File.read!(event_path)
173+
174+
IO.puts(event_details_json)
175+
176+
%{"pull_request" => %{"head" => %{"sha" => sha}}} = JSON.decode!(event_details_json)
177+
{:ok, sha}
178+
end
179+
end
143180
end

mix.exs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,13 @@ defmodule MixDependencySubmission.MixProject do
4848
steps: [:assemble, &Burrito.wrap/1],
4949
burrito: [
5050
targets: [
51-
Linux_X64: [os: :linux, cpu: :x86_64],
52-
Linux_ARM64: [os: :linux, cpu: :aarch64],
53-
macOS_X64: [os: :darwin, cpu: :x86_64],
54-
macOS_ARM64: [os: :darwin, cpu: :aarch64],
55-
Windows_X64: [os: :windows, cpu: :x86_64]
51+
Linux_X64: [os: :linux, cpu: :x86_64]#,
52+
# TODO: Re-enable
53+
# Linux_ARM64: [os: :linux, cpu: :aarch64],
54+
# macOS_X64: [os: :darwin, cpu: :x86_64],
55+
# macOS_ARM64: [os: :darwin, cpu: :aarch64],
56+
# Windows_X64: [os: :windows, cpu: :x86_64]
57+
5658
# Not currently supported by Burrito
5759
# Windows_ARM64: [os: :windows, cpu: :aarch64]
5860
]

0 commit comments

Comments
 (0)