Skip to content

Commit 4dbe283

Browse files
committed
fix(ci): reject YAML merge keys even with allowed trigger names
1 parent a8c1a7e commit 4dbe283

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

‎scripts/ci/check-github-actions-policy.py‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import yaml
77
from yaml.events import AliasEvent, DocumentEndEvent, DocumentStartEvent, NodeEvent
8-
from yaml.nodes import MappingNode, ScalarNode
8+
from yaml.nodes import MappingNode, ScalarNode, SequenceNode
99

1010
ROOT = Path(__file__).resolve().parents[2]
1111
WORKFLOWS = ROOT / ".github" / "workflows"
@@ -35,6 +35,16 @@ def inspect(path: Path) -> list[str]:
3535
root = yaml.compose(text, Loader=PolicyLoader)
3636
if not isinstance(root, MappingNode):
3737
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)
3848
on_nodes = [value for key, value in root.value
3949
if isinstance(key, ScalarNode) and key.value == "on"]
4050
if len(on_nodes) != 1:

‎scripts/ci/test_github_actions_policy.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ def test_rejects_duplicate_alias_merge_document_directive_and_tag(self):
4747
"on: &events {workflow_dispatch: null}\n",
4848
"on: *events\n",
4949
"on: {<<: {workflow_dispatch: null}, push: null}\n",
50+
"on: {<<: {workflow_dispatch: null}}\n",
51+
"<<: {on: {workflow_dispatch: null}}\non: {workflow_call: null}\n",
5052
"---\non: {workflow_dispatch: null}\n",
5153
"on: {workflow_dispatch: null}\n...\n",
5254
"%YAML 1.2\non: {workflow_dispatch: null}\n",

0 commit comments

Comments
 (0)