Bug 1527895 - Add code-review-issues task in CI, r=dustin,marco,tomprince
☠☠ backed out by 5cfbf5c1dbe7 ☠ ☠
authorBastien Abadie <bastien@mozilla.com>
Mon, 04 Mar 2019 16:23:16 +0000
changeset 520126 7fdcccd878addbfb83cd4587777a710ed070f6f5
parent 520125 1c4fb23363e0fca41931986561ff580c129eaa6e
child 520127 b02d1b4938cc2b63d4581743186d1d42df7e745d
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdustin, marco, tomprince
bugs1527895
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1527895 - Add code-review-issues task in CI, r=dustin,marco,tomprince Differential Revision: https://phabricator.services.mozilla.com/D21348
taskcluster/ci/code-review/kind.yml
taskcluster/ci/source-test/mozlint.yml
taskcluster/docs/attributes.rst
taskcluster/docs/kinds.rst
taskcluster/docs/parameters.rst
taskcluster/taskgraph/parameters.py
taskcluster/taskgraph/target_tasks.py
taskcluster/taskgraph/transforms/code_review.py
taskcluster/taskgraph/transforms/job/__init__.py
new file mode 100644
--- /dev/null
+++ b/taskcluster/ci/code-review/kind.yml
@@ -0,0 +1,41 @@
+# 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/.
+---
+loader: taskgraph.loader.transform:loader
+
+transforms:
+   - taskgraph.transforms.code_review:transforms
+   - taskgraph.transforms.job:transforms
+   - taskgraph.transforms.task:transforms
+
+kind-dependencies:
+   - source-test
+
+jobs:
+   issues:
+      label: code-review-issues
+      description: List all issues found in static analysis and linting tasks
+      worker-type: aws-provisioner-v1/gecko-{level}-b-linux
+
+      # Only run by using the code-review target_tasks_method
+      run-on-projects: []
+
+      # This option permits to run the task
+      # regardless of the soft-dependencies tasks exit status
+      # as we are interested in the task failures
+      requires: all-resolved
+
+      # Publish on pulse
+      routes:
+         - project.relman.codereview.v1.try_ending
+
+      # Dummy execution for now, we only need the pulse message
+      worker:
+         docker-image:
+            in-tree: debian9-amd64-build
+         max-run-time: 600
+      run:
+         using: run-task
+         checkout: false
+         command: /bin/true
--- a/taskcluster/ci/source-test/mozlint.yml
+++ b/taskcluster/ci/source-test/mozlint.yml
@@ -1,10 +1,12 @@
 job-defaults:
     always-target: true
+    attributes:
+        code-review: true
     treeherder:
         kind: test
         tier: 1
     worker-type: aws-provisioner-v1/gecko-t-linux-xlarge
     worker:
         docker-image: {in-tree: "lint"}
         max-run-time: 1800
     run:
--- a/taskcluster/docs/attributes.rst
+++ b/taskcluster/docs/attributes.rst
@@ -290,8 +290,15 @@ attribute.
 
 update-channel
 ==============
 The update channel the build is configured to use.
 
 openh264_rev
 ============
 Only used for openh264 plugin builds, used to signify the revision (and thus inform artifact name) of the given build.
+
+code-review
+===========
+If a task set this boolean attribute to `true`, it will be processed by the code
+review bot, the task will ran for every new Phabricator diff.
+Any supported and detected issue will be automatically reported on the
+Phabricator revision.
--- a/taskcluster/docs/kinds.rst
+++ b/taskcluster/docs/kinds.rst
@@ -56,16 +56,22 @@ job (usually chunked).
 source-test
 -----------
 
 Source-tests are tasks that run directly from the Gecko source. This can include linting,
 unit tests, source-code analysis, or measurement work. While source-test tasks run from
 a source checkout, it is still possible for them to depend on a build artifact, though
 often they do not.
 
+code-review
+-----------
+
+Publish issues found by source-test tasks on Phabricator.
+This is a part of Release Management code review Bot.
+
 upload-symbols
 --------------
 
 Upload-symbols tasks run after builds and upload the symbols files generated by
 build tasks to Socorro for later use in crash analysis.
 
 upload-generated-sources
 ------------------------
--- a/taskcluster/docs/parameters.rst
+++ b/taskcluster/docs/parameters.rst
@@ -189,8 +189,15 @@ These parameters correspond to the repos
 repository to checkout. Their meaning is the same as the corresponding
 parameters for the gecko repository above. They are optional, but if any of
 them are specified, they must all be specified.
 
 ``comm_base_repository``
 ``comm_head_repository``
 ``comm_head_rev``
 ``comm_head_ref``
+
+Code Review
+-----------
+
+``phabricator_diff``
+   The code review process needs to know the Phabricator Differential diff that
+   started the analysis. This parameter must start with `PHID-DIFF-`
--- a/taskcluster/taskgraph/parameters.py
+++ b/taskcluster/taskgraph/parameters.py
@@ -63,16 +63,17 @@ PARAMETERS = {
     'message': '',
     'moz_build_date': lambda: datetime.now().strftime("%Y%m%d%H%M%S"),
     'next_version': None,
     'optimize_target_tasks': True,
     'owner': 'nobody@mozilla.com',
     'project': 'mozilla-central',
     'pushdate': lambda: int(time.time()),
     'pushlog_id': '0',
+    'phabricator_diff': None,
     'release_enable_emefree': False,
     'release_enable_partners': False,
     'release_eta': '',
     'release_history': {},
     'release_partners': None,
     'release_partner_config': None,
     'release_partner_build_number': 1,
     'release_type': 'nightly',
--- a/taskcluster/taskgraph/target_tasks.py
+++ b/taskcluster/taskgraph/target_tasks.py
@@ -650,8 +650,26 @@ def target_tasks_release_simulation(full
             return False
         return True
 
     return [l for l, t in full_task_graph.tasks.iteritems()
             if filter_release_tasks(t, parameters)
             and filter_out_cron(t, parameters)
             and filter_for_target_project(t)
             and filter_out_android_on_esr(t)]
+
+
+@_target_task('codereview')
+def target_tasks_codereview(full_task_graph, parameters, graph_config):
+    """Select all code review tasks needed to produce a report"""
+
+    def filter(task):
+        # Ending tasks
+        if task.kind in ['code-review']:
+            return True
+
+        # Analyzer tasks
+        if task.attributes.get('code-review') is True:
+            return True
+
+        return False
+
+    return [l for l, t in full_task_graph.tasks.iteritems() if filter(t)]
new file mode 100644
--- /dev/null
+++ b/taskcluster/taskgraph/transforms/code_review.py
@@ -0,0 +1,34 @@
+# 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/.
+"""
+Add soft dependencies and configuration to code-review tasks.
+"""
+
+from __future__ import absolute_import, print_function, unicode_literals
+
+from taskgraph.transforms.base import TransformSequence
+
+transforms = TransformSequence()
+
+
+@transforms.add
+def add_dependencies(config, jobs):
+    for job in jobs:
+        job.setdefault('soft-dependencies', [])
+        job['soft-dependencies'] += [
+            dep_task.label
+            for dep_task in config.kind_dependencies_tasks
+            if dep_task.attributes.get('code-review') is True
+        ]
+        yield job
+
+
+@transforms.add
+def add_phabricator_config(config, jobs):
+    for job in jobs:
+        diff = config.params.get('phabricator_diff')
+        if diff is not None:
+            code_review = job.setdefault('extra', {}).setdefault('code-review', {})
+            code_review['phabricator-diff'] = diff
+        yield job
--- a/taskcluster/taskgraph/transforms/job/__init__.py
+++ b/taskcluster/taskgraph/transforms/job/__init__.py
@@ -44,16 +44,17 @@ job_description_schema = Schema({
     # the following fields are passed directly through to the task description,
     # possibly modified by the run implementation.  See
     # taskcluster/taskgraph/transforms/task.py for the schema details.
     Required('description'): task_description_schema['description'],
     Optional('attributes'): task_description_schema['attributes'],
     Optional('job-from'): task_description_schema['job-from'],
     Optional('dependencies'): task_description_schema['dependencies'],
     Optional('soft-dependencies'): task_description_schema['soft-dependencies'],
+    Optional('requires'): task_description_schema['requires'],
     Optional('expires-after'): task_description_schema['expires-after'],
     Optional('routes'): task_description_schema['routes'],
     Optional('scopes'): task_description_schema['scopes'],
     Optional('tags'): task_description_schema['tags'],
     Optional('extra'): task_description_schema['extra'],
     Optional('treeherder'): task_description_schema['treeherder'],
     Optional('index'): task_description_schema['index'],
     Optional('run-on-projects'): task_description_schema['run-on-projects'],