Skip to content

Commit

Permalink
feat(caches): support opting into or out of specific name caches
Browse files Browse the repository at this point in the history
Bug: 1526028
  • Loading branch information
ahal committed Jan 2, 2025
1 parent d883fc2 commit a70a57c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/taskgraph/transforms/run/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import hashlib
import json
import re

from taskgraph.util.taskcluster import get_artifact_prefix

Expand All @@ -31,7 +32,11 @@ def add_cache(task, taskdesc, name, mount_point, skip_untrusted=False):
skip_untrusted (bool): Whether cache is used in untrusted environments
(default: False). Only applies to docker-worker.
"""
if not task["run"].get("use-caches", True):
use_caches = task["run"].get("use-caches", True)
if isinstance(use_caches, list):
use_caches = any(re.match(pattern, name) for pattern in use_caches)

if not use_caches:
return

worker = task["worker"]
Expand Down
6 changes: 4 additions & 2 deletions src/taskgraph/transforms/run/run_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@
# tend to hide their caches. This cache is never added for level-1 tasks.
# TODO Once bug 1526028 is fixed, this and 'use-caches' should be merged.
Required("cache-dotcache"): bool,
# Whether or not to use caches.
Optional("use-caches"): bool,
# Whether or not to use caches. If a boolean, all caches will be
# enabled or disabled. If a list, entries are regexes. Only cache names
# that match one of the listed regexes are enabled.
Optional("use-caches"): Any(bool, [str]),
# if true (the default), perform a checkout on the worker
Required("checkout"): Any(bool, {str: dict}),
Optional(
Expand Down
12 changes: 12 additions & 0 deletions test/test_transforms_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,18 @@ def test_caches_generic_worker(run_caches):
]


def test_caches_regex(run_caches):
task = {
"run": {
"use-caches": ["cache[^1]"],
},
"worker-type": "t-win",
}
caches = run_caches(task)
assert len(caches) == 1
assert caches[0]["cache-name"] == "cache2"


@pytest.mark.parametrize("worker_type", ("t-linux", "t-win"))
def test_caches_disabled(run_caches, worker_type):
assert (
Expand Down

0 comments on commit a70a57c

Please sign in to comment.