Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions src/taskgraph/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,46 @@ def decision(options):
taskgraph_decision(options)


@command("actions", help="Print the rendered actions.json")
@argument(
"--root",
"-r",
help="root of the taskgraph definition relative to topsrcdir",
default="taskcluster",
)
@argument(
"--verbose",
"-v",
action="store_true",
help="include debug-level logging output",
)
@argument(
"--parameters",
"-p",
default="",
help="parameters file (.yml or .json; see `taskcluster/docs/parameters.rst`)`",
)
def actions(args):
from taskgraph.actions import render_actions_json
from taskgraph.generator import TaskGraphGenerator
from taskgraph.parameters import parameters_loader

if args.pop("verbose", False):
logging.root.setLevel(logging.DEBUG)

try:
parameters = parameters_loader(args["parameters"], strict=False)
tgg = TaskGraphGenerator(root_dir=args.get("root"), parameters=parameters)

actions = render_actions_json(tgg.parameters, tgg.graph_config, "DECISION-TASK")
print(json.dumps(actions, sort_keys=True, indent=2, separators=(",", ": ")))
except Exception:
traceback.print_exc()
sys.exit(1)

return 0


@command("action-callback", description="Run action callback used by action tasks")
@argument(
"--root",
Expand Down
50 changes: 50 additions & 0 deletions test/test_main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Any copyright is dedicated to the public domain.
# http://creativecommons.org/publicdomain/zero/1.0/

import json
import os
import sys
from pathlib import Path
Expand All @@ -9,6 +10,7 @@
import pytest

import taskgraph
from taskgraph.actions import registry
from taskgraph.graph import Graph
from taskgraph.main import get_filtered_taskgraph
from taskgraph.main import main as taskgraph_main
Expand Down Expand Up @@ -350,3 +352,51 @@ def test_action_callback(mocker, run_taskgraph):
)
root = Path(trigger_mock.call_args.kwargs["root"])
assert root.joinpath("config.yml").is_file()


FAKE_ACTION = {
"name": "test",
"title": "Test action",
"symbol": "ts",
"description": "A test action",
}


@pytest.mark.parametrize(
"with_generic_actions,new_action,expected",
(
pytest.param(True, {}, (9, None)),
pytest.param(False, {}, (0, None)),
pytest.param(False, FAKE_ACTION, (1, FAKE_ACTION)),
),
)
def test_dump_actions_json(
monkeypatch, run_taskgraph, capsys, with_generic_actions, new_action, expected
):
expected_actions_len, expected_fields = expected

if not with_generic_actions:
actions = []
callbacks = {}
monkeypatch.setattr(registry, "actions", actions)
monkeypatch.setattr(registry, "callbacks", callbacks)

def fake_actions_load(_graph_config):
return callbacks, actions

monkeypatch.setattr(registry, "_load", fake_actions_load)

if new_action:
registry.register_callback_action(**new_action)(lambda *args: None)

res = run_taskgraph(["actions"], target_tasks=[])
assert res == 0

output = json.loads(capsys.readouterr().out)

actions = output["actions"]
assert len(actions) == expected_actions_len
if expected_fields is not None:
action = actions[0]
for field_name in ("name", "title", "description"):
assert action[field_name] == expected_fields[field_name]
Loading