Last active
February 2, 2025 02:20
-
-
Save wa0x6e/3035117 to your computer and use it in GitHub Desktop.
Faster php lint target for jenkins php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
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> |
Sorry it filtered the tag
<modified />
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.
++
thanks :)
One "bug", please remove "--" with comments...
build.xml:37: The string "--" is not permitted within comments.
< modified / > do all work
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.