diff --git a/src/taskgraph/transforms/task.py b/src/taskgraph/transforms/task.py index 795a75744..7c834dcc7 100644 --- a/src/taskgraph/transforms/task.py +++ b/src/taskgraph/transforms/task.py @@ -649,7 +649,7 @@ def build_docker_worker_payload(config, task, task_def): if "max-run-time" in worker: payload["maxRunTime"] = worker["max-run-time"] - run_task = payload.get("command", [""])[0].endswith("run-task") + run_task = os.path.basename(payload.get("command", [""])[0]).startswith("run-task") # run-task exits EXIT_PURGE_CACHES if there is a problem with caches. # Automatically retry the tasks and purge caches if we see this exit diff --git a/src/taskgraph/util/verify.py b/src/taskgraph/util/verify.py index 357cc7d9a..90402763f 100644 --- a/src/taskgraph/util/verify.py +++ b/src/taskgraph/util/verify.py @@ -4,6 +4,7 @@ import logging +import os import re import sys import warnings @@ -333,7 +334,7 @@ def verify_run_task_caches(task, taskgraph, scratch_pad, graph_config, parameter command = payload.get("command") or [""] main_command = command[0] if isinstance(command[0], str) else "" - run_task = main_command.endswith("run-task") + run_task = os.path.basename(main_command).startswith("run-task") for cache in payload.get("cache", {}).get( "task-reference", payload.get("cache", {}) diff --git a/test/test_transforms_task.py b/test/test_transforms_task.py index 3e049ba72..ad5697f42 100644 --- a/test/test_transforms_task.py +++ b/test/test_transforms_task.py @@ -871,6 +871,36 @@ def test_default_expires_after(run_transform, graph_config, expires_after, test_ assert task_dict["task"]["expires"] == {"relative-datestamp": "28 days"} +@pytest.mark.parametrize( + "command", + ( + ["run-task"], + ["run-task-hg"], + ["/usr/local/bin/run-task"], + ["/usr/bin/run-task-hg"], + ), +) +def test_run_task_exit_status(run_transform, make_transform_config, command): + task_def = { + "description": "fake description", + "name": "fake-task-name", + "worker-type": "t-linux", + "worker": { + "docker-image": "fake-image-name", + "max-run-time": 1800, + "command": command, + }, + } + + task_dict = run_transform( + task.transforms, task_def, config=make_transform_config() + )[0] + payload = task_dict["task"]["payload"] + # If run-task is properly detected, then the transform sets those onExitStatus + assert 72 in payload["onExitStatus"]["retry"] + assert 72 in payload["onExitStatus"]["purgeCaches"] + + @pytest.mark.parametrize( "test_task", ( diff --git a/test/test_util_verify.py b/test/test_util_verify.py index 359afdf85..542ba09b4 100644 --- a/test/test_util_verify.py +++ b/test/test_util_verify.py @@ -302,6 +302,22 @@ def make_task_treeherder(label, symbol, platform="linux/opt"): pytest.raises(Exception, match="cache name is not dep"), id="using run-task without cache suffix", ), + pytest.param( + "verify_run_task_caches", + make_graph( + make_task( + "task1", + task_def={ + "payload": { + "cache": {"test-domain-level-1-checkouts": {}}, + "command": ["run-task-hg"], + } + }, + ) + ), + pytest.raises(Exception, match="cache name is not dep"), + id="using run-task-hg without cache suffix", + ), ), ) @pytest.mark.filterwarnings("error")