Skip to content

Commit

Permalink
fix(transforms.run): be more specific about implicit files changed fo…
Browse files Browse the repository at this point in the history
…r 'when' optimization
  • Loading branch information
ahal committed Oct 17, 2024
1 parent e8640e7 commit 727cdd6
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/taskgraph/transforms/run/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ def rewrite_when_to_optimization(config, tasks):
files_changed = when.get("files-changed")

# implicitly add task config directory.
files_changed.append(f"{config.path}/**")
files_changed.append(f"{config.path}/kind.yml")
if task.get("task-from") and task["task-from"] != "kind.yml":
files_changed.append(f"{config.path}/{task['task-from']}")

# "only when files changed" implies "skip if files have not changed"
task["optimization"] = {"skip-unless-changed": files_changed}
Expand Down
39 changes: 39 additions & 0 deletions test/test_transforms_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,45 @@ def test_worker_caches(task, transform):
validate_schema(partial_schema, taskdesc["worker"][key], "validation error")


def test_rewrite_when_to_optimization(run_transform, make_transform_config):
config = make_transform_config()

task = {"foo": "bar"}
result = run_transform(run.rewrite_when_to_optimization, task)
assert list(result) == [{"foo": "bar"}]

task = {"foo": "bar", "when": {"files-changed": ["README.md"]}}
result = run_transform(run.rewrite_when_to_optimization, task)
assert list(result) == [
{
"foo": "bar",
"optimization": {
"skip-unless-changed": ["README.md", f"{config.path}/kind.yml"]
},
}
]

task = {
"foo": "bar",
"when": {"files-changed": ["README.md"]},
"task-from": "foo.yml",
}
result = run_transform(run.rewrite_when_to_optimization, task)
assert list(result) == [
{
"foo": "bar",
"optimization": {
"skip-unless-changed": [
"README.md",
f"{config.path}/kind.yml",
f"{config.path}/foo.yml",
]
},
"task-from": "foo.yml",
}
]


def assert_use_fetches_toolchain_env(task):
assert task["worker"]["env"]["FOO"] == "1"

Expand Down

0 comments on commit 727cdd6

Please sign in to comment.