From a1a44cb7846b5b8b31b292ad8f22c72561e580e6 Mon Sep 17 00:00:00 2001 From: Dave Townsend Date: Wed, 6 Jan 2016 13:33:30 -0800 Subject: [PATCH] Bug 1229588: Add a taskcluster test for eslint. r=dustin Adds a new lint docker image for linting tools and adds an eslint-gecko task that uses it to run eslint over the tree. --HG-- extra : rebase_source : 6e3584ae9ec05ca1c45270f312d96cd026550e17 --- testing/docker/lint/Dockerfile | 24 +++++++++++ .../tasks/branches/base_job_flags.yml | 1 + .../taskcluster/tasks/branches/base_jobs.yml | 6 +++ testing/taskcluster/tasks/lint.yml | 40 +++++++++++++++++++ .../taskcluster/tasks/tests/eslint-gecko.yml | 35 ++++++++++++++++ tools/lint/eslint-formatter.js | 23 +++++++++++ 6 files changed, 129 insertions(+) create mode 100644 testing/docker/lint/Dockerfile create mode 100644 testing/taskcluster/tasks/lint.yml create mode 100644 testing/taskcluster/tasks/tests/eslint-gecko.yml create mode 100644 tools/lint/eslint-formatter.js diff --git a/testing/docker/lint/Dockerfile b/testing/docker/lint/Dockerfile new file mode 100644 index 000000000000..d22d3035a8ba --- /dev/null +++ b/testing/docker/lint/Dockerfile @@ -0,0 +1,24 @@ +FROM node:4.2 +MAINTAINER Dave Townsend + +RUN useradd -d /home/worker -s /bin/bash -m worker +WORKDIR /home/worker + +# install necessary npm packages +RUN npm install -g taskcluster-vcs@2.3.12 +RUN npm install -g eslint@1.10.3 +RUN npm install -g eslint-plugin-html@1.1.0 +RUN npm install -g eslint-plugin-react@3.13.1 + +# Set variable normally configured at login, by the shells parent process, these +# are taken from GNU su manual +ENV HOME /home/worker +ENV SHELL /bin/bash +ENV USER worker +ENV LOGNAME worker +ENV HOSTNAME taskcluster-worker +ENV LANG en_US.UTF-8 +ENV LC_ALL en_US.UTF-8 + +# Set a default command useful for debugging +CMD ["/bin/bash", "--login"] diff --git a/testing/taskcluster/tasks/branches/base_job_flags.yml b/testing/taskcluster/tasks/branches/base_job_flags.yml index 6b83117e0376..520d06da3492 100644 --- a/testing/taskcluster/tasks/branches/base_job_flags.yml +++ b/testing/taskcluster/tasks/branches/base_job_flags.yml @@ -105,6 +105,7 @@ flags: - linux64-st-an - macosx64 - macosx64-st-an + - eslint-gecko tests: - cppunit diff --git a/testing/taskcluster/tasks/branches/base_jobs.yml b/testing/taskcluster/tasks/branches/base_jobs.yml index 96376f30b936..74061dc60ad5 100644 --- a/testing/taskcluster/tasks/branches/base_jobs.yml +++ b/testing/taskcluster/tasks/branches/base_jobs.yml @@ -176,6 +176,12 @@ builds: types: opt: task: tasks/builds/android_api_11_b2gdroid.yml + eslint-gecko: + platforms: + - lint + types: + opt: + task: tasks/tests/eslint-gecko.yml tests: cppunit: diff --git a/testing/taskcluster/tasks/lint.yml b/testing/taskcluster/tasks/lint.yml new file mode 100644 index 000000000000..b79070e5d139 --- /dev/null +++ b/testing/taskcluster/tasks/lint.yml @@ -0,0 +1,40 @@ +# This is the "base" task which contains the common values all linting tests must +# provide. +--- +taskId: {{build_slugid}} + +task: + created: '{{now}}' + deadline: '{{#from_now}}24 hours{{/from_now}}' + metadata: + source: http://todo.com/soon + owner: mozilla-taskcluster-maintenance@mozilla.com + + tags: + createdForUser: {{owner}} + + workerType: b2gtest + provisionerId: aws-provisioner-v1 + schedulerId: task-graph-scheduler + + routes: + - 'index.gecko.v1.{{project}}.revision.linux.{{head_rev}}.{{build_name}}.{{build_type}}' + - 'index.gecko.v1.{{project}}.latest.linux.{{build_name}}.{{build_type}}' + scopes: + # Nearly all of our build tasks use tc-vcs so just include the scope across + # the board. + - 'docker-worker:cache:tc-vcs' + + payload: + # Thirty minutes should be enough for lint checks + maxRunTime: 1800 + + cache: + tc-vcs: '/home/worker/.tc-vcs' + + extra: + build_product: '{{build_product}}' + build_name: '{{build_name}}' + build_type: '{{build_type}}' + index: + rank: {{pushlog_id}} diff --git a/testing/taskcluster/tasks/tests/eslint-gecko.yml b/testing/taskcluster/tasks/tests/eslint-gecko.yml new file mode 100644 index 000000000000..015e20e09b65 --- /dev/null +++ b/testing/taskcluster/tasks/tests/eslint-gecko.yml @@ -0,0 +1,35 @@ +--- +$inherits: + from: 'tasks/lint.yml' + +task: + metadata: + name: '[TC] - ESLint' + description: 'ESLint test' + + payload: + image: + type: 'task-image' + path: 'public/image.tar' + taskId: '{{#task_id_for_image}}lint{{/task_id_for_image}}' + + command: + - bash + - -cx + - > + tc-vcs checkout ./gecko {{base_repository}} {{head_repository}} {{head_rev}} {{head_ref}} && + cd gecko && + npm link testing/eslint-plugin-mozilla && + eslint --plugin html --ext [.js,.jsm,.jsx,.xml,.html] -f tools/lint/eslint-formatter . + extra: + locations: + build: null + tests: null + treeherder: + machine: + platform: lint + groupSymbol: tc + symbol: ES + treeherderEnv: + - production + - staging diff --git a/tools/lint/eslint-formatter.js b/tools/lint/eslint-formatter.js new file mode 100644 index 000000000000..6458d4adbce4 --- /dev/null +++ b/tools/lint/eslint-formatter.js @@ -0,0 +1,23 @@ +/* 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/. */ +"use strict"; + +const path = require("path") + +module.exports = function(results) { + for (let file of results) { + let filePath = path.relative(".", file.filePath); + for (let message of file.messages) { + let status = message.message; + + if ("ruleId" in message) { + status = `${status} (${message.ruleId})`; + } + + let severity = message.severity == 1 ? "TEST-UNEXPECTED-WARNING" + : "TEST-UNEXPECTED-ERROR"; + console.log(`${severity} | ${filePath}:${message.line}:${message.column} | ${status}`); + } + } +};