Skip to content

Commit f9abd3d

Browse files
committed
test: Replace test_num_dependencies with github action
The purpose of the test_num_dependencies test was to be a "prompt" about dependency changes in PRs. However, manually updating the dependencies.txt file is incompatible with letting dependabot manage automated dependency updates (firecracker-microvm#3585). We therefore decided to replace the test with a different "prompt" in the form of an optional GitHub Actions check that fails whenever a lockfile is touched. Signed-off-by: Patrick Roy <[email protected]>
1 parent c3102e7 commit f9abd3d

File tree

3 files changed

+18
-134
lines changed

3 files changed

+18
-134
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Check no dependencies were modified
2+
3+
on:
4+
pull_request
5+
6+
jobs:
7+
dependency_changed_check:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: "Checkout repository"
11+
uses: actions/checkout@v3
12+
with:
13+
ref: ${{ github.event.pull_request.head.sha }}
14+
15+
- name: "Check Cargo.lock not in changeset"
16+
run: |
17+
git fetch origin
18+
git diff origin/$GITHUB_BASE_REF.. --name-only| ( ! grep "Cargo.lock")

tests/framework/dependencies.txt

Lines changed: 0 additions & 89 deletions
This file was deleted.

tests/integration_tests/build/test_dependencies.py

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# SPDX-License-Identifier: Apache-2.0
33
"""Enforces controls over dependencies."""
44

5-
import ast
65
import os
76

87
import pytest
@@ -29,47 +28,3 @@ def test_licenses():
2928
utils.run_cmd(
3029
"cargo deny --locked --manifest-path {} check licenses".format(toml_file)
3130
)
32-
33-
34-
@pytest.mark.parametrize("dep_file", ["framework/dependencies.txt"])
35-
def test_num_dependencies(dep_file):
36-
"""Enforce minimal dependency check.
37-
38-
@type: build
39-
"""
40-
_, stdout, _ = utils.run_cmd(
41-
"cargo tree --locked --prefix none -e no-dev " "--workspace"
42-
)
43-
deps = stdout.splitlines()
44-
45-
current_deps = set()
46-
# cargo tree displays a tree of dependencies which means
47-
# some of them will repeat. Below is a mechanism for filtering
48-
# unique dependencies.
49-
# cargo tree tries to display a (*) at the end of each non-leaf dependency
50-
# that was already encountered (crates without dependencies, such as libc
51-
# appear multiple times).
52-
for line in deps:
53-
if line and "(*)" not in line:
54-
# only care about dependency name, not version/path/github repo
55-
current_deps.add(line.split()[0])
56-
57-
# Use the code below to update the expected dependencies.
58-
# with open(dep_file, "w", encoding='utf-8') as prev_deps:
59-
# prev_deps.write(repr(sorted(current_deps)).replace(',', ',\n'))
60-
61-
with open(dep_file, encoding="utf-8") as prev_deps:
62-
prev_deps = ast.literal_eval(prev_deps.read())
63-
64-
difference = current_deps - set(prev_deps)
65-
66-
if difference:
67-
assert (
68-
False
69-
), f"New build dependencies detected. Is this expected? New dependencies {difference}"
70-
71-
difference = set(prev_deps) - current_deps
72-
if difference:
73-
assert (
74-
False
75-
), f"Some build dependencies have been removed: {difference}. Please update the test accordingly."

0 commit comments

Comments
 (0)