Skip to content

Commit

Permalink
feat(cli): support --parameters=index:<index path>
Browse files Browse the repository at this point in the history
Currently we support finding the decision task id based on `project`,
from the index, but sometimes we want to find other types of ids (e.g
for cron decision tasks).
  • Loading branch information
ahal committed Oct 25, 2024
1 parent 727cdd6 commit ea79a39
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
2 changes: 2 additions & 0 deletions docs/howto/run-locally.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ following formats are accepted:
and used.
* A value of ``project=<project>``. The ``parameters.yml`` artifact from the
latest decision task on ``<project>`` will be downloaded and used.
* A value of ``index=<index>``. The ``parameters.yml`` artifact will be
downloaded from the decision task pointed to by the specified index path.
* Path to a directory containing multiple parameter files. Any ``.yml`` file in
the directory will be considered a parameter set.

Expand Down
23 changes: 13 additions & 10 deletions src/taskgraph/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def format_spec(spec):
if spec is None:
return "defaults"

if any(spec.startswith(s) for s in ("task-id=", "project=")):
if any(spec.startswith(s) for s in ("task-id=", "project=", "index=")):
return spec

result = urlparse(spec)
Expand Down Expand Up @@ -327,16 +327,19 @@ def load_parameters_file(
task_id = None
if spec.startswith("task-id="):
task_id = spec.split("=")[1]
elif spec.startswith("project="):
if trust_domain is None:
raise ValueError(
"Can't specify parameters by project "
"if trust domain isn't supplied.",
elif spec.startswith("project=") or spec.startswith("index="):
if spec.startswith("project="):
if trust_domain is None:
raise ValueError(
"Can't specify parameters by project "
"if trust domain isn't supplied.",
)
index = "{trust_domain}.v2.{project}.latest.taskgraph.decision".format(
trust_domain=trust_domain,
project=spec.split("=")[1],
)
index = "{trust_domain}.v2.{project}.latest.taskgraph.decision".format(
trust_domain=trust_domain,
project=spec.split("=")[1],
)
else:
index = spec.split("=")[1]
task_id = find_task_id(index)

if task_id:
Expand Down
10 changes: 10 additions & 0 deletions test/test_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ def test_load_parameters_file_task_id(
tid = "abc"
project = "foo"
trust_domain = "bar"
index = f"{trust_domain}.v2.{project}.latest.taskgraph.cron"
expected = {"some": "data"}

# Setup mocks
Expand All @@ -171,6 +172,14 @@ def test_load_parameters_file_task_id(
self.assertEqual(dict(ret), expected)
self.assertRaises(ValueError, load_parameters_file, f"project={project}")

# Test `index=`
ret = load_parameters_file(f"index={index}")
mock_load_stream.assert_called_with(mock_urlopen())
mock_find_task_id.assert_called_with(
f"{trust_domain}.v2.{project}.latest.taskgraph.cron"
)
self.assertEqual(dict(ret), expected)

# Test gzipped data
r = mock.Mock()
r.info.return_value = {"Content-Encoding": "gzip"}
Expand Down Expand Up @@ -238,6 +247,7 @@ def test_parameters_id():
("http://example.org/bar.yml?id=0", "bar"),
("task-id=123", "task-id=123"),
("project=autoland", "project=autoland"),
("index=foo.v2.bar.latest", "index=foo.v2.bar.latest"),
),
)
def test_parameters_format_spec(spec, expected):
Expand Down

0 comments on commit ea79a39

Please sign in to comment.