-
Notifications
You must be signed in to change notification settings - Fork 754
/
deny-git-deps.py
51 lines (40 loc) · 1.39 KB
/
deny-git-deps.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
"""
Script to deny Git dependencies in the Cargo workspace. Can be passed one optional argument for the
root folder. If not provided, it will use the cwd.
## Usage
python3 .github/scripts/deny-git-deps.py polkadot-sdk
"""
import os
import sys
from cargo_workspace import Workspace, DependencyLocation
KNOWN_BAD_GIT_DEPS = {
'simple-mermaid': ['xcm-docs'],
# Fix in <https://github.com/paritytech/polkadot-sdk/issues/2922>
'bandersnatch_vrfs': ['sp-core'],
'subwasmlib': ['polkadot-zombienet-sdk-tests'],
}
root = sys.argv[1] if len(sys.argv) > 1 else os.getcwd()
workspace = Workspace.from_path(root)
errors = []
def check_dep(dep, used_by):
if dep.location != DependencyLocation.GIT:
return
if used_by in KNOWN_BAD_GIT_DEPS.get(dep.name, []):
print(f'🤨 Ignoring git dependency {dep.name} in {used_by}')
else:
errors.append(f'🚫 Found git dependency {dep.name} in {used_by}')
# Check the workspace dependencies that can be inherited:
for dep in workspace.dependencies:
check_dep(dep, "workspace")
if workspace.crates.find_by_name(dep.name):
if dep.location != DependencyLocation.PATH:
errors.append(f'🚫 Workspace must use path to link local dependency {dep.name}')
# And the dependencies of each crate:
for crate in workspace.crates:
for dep in crate.dependencies:
check_dep(dep, crate.name)
if errors:
print('❌ Found errors:')
for error in errors:
print(error)
sys.exit(1)