Hashar has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/339675 )

Change subject: PHP CodeSniffer on CI should only lint HEAD
......................................................................

PHP CodeSniffer on CI should only lint HEAD

The Jenkins job mediawiki-core-phpcs-trusty runs PHP CodeSniffer against
every single files. That is one of the slowest jobs we have. We could be
smarter and only run against files changed in the patchset proposed
which would dramatically speed it up.

phpcs supports a bootstrap file that would let us finely tweak it is
state after all arguments and configuration have been processed and just
before the lint actually starts.

Thus, we could shell out to git just like the slave script
git-changed-in-head, grab the files, filter out the one that do not
match phpcs.xml extension:

    <arg name="extensions" value="php,php5,inc,sample"/>

Pass --bootstrap in phpcs.xml

Add a bootstrap script tests/phpcs/bootstrap-ci.php. Early returns
unless we are on CLI and JENKINS_URL env variable is set.

Get list of files added/modified/changed in HEAD based on
integration/jenkins.git script bin/git-changed-in-head for which I am
the author and licensed under GPL2.0+

Filter out any files that do not match phpcs extensions and use what is
left to override PHPCS built in list of files.

Bug: T158974
Change-Id: I2f492f889594135e37950fcb8e40da0c4d088430
---
M phpcs.xml
A tests/phpcs/bootstrap-ci.php
2 files changed, 47 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/75/339675/1

diff --git a/phpcs.xml b/phpcs.xml
index 4693b42..e113a1e 100644
--- a/phpcs.xml
+++ b/phpcs.xml
@@ -12,6 +12,7 @@
                </properties>
        </rule>
        <file>.</file>
+       <arg name="bootstrap" value="tests/phpcs/bootstrap-ci.php"/>
        <arg name="encoding" value="utf8"/>
        <arg name="extensions" value="php,php5,inc,sample"/>
        <rule ref="Generic.Files.LineLength">
diff --git a/tests/phpcs/bootstrap-ci.php b/tests/phpcs/bootstrap-ci.php
new file mode 100644
index 0000000..101a04e
--- /dev/null
+++ b/tests/phpcs/bootstrap-ci.php
@@ -0,0 +1,46 @@
+<?php
+/**
+ * Change PHP CodeSniffer to only lint files changed in HEAD.
+ *
+ * Copyright © 2017 Antoine Musso <has...@free.fr>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ * @author Antoine Musso
+ */
+
+# Only run from cli and when using Jenkins
+if ( ! ( PHP_SAPI == 'cli' && isset( $_ENV['JENKINS_URL'] ) ) ) {
+       return;
+}
+
+# From integration/jenkins.git bin/git-changed-in-head
+$_head_files = [];
+exec('git show HEAD --name-only --diff-filter=ACM -m --first-parent 
--format=format:',
+       $_head_files, $_return);
+if ( $_return !== 0 ) {
+       unset( $_head_files );
+       unset( $_return );
+       return;
+}
+
+# Only keep files that matches phpcs.xml extensions.
+$values['files'] = array_filter( $_head_files, function( $file ) use ( $values 
) {
+       $pinfo = pathinfo( $file );
+       return in_array(
+               strtolower( $pinfo['extension'] ), $values['extensions'] );
+} );

-- 
To view, visit https://gerrit.wikimedia.org/r/339675
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I2f492f889594135e37950fcb8e40da0c4d088430
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Hashar <has...@free.fr>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to