Build/Test Tools: Better git/svn detection
Prevent tasks from running twice in parallel if both .svn and .git directories are present. Add `--ignore-externals` to `svn status` and replace `git diff --name-only` with `git status --short`. Merge some duplicate code. Fixes #36394. See #35557. See [36906]. git-svn-id: https://develop.svn.wordpress.org/trunk@37185 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
765e23a4a6
commit
f0bc007421
95
Gruntfile.js
95
Gruntfile.js
@ -1,7 +1,7 @@
|
|||||||
/* jshint node:true */
|
/* jshint node:true */
|
||||||
module.exports = function(grunt) {
|
module.exports = function(grunt) {
|
||||||
var path = require('path'),
|
var path = require('path'),
|
||||||
gitorsvn = require('git-or-svn'),
|
fs = require( 'fs' ),
|
||||||
SOURCE_DIR = 'src/',
|
SOURCE_DIR = 'src/',
|
||||||
BUILD_DIR = 'build/',
|
BUILD_DIR = 'build/',
|
||||||
autoprefixer = require('autoprefixer'),
|
autoprefixer = require('autoprefixer'),
|
||||||
@ -689,57 +689,54 @@ module.exports = function(grunt) {
|
|||||||
|
|
||||||
grunt.registerTask( 'precommit', 'Runs test and build tasks in preparation for a commit', function() {
|
grunt.registerTask( 'precommit', 'Runs test and build tasks in preparation for a commit', function() {
|
||||||
var done = this.async();
|
var done = this.async();
|
||||||
|
var map = {
|
||||||
|
svn: 'svn status --ignore-externals',
|
||||||
|
git: 'git status --short'
|
||||||
|
};
|
||||||
|
|
||||||
// Figure out what tasks to run based on what files have been modified.
|
find( [
|
||||||
function enqueueTestingTasksForModifiedFiles( filesModified ) {
|
__dirname + '/.svn',
|
||||||
var taskList = ['precommit:base'];
|
__dirname + '/.git',
|
||||||
if ( /.*\.js/.test( filesModified ) ) {
|
path.dirname( __dirname ) + '/.svn'
|
||||||
grunt.log.write( 'JavaScript source files modified. JavaScript tests will be run.\n');
|
] );
|
||||||
taskList = taskList.concat( ['precommit:js'] );
|
|
||||||
}
|
function find( set ) {
|
||||||
if ( /src.*\.css/.test( filesModified ) ) {
|
var dir;
|
||||||
grunt.log.write( 'CSS source files modified. CSS tests will be run.\n');
|
|
||||||
taskList = taskList.concat( ['postcss:core'] );
|
if ( set.length ) {
|
||||||
}
|
fs.stat( dir = set.shift(), function( error ) {
|
||||||
if ( /.*\.php/.test( filesModified ) ) {
|
error ? find( set ) : run( path.basename( dir ).substr( 1 ) );
|
||||||
grunt.log.write( 'PHP source files modified. PHP tests will be run.\n');
|
} );
|
||||||
taskList = taskList.concat( ['precommit:php'] );
|
|
||||||
}
|
|
||||||
grunt.task.run( taskList );
|
|
||||||
done();
|
|
||||||
}
|
|
||||||
gitorsvn( __dirname, function(gitorsvn) {
|
|
||||||
if ( gitorsvn === 'svn' ) {
|
|
||||||
grunt.util.spawn(
|
|
||||||
{
|
|
||||||
cmd: 'svn',
|
|
||||||
args: ['status']
|
|
||||||
},
|
|
||||||
function(error, result, code) {
|
|
||||||
if ( code !== 0 ) {
|
|
||||||
grunt.fail.warn( 'The `svn status` command returned a non-zero exit code.', code );
|
|
||||||
}
|
|
||||||
enqueueTestingTasksForModifiedFiles( result.stdout );
|
|
||||||
}
|
|
||||||
);
|
|
||||||
} else if ( gitorsvn === 'git' ) {
|
|
||||||
grunt.util.spawn(
|
|
||||||
{
|
|
||||||
cmd: 'git',
|
|
||||||
args: ['diff', '--name-only']
|
|
||||||
},
|
|
||||||
function(error, result, code) {
|
|
||||||
if ( code !== 0 ) {
|
|
||||||
grunt.fail.warn( 'The `git diff --name-only` command returned a non-zero exit code.', code );
|
|
||||||
}
|
|
||||||
enqueueTestingTasksForModifiedFiles( result.stdout );
|
|
||||||
}
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
grunt.log.write( 'This WordPress install is not under version control. No tests will be run.' );
|
grunt.fatal( 'This WordPress install is not under version control.' );
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
});
|
|
||||||
|
function run( type ) {
|
||||||
|
var command = map[ type ].split( ' ' );
|
||||||
|
var taskList = [ 'precommit:base' ];
|
||||||
|
|
||||||
|
grunt.util.spawn( {
|
||||||
|
cmd: command.shift(),
|
||||||
|
args: command
|
||||||
|
}, function( error, result, code ) {
|
||||||
|
if ( code !== 0 ) {
|
||||||
|
grunt.fatal( 'The `' + map[ type ] + '` command returned a non-zero exit code.', code );
|
||||||
|
}
|
||||||
|
|
||||||
|
[ 'js', 'css', 'php' ].forEach( function( extension ) {
|
||||||
|
if ( ( result.stdout + '\n' ).indexOf( '.' + extension + '\n' ) !== -1 ) {
|
||||||
|
grunt.log.writeln( extension.toUpperCase() + ' files modified. ' + extension.toUpperCase() + ' tests will be run.');
|
||||||
|
taskList.push( 'precommit:' + extension );
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
|
||||||
|
grunt.task.run( taskList );
|
||||||
|
|
||||||
|
done();
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
|
||||||
grunt.registerTask( 'copy:all', [
|
grunt.registerTask( 'copy:all', [
|
||||||
'copy:files',
|
'copy:files',
|
||||||
|
@ -10,7 +10,6 @@
|
|||||||
"license": "GPL-2.0+",
|
"license": "GPL-2.0+",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"autoprefixer": "~6.3.3",
|
"autoprefixer": "~6.3.3",
|
||||||
"git-or-svn": "~0.1.0",
|
|
||||||
"grunt": "~0.4.5",
|
"grunt": "~0.4.5",
|
||||||
"grunt-browserify": "~5.0.0",
|
"grunt-browserify": "~5.0.0",
|
||||||
"grunt-contrib-clean": "~1.0.0",
|
"grunt-contrib-clean": "~1.0.0",
|
||||||
|
Loading…
Reference in New Issue
Block a user