Bug 1393277 - Record information about action tasks to support cot draft
authorBrian Stack <bstack@mozilla.com>
Fri, 22 Sep 2017 12:48:33 -0700
changeset 670262 06fd8e922286df86ae3f28b58bf86b50bdcf3c93
parent 670261 0e8be9bfebaf8966464b4c0f80b128b59b98a97b
child 733189 a3f9a0d5022a21a3f9509a34fedafd3712dbba59
push id81580
push userbstack@mozilla.com
push dateTue, 26 Sep 2017 07:18:14 +0000
bugs1393277
milestone58.0a1
Bug 1393277 - Record information about action tasks to support cot MozReview-Commit-ID: Kyyh6G6yw2W
taskcluster/taskgraph/actions/registry.py
taskcluster/taskgraph/actions/util.py
taskcluster/taskgraph/transforms/task.py
--- a/taskcluster/taskgraph/actions/registry.py
+++ b/taskcluster/taskgraph/actions/registry.py
@@ -260,16 +260,26 @@ ln -s /builds/worker/artifacts artifacts
                     ],
                 },
                 'extra': {
                     'treeherder': {
                         'groupName': 'action-callback',
                         'groupSymbol': 'AC',
                         'symbol': symbol,
                     },
+                    'parent': task_group_id,
+                    'action': {
+                        'name': name,
+                        'context': {
+                            'taskGroupId': task_group_id,
+                            'taskId': {'$eval': 'taskId'},
+                            'input': {'$eval': 'input'},
+                            'parameters': {'$eval': 'parameters'},
+                        },
+                    },
                 },
             }
         mem['registered'] = True
         callbacks[cb.__name__] = cb
     return register_callback
 
 
 def render_actions_json(parameters):
--- a/taskcluster/taskgraph/actions/util.py
+++ b/taskcluster/taskgraph/actions/util.py
@@ -2,16 +2,17 @@
 
 # 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 logging
+import os
 
 from requests.exceptions import HTTPError
 
 from taskgraph import create
 from taskgraph.decision import write_artifact
 from taskgraph.taskgraph import TaskGraph
 from taskgraph.optimize import optimize_task_graph
 from taskgraph.util.taskcluster import get_session, find_task_id, get_artifact, list_tasks
@@ -60,27 +61,30 @@ def create_task_from_def(task_id, task_d
     it to this function. No dependencies will be scheduled. You must handle
     this yourself. Seeing how create_tasks handles it might prove helpful."""
     task_def['schedulerId'] = 'gecko-level-{}'.format(level)
     label = task_def['metadata']['name']
     session = get_session()
     create.create_task(session, task_id, label, task_def)
 
 
-def create_tasks(to_run, full_task_graph, label_to_taskid, params, decision_task_id):
+def create_tasks(to_run, full_task_graph, label_to_taskid, params, decision_task_id=None):
     """Create new tasks.  The task definition will have {relative-datestamp':
     '..'} rendered just like in a decision task.  Action callbacks should use
     this function to create new tasks,
     allowing easy debugging with `mach taskgraph action-callback --test`.
-    This builds up all required tasks to run in order to run the tasks requested."""
+    This builds up all required tasks to run in order to run the tasks requested.
+
+    If you wish to create the tasks in a new group, leave out decision_task_id."""
     to_run = set(to_run)
     target_graph = full_task_graph.graph.transitive_closure(to_run)
     target_task_graph = TaskGraph(
         {l: full_task_graph[l] for l in target_graph.nodes},
         target_graph)
     optimized_task_graph, label_to_taskid = optimize_task_graph(target_task_graph,
                                                                 params,
                                                                 to_run,
                                                                 label_to_taskid)
     write_artifact('task-graph.json', optimized_task_graph.to_json())
     write_artifact('label-to-taskid.json', label_to_taskid)
     write_artifact('to-run.json', list(to_run))
-    create.create_tasks(optimized_task_graph, label_to_taskid, params, decision_task_id)
+    create.create_tasks(optimized_task_graph, label_to_taskid,
+                        params, decision_task_id, os.environ.get('TASK_ID'))
--- a/taskcluster/taskgraph/transforms/task.py
+++ b/taskcluster/taskgraph/transforms/task.py
@@ -1136,16 +1136,17 @@ def build_task(config, tasks):
         worker_type = task['worker-type'].format(level=level)
         provisioner_id, worker_type = worker_type.split('/', 1)
 
         routes = task.get('routes', [])
         scopes = [s.format(level=level) for s in task.get('scopes', [])]
 
         # set up extra
         extra = task.get('extra', {})
+        extra['parent'] = os.environ.get('TASK_ID', '')
         task_th = task.get('treeherder')
         if task_th:
             extra['treeherderEnv'] = task_th['environments']
 
             treeherder = extra.setdefault('treeherder', {})
 
             machine_platform, collection = task_th['platform'].split('/', 1)
             treeherder['machine'] = {'platform': machine_platform}
@@ -1183,16 +1184,17 @@ def build_task(config, tasks):
             task['priority'] = BRANCH_PRIORITIES.get(
                 config.params['project'],
                 DEFAULT_BRANCH_PRIORITY)
 
         tags = task.get('tags', {})
         tags.update({
             'createdForUser': config.params['owner'],
             'kind': config.kind,
+            'label': task['label'],
         })
 
         task_def = {
             'provisionerId': provisioner_id,
             'workerType': worker_type,
             'routes': routes,
             'created': {'relative-datestamp': '0 seconds'},
             'deadline': {'relative-datestamp': task['deadline-after']},