Skip to content

Commit 07ab89c

Browse files
committed
feat(caches): support opting into or out of specific name caches
Bug: 1526028
1 parent f7d3b47 commit 07ab89c

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

src/taskgraph/transforms/run/common.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import hashlib
1111
import json
12+
import re
1213

1314
from taskgraph.util.taskcluster import get_artifact_prefix
1415

@@ -31,7 +32,11 @@ def add_cache(task, taskdesc, name, mount_point, skip_untrusted=False):
3132
skip_untrusted (bool): Whether cache is used in untrusted environments
3233
(default: False). Only applies to docker-worker.
3334
"""
34-
if not task["run"].get("use-caches", True):
35+
use_caches = task["run"].get("use-caches", True)
36+
if isinstance(use_caches, list):
37+
use_caches = any(re.match(pattern, name) for pattern in use_caches)
38+
39+
if not use_caches:
3540
return
3641

3742
worker = task["worker"]

src/taskgraph/transforms/run/run_task.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@
2828
# tend to hide their caches. This cache is never added for level-1 tasks.
2929
# TODO Once bug 1526028 is fixed, this and 'use-caches' should be merged.
3030
Required("cache-dotcache"): bool,
31-
# Whether or not to use caches.
32-
Optional("use-caches"): bool,
31+
# Whether or not to use caches. If a boolean, all caches will be
32+
# enabled or disabled. If a list, entries are regexes. Only cache names
33+
# that match one of the listed regexes are enabled.
34+
Optional("use-caches"): Any(bool, [str]),
3335
# if true (the default), perform a checkout on the worker
3436
Required("checkout"): Any(bool, {str: dict}),
3537
Optional(

test/test_transforms_run.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,18 @@ def test_caches_generic_worker(run_caches):
109109
]
110110

111111

112+
def test_caches_regex(run_caches):
113+
task = {
114+
"run": {
115+
"use-caches": ["cache[^1]"],
116+
},
117+
"worker-type": "t-win",
118+
}
119+
caches = run_caches(task)
120+
assert len(caches) == 1
121+
assert caches[0]["cache-name"] == "cache2"
122+
123+
112124
@pytest.mark.parametrize("worker_type", ("t-linux", "t-win"))
113125
def test_caches_disabled(run_caches, worker_type):
114126
assert (

0 commit comments

Comments
 (0)