Skip to content

Commit 9b4feb1

Browse files
committed
ci: add route to index docker-images by PR number
1 parent a6fbb8c commit 9b4feb1

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

src/taskgraph/transforms/docker_image.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,3 +256,31 @@ def fill_template(config, tasks):
256256
}
257257

258258
yield taskdesc
259+
260+
261+
@transforms.add
262+
def add_pr_route(config, tasks):
263+
"""Taskgraph builds several docker-images that get used externally.
264+
265+
Indexing these images by pull request number, allows us to easily test them
266+
in external repos using the `indexed-image` image definition type.
267+
"""
268+
if not (pr_number := config.params.get("pull_request_number")):
269+
yield from tasks
270+
return
271+
272+
PR_ROUTE = (
273+
"index.{trust-domain}.v2.{project}-pr.{pr-number}.latest.{product}.{task-name}"
274+
)
275+
subs = {
276+
"trust-domain": config.graph_config["trust-domain"],
277+
"project": config.params["project"],
278+
"pr-number": pr_number,
279+
"product": "docker-image",
280+
}
281+
282+
for task in tasks:
283+
subs["task-name"] = task["attributes"]["image_name"]
284+
routes = task.setdefault("routes", [])
285+
routes.append(PR_ROUTE.format(**subs))
286+
yield task

test/test_transform_docker_image.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,22 @@
4343
},
4444
id="symbol",
4545
),
46+
pytest.param(
47+
{},
48+
{"pull_request_number": "123"},
49+
{
50+
"routes": [
51+
"index.test-domain.v2.some-project-pr.123.latest.docker-image.fake-name"
52+
]
53+
},
54+
id="pr_route",
55+
),
56+
pytest.param(
57+
{},
58+
{},
59+
{},
60+
id="no_pr_route_without_pr_number",
61+
),
4662
),
4763
)
4864
@unittest.mock.patch(

0 commit comments

Comments
 (0)