Bug 1383880: Annotate builds and tests with SCHEDULES-related optimizations; r=ahal
This means that a push to try affecting only Android will only run android builds
and tests, for example.
MozReview-Commit-ID: HVUvIg0EUZn
--- a/taskcluster/taskgraph/transforms/build_attrs.py
+++ b/taskcluster/taskgraph/transforms/build_attrs.py
@@ -1,14 +1,15 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from __future__ import absolute_import, print_function, unicode_literals
from taskgraph.transforms.base import TransformSequence
+from taskgraph.util.platforms import platform_family
transforms = TransformSequence()
@transforms.add
def set_build_attributes(config, jobs):
"""
Set the build_platform and build_type attributes based on the job name.
@@ -26,8 +27,23 @@ def set_build_attributes(config, jobs):
attributes = job.setdefault('attributes', {})
attributes.update({
'build_platform': build_platform,
'build_type': build_type,
})
yield job
+
+
+@transforms.add
+def set_schedules_optimization(config, jobs):
+ """Set the `skip-unless-affected` optimization based on the build platform."""
+ for job in jobs:
+ # don't add skip-unless-schedules if there's already a when defined
+ if 'when' in job:
+ yield job
+ continue
+
+ build_platform = job['attributes']['build_platform']
+ job.setdefault('optimization',
+ {'skip-unless-schedules': [platform_family(build_platform)]})
+ yield job
--- a/taskcluster/taskgraph/transforms/tests.py
+++ b/taskcluster/taskgraph/transforms/tests.py
@@ -17,16 +17,17 @@ what should run where. this is the wrong
for example - use `all_tests.py` instead.
"""
from __future__ import absolute_import, print_function, unicode_literals
from taskgraph.transforms.base import TransformSequence
from taskgraph.util.schema import resolve_keyed_by
from taskgraph.util.treeherder import split_symbol, join_symbol
+from taskgraph.util.platforms import platform_family
from taskgraph.util.schema import (
validate_schema,
optionally_keyed_by,
Schema,
)
from voluptuous import (
Any,
Optional,
@@ -930,22 +931,26 @@ def make_job_description(config, tests):
}
jobdesc['treeherder'] = {
'symbol': test['treeherder-symbol'],
'kind': 'test',
'tier': test['tier'],
'platform': test.get('treeherder-machine-platform', test['build-platform']),
}
- # run SETA unless this is a try push
- if config.params['project'] == 'try':
- jobdesc['when'] = test.get('when', {})
+ if test.get('when'):
+ jobdesc['when'] = test['when']
else:
- # when SETA is enabled, the 'when' does not apply (optimizations don't mix)
- jobdesc['optimization'] = {'seta': None}
+ schedules = [platform_family(test['build-platform'])]
+ if config.params['project'] != 'try':
+ # for non-try branches, include SETA
+ jobdesc['optimization'] = {'skip-unless-schedules-or-seta': schedules}
+ else:
+ # otherwise just use skip-unless-schedules
+ jobdesc['optimization'] = {'skip-unless-schedules': schedules}
run = jobdesc['run'] = {}
run['using'] = 'mozharness-test'
run['test'] = test
jobdesc['worker-type'] = test.pop('worker-type')
yield jobdesc
new file mode 100644
--- /dev/null
+++ b/taskcluster/taskgraph/util/platforms.py
@@ -0,0 +1,20 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+from __future__ import absolute_import, print_function, unicode_literals
+
+import re
+
+# platform family is extracted from build platform by taking the alphabetic prefix
+# and then translating win -> windows
+_platform_re = re.compile(r'^[a-z]*')
+_renames = {
+ 'win': 'windows'
+}
+
+
+def platform_family(build_platform):
+ """Given a build platform, return the platform family (linux, macosx, etc.)"""
+ family = _platform_re.match(build_platform).group(0)
+ return _renames.get(family, family)