-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathcheck_pipeline_name_only_steps.py
More file actions
104 lines (84 loc) · 3.71 KB
/
check_pipeline_name_only_steps.py
File metadata and controls
104 lines (84 loc) · 3.71 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
from __future__ import annotations
import argparse
import sys
from collections.abc import Sequence
from typing import Any
import ruamel.yaml
yaml = ruamel.yaml.YAML(typ="safe")
def check_pipeline_steps(melange_cfg: dict[str, Any]) -> tuple[bool, list[str]]:
"""
Check if any pipeline steps have only a 'name' field without 'uses' or other details.
Returns (is_valid, list_of_issues).
"""
issues = []
# Check main pipeline
pipelines = melange_cfg.get("pipeline", [])
for i, step in enumerate(pipelines):
if isinstance(step, dict):
# Check if step has only 'name' and no 'uses'
if "name" in step and "uses" not in step and len(step) == 1:
step_name = step.get("name", f"step {i}")
issues.append(
f"main pipeline step '{step_name}' has only a name with no 'uses' or other details",
)
# Check test pipeline
test_section = melange_cfg.get("test", {})
test_pipelines = test_section.get("pipeline", [])
for i, step in enumerate(test_pipelines):
if isinstance(step, dict):
# Check if step has only 'name' and no 'uses'
if "name" in step and "uses" not in step and len(step) == 1:
step_name = step.get("name", f"step {i}")
issues.append(
f"test pipeline step '{step_name}' has only a name with no 'uses' or other details",
)
# Check each subpackage
for sub_idx, subpkg in enumerate(melange_cfg.get("subpackages", [])):
subpkg_name = subpkg.get("name", f"subpackage-{sub_idx}")
# Check subpackage pipelines
subpkg_pipelines = subpkg.get("pipeline", [])
for i, step in enumerate(subpkg_pipelines):
if isinstance(step, dict):
# Check if step has only 'name' and no 'uses'
if "name" in step and "uses" not in step and len(step) == 1:
step_name = step.get("name", f"step {i}")
issues.append(
f"subpackage '{subpkg_name}' pipeline step '{step_name}' has only a name with no 'uses' or other details",
)
# Check subpackage test pipelines
subpkg_test_section = subpkg.get("test", {})
subpkg_test_pipelines = subpkg_test_section.get("pipeline", [])
for i, step in enumerate(subpkg_test_pipelines):
if isinstance(step, dict):
# Check if step has only 'name' and no 'uses'
if "name" in step and "uses" not in step and len(step) == 1:
step_name = step.get("name", f"step {i}")
issues.append(
f"subpackage '{subpkg_name}' test pipeline step '{step_name}' has only a name with no 'uses' or other details",
)
return len(issues) == 0, issues
def main(argv: Sequence[str] | None = None) -> int:
parser = argparse.ArgumentParser(
description="Check that pipeline steps don't have only a name without uses or other details",
)
parser.add_argument("filenames", nargs="*", help="Filenames to check")
args = parser.parse_args(argv)
retval = 0
for filename in args.filenames:
try:
with open(filename) as f:
melange_cfg = yaml.load(f)
except Exception as e:
print(f"Error loading {filename}: {e}")
retval = 1
continue
if not melange_cfg:
continue
is_valid, issues = check_pipeline_steps(melange_cfg)
if not is_valid:
for issue in issues:
print(f"{filename}: {issue}")
retval = 1
return retval
if __name__ == "__main__":
sys.exit(main())