Skip to content

Commit 31f40d5

Browse files
authored
only check for bans if the dependency tree changed (#9252)
# Objective - CI job `check-bans` fails often for unrelated reasons to a PR. Reduce those failures ## Solution - Currently, the job only runs if a `Cargo.toml` file changed. This PR would run the job only if the output of `cargo tree --depth 3` is different in a PR from main. the job would still always run on main
1 parent dfe462b commit 31f40d5

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

.github/workflows/dependencies.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,36 @@ jobs:
2929
check-bans:
3030
runs-on: ubuntu-latest
3131
steps:
32+
# on main, prepare a new cargo tree output and cache it
33+
- name: On main, prepare new cargo tree cache
34+
if: github.ref == 'refs/heads/main'
35+
run: cargo tree --depth 3 > cargo-tree-from-main
36+
- name: On main, save the new cargo tree cache
37+
if: github.ref == 'refs/heads/main'
38+
uses: actions/cache/save@v3
39+
with:
40+
path: cargo-tree-from-main
41+
key: cargo-tree-from-main
42+
# on other branch, restore the cached cargo tree output
43+
- name: On PR, restore cargo tree cache
44+
uses: actions/cache/restore@v3
45+
if: github.ref != 'refs/heads/main'
46+
with:
47+
path: cargo-tree-from-main
48+
key: cargo-tree-from-main
3249
- uses: actions/checkout@v3
3350
- uses: dtolnay/rust-toolchain@stable
51+
# if not on main, check that the cargo tree output is unchanged
52+
- name: Check if the cargo tree changed from main
53+
if: github.ref != 'refs/heads/main'
54+
continue-on-error: true
55+
id: cargo-tree-changed
56+
run: diff cargo-tree-from-main <(cargo tree --depth 3)
3457
- name: Install cargo-deny
3558
run: cargo install cargo-deny
59+
# if the check was not a success (either skipped because on main or failed because of a change), run the check
3660
- name: Check for banned and duplicated dependencies
61+
if: steps.cargo-tree-changed.outcome != 'success'
3762
run: cargo deny check bans
3863

3964
check-licenses:

0 commit comments

Comments
 (0)