From c239bd5c5a5e40dc3349ba8196f91b16afb2a872 Mon Sep 17 00:00:00 2001 From: Gary Katsevman Date: Wed, 4 Jan 2017 10:58:54 -0500 Subject: [PATCH] chore: don't run tests on travis if only docs were changed (#3908) --- build/docs-only.js | 19 +++++++++++++++++++ build/grunt.js | 29 ++++++++++++++++++++++------- package.json | 1 + 3 files changed, 42 insertions(+), 7 deletions(-) create mode 100644 build/docs-only.js diff --git a/build/docs-only.js b/build/docs-only.js new file mode 100644 index 0000000000..1880bb7cf0 --- /dev/null +++ b/build/docs-only.js @@ -0,0 +1,19 @@ +import sh from 'shelljs'; +import path from 'path'; + + +export default function(commit, commitRange) { + const SINGLE_COMMIT = `git diff-tree --no-commit-id --name-only -r ${commit}`; + const COMMIT_RANGE = `git diff --name-only ${commitRange}`; + + let command = SINGLE_COMMIT; + + if (commitRange) { + command = COMMIT_RANGE + } + + const output = sh.exec(command, {async: false, silent: true}).stdout; + + const files = output.split('\n').filter(Boolean); + return files.every((file) => file.startsWith('docs') || path.extname(file) === '.md'); +}; diff --git a/build/grunt.js b/build/grunt.js index e89286e182..560c1f5b7d 100644 --- a/build/grunt.js +++ b/build/grunt.js @@ -1,6 +1,7 @@ import {gruntCustomizer, gruntOptionsMaker} from './options-customizer.js'; import chg from 'chg'; import npmRun from 'npm-run'; +import isDocsOnly from './docs-only.js'; module.exports = function(grunt) { require('time-grunt')(grunt); @@ -550,13 +551,27 @@ module.exports = function(grunt) { grunt.registerTask('default', ['test']); // The test script includes coveralls only when the TRAVIS env var is set. - grunt.registerTask('test', [ - 'build', - 'shell:noderequire', - 'shell:browserify', - 'shell:webpack', - 'karma:defaults', - 'test-a11y'].concat(process.env.TRAVIS && 'coveralls').filter(Boolean)); + grunt.registerTask('test', function() { + const tasks = [ + 'build', + 'shell:noderequire', + 'shell:browserify', + 'shell:webpack', + 'karma:defaults', + 'test-a11y' + ]; + + if (process.env.TRAVIS) { + if (isDocsOnly(process.env.TRAVIS_COMMIT, process.env.TRAVIS_COMMIT_RANGE)) { + grunt.log.write('Not running any tests because only docs were changed'); + return; + } + + tasks.concat(process.env.TRAVIS && 'coveralls').filter(Boolean); + } + + grunt.task.run(tasks); + }); // Run while developing grunt.registerTask('dev', ['connect:dev', 'concurrent:dev']); diff --git a/package.json b/package.json index ab114a92c2..d2bf00efeb 100644 --- a/package.json +++ b/package.json @@ -112,6 +112,7 @@ "remark-lint": "^5.2.0", "remark-toc": "^3.1.0", "remark-validate-links": "^5.0.0", + "shelljs": "^0.7.5", "sinon": "^1.16.1", "time-grunt": "^1.1.1", "uglify-js": "~2.7.3",