Bug 1383880: Annotate builds and tests with SCHEDULES-related optimizations; r?ahal draft
authorDustin J. Mitchell <dustin@mozilla.com>
Fri, 25 Aug 2017 19:15:12 +0000
changeset 657656 7130f21a032d0358e6e3656968aa9f49ec7a593f
parent 657655 9af15234c4748bfdf9a60beed54fb230e43ccfa5
child 657657 91f7e6c9826da594b2a998312899ad14b1fb1b74
push id77585
push userdmitchell@mozilla.com
push dateFri, 01 Sep 2017 19:18:47 +0000
reviewersahal
bugs1383880
milestone57.0a1
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
taskcluster/taskgraph/transforms/build_attrs.py
taskcluster/taskgraph/transforms/tests.py
taskcluster/taskgraph/util/platforms.py
--- 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,
@@ -917,22 +918,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-unles-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)