Skip to content

Commit 195eef8

Browse files
authored
Add a way to prevent some actions from getting generated (#938)
Right now taskgraph always generates some generic actions that are used on fxci on some projects. Projects that do not need to use said actions are forced to add `rm actions.json` at the end of their decision task to not get basic taskcluster features overridden by taskgraph (rerun/retrigger mainly). This adds a `disabled_actions` graph configuration that allows giving a list of actions that should not be emitted in the actions.json.
1 parent 1ab9c53 commit 195eef8

3 files changed

Lines changed: 92 additions & 1 deletion

File tree

src/taskgraph/actions/registry.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,12 +273,27 @@ def render_actions_json(parameters, graph_config, decision_task_id):
273273
artifact.
274274
"""
275275
assert isinstance(parameters, Parameters), "requires instance of Parameters"
276+
277+
all_actions = _get_actions(graph_config)
278+
disabled = set(graph_config["taskgraph"].get("disabled-actions") or [])
279+
known_cb_names = {action.cb_name for action in all_actions}
280+
unknown = disabled - known_cb_names
281+
if unknown:
282+
raise ValueError(
283+
"Unknown action(s) in `taskgraph.disabled-actions`: "
284+
f"{sorted(unknown)}. Known actions: {sorted(known_cb_names)}"
285+
)
286+
276287
actions = []
277-
for action in sorted(_get_actions(graph_config), key=lambda action: action.order):
288+
for action in sorted(all_actions, key=lambda action: action.order):
289+
if action.cb_name in disabled:
290+
continue
291+
278292
action = action.action_builder(parameters, graph_config, decision_task_id)
279293
if action:
280294
assert is_json(action), "action must be a JSON compatible object"
281295
actions.append(action)
296+
282297
return {
283298
"version": 1,
284299
"variables": {},

src/taskgraph/config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ class TaskgraphConfig(Schema):
5757
index_path_regexes: Optional[list[str]] = None
5858
# Configuration related to the 'run' transforms.
5959
run: Optional[RunConfig] = None
60+
# List of action `cb_name`s to omit from `actions.json`,
61+
# e.g. `["retrigger", "retrigger-disabled", "rerun"]`.
62+
disabled_actions: Optional[list[str]] = None
6063

6164
def __post_init__(self):
6265
# Validate repositories has at least 1 entry (was All(..., Length(min=1)))

test/test_actions_registry.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from mozilla_repo_urls import InvalidRepoUrlError
55

66
from taskgraph.actions import registry
7+
from taskgraph.parameters import Parameters
78
from test import does_not_raise
89

910

@@ -126,3 +127,75 @@ def test_sanity_check_task_scope(
126127
)
127128
with expectation:
128129
registry.sanity_check_task_scope(callback, parameters, graph_config={})
130+
131+
132+
def _make_action(cb_name):
133+
return registry.Action(
134+
order=42,
135+
cb_name=cb_name,
136+
permission="generic",
137+
action_builder=lambda parameters, graph_config, decision_task_id: {
138+
"cb_name": cb_name,
139+
},
140+
)
141+
142+
143+
@pytest.fixture
144+
def fake_actions(monkeypatch):
145+
fake = [
146+
_make_action("retrigger"),
147+
_make_action("retrigger-disabled"),
148+
_make_action("rerun"),
149+
_make_action("cancel"),
150+
]
151+
monkeypatch.setattr(registry, "_get_actions", lambda graph_config: fake)
152+
return fake
153+
154+
155+
def _graph_config(disabled_actions):
156+
taskgraph = {}
157+
if disabled_actions is not None:
158+
taskgraph["disabled-actions"] = disabled_actions
159+
return {"taskgraph": taskgraph}
160+
161+
162+
def test_render_actions_json_no_disabled(fake_actions):
163+
result = registry.render_actions_json(
164+
Parameters(strict=False), _graph_config(None), "DECISION-TASK"
165+
)
166+
assert [a["cb_name"] for a in result["actions"]] == [
167+
"retrigger",
168+
"retrigger-disabled",
169+
"rerun",
170+
"cancel",
171+
]
172+
173+
174+
def test_render_actions_json_filters_disabled(fake_actions):
175+
result = registry.render_actions_json(
176+
Parameters(strict=False),
177+
_graph_config(["retrigger", "retrigger-disabled", "rerun"]),
178+
"DECISION-TASK",
179+
)
180+
assert [a["cb_name"] for a in result["actions"]] == ["cancel"]
181+
182+
183+
def test_render_actions_json_empty_disabled(fake_actions):
184+
result = registry.render_actions_json(
185+
Parameters(strict=False), _graph_config([]), "DECISION-TASK"
186+
)
187+
assert [a["cb_name"] for a in result["actions"]] == [
188+
"retrigger",
189+
"retrigger-disabled",
190+
"rerun",
191+
"cancel",
192+
]
193+
194+
195+
def test_render_actions_json_unknown_disabled_raises(fake_actions):
196+
with pytest.raises(ValueError, match="does-not-exist"):
197+
registry.render_actions_json(
198+
Parameters(strict=False),
199+
_graph_config(["retrigger", "does-not-exist"]),
200+
"DECISION-TASK",
201+
)

0 commit comments

Comments
 (0)