Bug 1273633: support per-branch config in the decision task; r?garndt draft
authorDustin J. Mitchell <dustin@mozilla.com>
Tue, 17 May 2016 21:27:11 +0000
changeset 368361 f22a7118a0751ba665f603b5d82163dedeab0bc5
parent 368360 0cca43ee2c60b7844bf595a0a23a8945b25403f7
child 521237 be9f9cf151ba906386ea584cefb6519ca422794b
push id18499
push userdmitchell@mozilla.com
push dateWed, 18 May 2016 16:19:24 +0000
reviewersgarndt
bugs1273633
milestone49.0a1
Bug 1273633: support per-branch config in the decision task; r?garndt MozReview-Commit-ID: LXQIaSzPpr4
.taskcluster.yml
taskcluster/taskgraph/decision.py
taskcluster/taskgraph/parameters.py
--- a/.taskcluster.yml
+++ b/.taskcluster.yml
@@ -89,17 +89,16 @@ tasks:
           - /bin/bash
           - -cx
           - >
             mkdir -p /home/worker/artifacts &&
             checkout-gecko workspace &&
             cd workspace/gecko &&
             ln -s /home/worker/artifacts artifacts &&
             ./mach taskgraph decision
-            --target-tasks-method=try_option_syntax
             --pushlog-id='{{pushlog_id}}'
             --project='{{project}}'
             --message='{{comment}}'
             --owner='{{owner}}'
             --level='{{level}}'
             --base-repository='https://hg.mozilla.org/mozilla-central'
             --head-repository='{{{url}}}'
             --head-ref='{{revision}}'
--- a/taskcluster/taskgraph/decision.py
+++ b/taskcluster/taskgraph/decision.py
@@ -8,21 +8,36 @@ from __future__ import absolute_import, 
 
 import os
 import json
 import logging
 import yaml
 
 from .generator import TaskGraphGenerator
 from .create import create_tasks
-from .parameters import get_decision_parameters
+from .parameters import Parameters
 from .target_tasks import get_method
 
 ARTIFACTS_DIR = 'artifacts'
 
+logger = logging.getLogger(__name__)
+
+# For each project, this gives a set of parameters specific to the project.
+# See `taskcluster/docs/parameters.rst` for information on parameters.
+PER_PROJECT_PARAMETERS = {
+    'try': {
+        'target_tasks_method': 'try_option_syntax',
+    },
+
+    # the default parameters are used for projects that do not match above.
+    'default': {
+        'target_tasks_method': 'all_tasks',
+    }
+}
+
 
 def taskgraph_decision(log, options):
     """
     Run the decision task.  This function implements `mach taskgraph decision`,
     and is responsible for
 
      * processing decision task command-line options into parameters
      * running task-graph generation exactly the same way the other `mach
@@ -59,16 +74,48 @@ def taskgraph_decision(log, options):
     write_artifact('task-graph.json',
                    taskgraph_to_json(tgg.optimized_task_graph),
                    log)
 
     # actually create the graph
     create_tasks(tgg.optimized_task_graph)
 
 
+def get_decision_parameters(options):
+    """
+    Load parameters from the command-line options for 'taskgraph decision'.
+    This also applies per-project parameters, based on the given project.
+
+    """
+    parameters = {n: options[n] for n in [
+        'base_repository',
+        'head_repository',
+        'head_rev',
+        'head_ref',
+        'revision_hash',
+        'message',
+        'project',
+        'pushlog_id',
+        'owner',
+        'level',
+        'target_tasks_method',
+    ] if n in options}
+
+    project = parameters['project']
+    try:
+        parameters.update(PER_PROJECT_PARAMETERS[project])
+    except KeyError:
+        logger.warning("using default project parameters; add {} to "
+              "PER_PROJECT_PARAMETERS in {} to customize behavior "
+              "for this project".format(project, __file__))
+        parameters.update(PER_PROJECT_PARAMETERS['default'])
+
+    return Parameters(parameters)
+
+
 def taskgraph_to_json(taskgraph):
     tasks = taskgraph.tasks
 
     def tojson(task):
         return {
             'task': task.task,
             'attributes': task.attributes,
             'dependencies': []
--- a/taskcluster/taskgraph/parameters.py
+++ b/taskcluster/taskgraph/parameters.py
@@ -29,26 +29,8 @@ def load_parameters_file(options):
         return Parameters()
     with open(filename) as f:
         if filename.endswith('.yml'):
             return Parameters(**yaml.safe_load(f))
         elif filename.endswith('.json'):
             return Parameters(**json.load(f))
         else:
             raise TypeError("Parameters file `{}` is not JSON or YAML".format(filename))
-
-def get_decision_parameters(options):
-    """
-    Load parameters from the command-line options for 'taskgraph decision'.
-    """
-    return Parameters({n: options[n] for n in [
-        'base_repository',
-        'head_repository',
-        'head_rev',
-        'head_ref',
-        'revision_hash',
-        'message',
-        'project',
-        'pushlog_id',
-        'owner',
-        'level',
-        'target_tasks_method',
-    ] if n in options})