Skip to content

Commit

Permalink
chore: don't run tests on travis if only docs were changed (#3908)
Browse files Browse the repository at this point in the history
  • Loading branch information
gkatsev authored Jan 4, 2017
1 parent b547214 commit c239bd5
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
19 changes: 19 additions & 0 deletions build/docs-only.js
Original file line number Diff line number Diff line change
@@ -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');
};
29 changes: 22 additions & 7 deletions build/grunt.js
Original file line number Diff line number Diff line change
@@ -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);
Expand Down Expand Up @@ -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']);
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit c239bd5

Please sign in to comment.