|
5 | 5 |
|
6 | 6 | import yaml |
7 | 7 | from yaml.events import AliasEvent, DocumentEndEvent, DocumentStartEvent, NodeEvent |
8 | | -from yaml.nodes import MappingNode, ScalarNode |
| 8 | +from yaml.nodes import MappingNode, ScalarNode, SequenceNode |
9 | 9 |
|
10 | 10 | ROOT = Path(__file__).resolve().parents[2] |
11 | 11 | WORKFLOWS = ROOT / ".github" / "workflows" |
@@ -35,6 +35,16 @@ def inspect(path: Path) -> list[str]: |
35 | 35 | root = yaml.compose(text, Loader=PolicyLoader) |
36 | 36 | if not isinstance(root, MappingNode): |
37 | 37 | raise ValueError("workflow document root must be a mapping") |
| 38 | + pending = [root] |
| 39 | + while pending: |
| 40 | + node = pending.pop() |
| 41 | + if isinstance(node, MappingNode): |
| 42 | + for key, value in node.value: |
| 43 | + if isinstance(key, ScalarNode) and key.tag == "tag:yaml.org,2002:merge": |
| 44 | + raise ValueError("YAML merge keys are unsupported") |
| 45 | + pending.extend((key, value)) |
| 46 | + elif isinstance(node, SequenceNode): |
| 47 | + pending.extend(node.value) |
38 | 48 | on_nodes = [value for key, value in root.value |
39 | 49 | if isinstance(key, ScalarNode) and key.value == "on"] |
40 | 50 | if len(on_nodes) != 1: |
|
0 commit comments