Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions docs/reference/optimization-strategies.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,11 @@ Strategies for Removing Tasks
skip-unless-changed
~~~~~~~~~~~~~~~~~~~

.. note::

This strategy is only implemented for Mercurial repositories hosted on
``hg.mozilla.org``.

The :class:`skip-unless-changed
<taskgraph.optimize.strategies.SkipUnlessChanged>` strategy will optimize the
target task away *unless* a specified file is modified. Glob patterns are
supported.
target task away *unless* a specified file is modified. When there is no
difference between head and base revs (for example, cron or action tasks), this
optimization will not apply. Glob patterns are supported.

Example:

Expand Down
5 changes: 3 additions & 2 deletions src/taskgraph/optimize/strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@ def check(self, files_changed, patterns):
return False

def should_remove_task(self, task, params, file_patterns):
# pushlog_id == -1 - this is the case when run from a cron.yml job or on a git repository
if params.get("repository_type") == "hg" and params.get("pushlog_id") == -1:
# skip-unless-changed should not apply when there is no commit delta,
# such as for cron and action tasks (there will never be file changes)
if params.get("base_rev") and params.get("head_rev") == params.get("base_rev"):
return False

changed = self.check(params["files_changed"], file_patterns)
Expand Down
6 changes: 5 additions & 1 deletion test/test_optimize_strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,11 @@ def test_index_search(caplog, responses, params, state, expires, expected, logs)
{"files_changed": ["bar.txt"]}, ["foo.txt"], True, id="files don't match"
),
pytest.param(
{"repository_type": "hg", "pushlog_id": -1, "files_changed": ["bar.txt"]},
{
"head_rev": "8843d7f92416211de9ebb963ff4ce28125932878",
"base_rev": "8843d7f92416211de9ebb963ff4ce28125932878",
"files_changed": ["bar.txt"],
},
["foo.txt"],
False,
id="cron task",
Expand Down