Skip to content

Instantly share code, notes, and snippets.

@wa0x6e
Last active April 23, 2018 20:03
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save wa0x6e/3035117 to your computer and use it in GitHub Desktop.
Save wa0x6e/3035117 to your computer and use it in GitHub Desktop.
Faster php lint target for jenkins php
<!--
More faster : lint only modified files
--------------------------------------
We create a new target to retrieve a list of modified files
If there is modified files, execute the lint target, else skip
with the `if="modifiedFiles"` option.
The list of modified files is stored in ${files.modified}, one file per line.
Feel free to reuse the checkModified target to execute other tasks only on
newly modified .php files
-->
<!-- A new target to search for modified files -->
<target name="checkModified" description="Check for modified php files">
<echo message="Searching for newly modified files" />
<path id="editedfiles">
<fileset dir="${basedir}/src/">
<modified /> <!-- Search only for modified files -->
<include name="**/*.php" /> <!-- Search only for files with .php extension -->
<exclude name="**/vendor/**" /> <!-- Exclude vendor directory -->
</fileset>
</path>
<pathconvert pathsep="${line.separator}" property="files.modified" refid="editedfiles" />
<condition property="modifiedFiles">
<not>
<equals arg1="${files.modified}" arg2="" />
</not>
</condition>
</target>
<!-- The Php Lint target -->
<!-- Will only execute if and only if there is some modified files -->
<target name="lint" depends="checkModified" description="Perform syntax check of sourcecode files" if="modifiedFiles">
<echo message="Linting php files" />
<exec executable="bash" failonerror="true">
<arg value="-c" />
<arg value="echo '${files.modified}' | xargs -n 1 -P 4 php -l" />
</exec>
</target>
<!--
Just lint all files in parallel
------------------------------
If you want to lint all files, not only on modified one
-->
<target name="lint" description="Perform syntax check of sourcecode files">
<exec executable="bash" failonerror="true">
<arg value="-c" />
<arg value="find -L ${basedir}/src -name '*.php' -print0 | xargs -0 -n 1 -P 4 php -l" />
</exec>
</target>
@Rockstar04
Copy link

Can you think of any way to use this method with ants flag so this will only lint diffs? This is 100x faster for big commits to our master branch, but having to re-lint all files for small commits to our develop branch is actually slower.

@Rockstar04
Copy link

Sorry it filtered the tag

<modified />

@wa0x6e
Copy link
Author

wa0x6e commented Apr 3, 2013

Check it out, it should works.

You can also reuse the ${files.modified} variable elsewhere, it contains the list of modified files, and execute some task only if there are modified files, with if="modifiedFiles".

Only drawback of this method is that if the lint fail, and you miss it (not edit the file), and lint again, it will not show up, since it has been flagged as not modified since the last lint.

@longkey1
Copy link

longkey1 commented Apr 4, 2013

++

@porkaria
Copy link

thanks :)

One "bug", please remove "--" with comments...

build.xml:37: The string "--" is not permitted within comments.

@seyfer
Copy link

seyfer commented Oct 10, 2013

< modified / > do all work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment