Bug 1415868 - add 'mach taskgraph actions'; r?jonasfj,tomprince draft
authorDustin J. Mitchell <dustin@mozilla.com>
Mon, 23 Apr 2018 21:14:14 +0000
changeset 797329 210112d04526ed7b6bbc79300dc6088f54de91f9
parent 796268 8fb36531f7d05c4a7127750589cd1736113d2d53
child 797330 1c7bb608a7e0e9ee537f55e0c17d3b88f37c4ee3
push id110465
push userdmitchell@mozilla.com
push dateFri, 18 May 2018 22:17:50 +0000
reviewersjonasfj, tomprince
Bug 1415868 - add 'mach taskgraph actions'; r?jonasfj,tomprince MozReview-Commit-ID: ExVRgcD02GK
--- a/taskcluster/docs/actions.rst
+++ b/taskcluster/docs/actions.rst
@@ -29,16 +29,21 @@ creating a custom action task.  A callba
 action task that will invoke a Python function of your devising.
 A custom action task is an arbitrary task definition that will be created
 directly.  In cases where the callback would simply call ``queue.createTask``,
 a custom action task can be more efficient.
 Creating a Callback Action
+.. note:
+    You can generate ``actions.json`` on the command line with ``./mach taskgraph actions``.
 A *callback action* is an action that calls back into in-tree logic. That is,
 you register the action with name, title, description, context, input schema and a
 python callback. When the action is triggered in a user interface,
 input matching the schema is collected, passed to a new task which then calls
 your python callback, enabling it to do pretty much anything it wants to.
 To create a new callback action you must create a file
 ``taskcluster/taskgraph/actions/my-action.py``, that at minimum contains::
--- a/taskcluster/mach_commands.py
+++ b/taskcluster/mach_commands.py
@@ -98,16 +98,30 @@ class MachCommands(MachCommandBase):
     def taskgraph_optimized(self, **options):
         return self.show_taskgraph('optimized_task_graph', options)
     @ShowTaskGraphSubCommand('taskgraph', 'morphed',
                              description="Show the morphed taskgraph")
     def taskgraph_morphed(self, **options):
         return self.show_taskgraph('morphed_task_graph', options)
+    @SubCommand('taskgraph', 'actions',
+                description="Write actions.json to stdout")
+    @CommandArgument('--root', '-r',
+                     help="root of the taskgraph definition relative to topsrcdir")
+    @CommandArgument('--quiet', '-q', action="store_true",
+                     help="suppress all logging output")
+    @CommandArgument('--verbose', '-v', action="store_true",
+                     help="include debug-level logging output")
+    @CommandArgument('--parameters', '-p', default="project=mozilla-central",
+                     help="parameters file (.yml or .json; see "
+                          "`taskcluster/docs/parameters.rst`)`")
+    def taskgraph_actions(self, **options):
+        return self.show_actions(options)
     @SubCommand('taskgraph', 'decision',
                 description="Run the decision task")
     @CommandArgument('--root', '-r',
                      help="root of the taskgraph definition relative to topsrcdir")
                      help='URL for "base" repository to clone')
@@ -380,16 +394,38 @@ class MachCommands(MachCommandBase):
             if regexprogram.match(task.label):
                 filteredtasks[key] = task
                 for depname, dep in named_links_dict[key].iteritems():
                     if regexprogram.match(dep):
                         filterededges.add((key, dep, depname))
         filtered_taskgraph = TaskGraph(filteredtasks, Graph(set(filteredtasks), filterededges))
         return filtered_taskgraph
+    def show_actions(self, options):
+        import taskgraph.parameters
+        import taskgraph.target_tasks
+        import taskgraph.generator
+        import taskgraph
+        import taskgraph.actions
+        try:
+            self.setup_logging(quiet=options['quiet'], verbose=options['verbose'])
+            parameters = taskgraph.parameters.load_parameters_file(options['parameters'])
+            parameters.check()
+            tgg = taskgraph.generator.TaskGraphGenerator(
+                root_dir=options.get('root'),
+                parameters=parameters)
+            actions = taskgraph.actions.render_actions_json(parameters, tgg.graph_config)
+            print(json.dumps(actions, sort_keys=True, indent=2, separators=(',', ': ')))
+        except Exception:
+            traceback.print_exc()
+            sys.exit(1)
 class TaskClusterImagesProvider(MachCommandBase):
     def _ensure_zstd(self):
             import zstandard  # noqa: F401
         except (ImportError, AttributeError):