Skip to content

Instantly share code, notes, and snippets.

@NoodlesNZ
Last active August 29, 2015 14:24
Show Gist options
  • Save NoodlesNZ/ea5ab91c03f4dfb13ca0 to your computer and use it in GitHub Desktop.
Save NoodlesNZ/ea5ab91c03f4dfb13ca0 to your computer and use it in GitHub Desktop.
Jenkins phpcs
<?xml version="1.0" encoding="UTF-8"?>
<project name="projectname" default="build">
<!-- Check for checkstyle report from previous build -->
<available file="${basedir}/build/logs/checkstyle.xml" type="file"
property="phpcs.checkstyle.exists"/>
<target name="build"
depends="prepare,lint,tools-parallel"/>
<target name="tools-parallel" description="Run tools in parallel">
<parallel threadCount="2">
<!-- do other build targets (not included here)
<sequential>
<antcall target="pdepend"/>
<antcall target="phpmd-ci"/>
</sequential>
-->
<antcall target="phpcs-ci"/>
</parallel>
</target>
<target name="clean" depends="phpcs-prep" description="Cleanup build artifacts">
<delete dir="${basedir}/build/logs"/>
<delete dir="${basedir}/build/pdepend"/>
</target>
<target name="prepare" depends="clean"
description="Prepare for build">
<mkdir dir="${basedir}/build/logs"/>
<mkdir dir="${basedir}/build/pdepend"/>
</target>
<target name="lint" description="Perform syntax check of sourcecode files">
<apply executable="php" failonerror="true">
<arg value="-l" />
<fileset dir="${basedir}/public_html">
<include name="**/*.php" />
<modified />
</fileset>
</apply>
</target>
<target name="phpcs-prep" depends="phpcs-partial,phpcs-full" />
<target name="phpcs-partial" description="Partial phpcs runner" if="phpcs.checkstyle.exists">
<!-- Debugging message -->
<echo>Running Partial phpcs</echo>
<!-- Find changed files -->
<fileset dir="public_html/" id="phpcs.changedfiles">
<include name="**/*.php" />
<modified />
</fileset>
<!-- Find all files listed in the last checkstyle.xml report -->
<xmlproperty file="${basedir}/build/logs/checkstyle.xml"
collapseAttributes="true" delimiter=" "/>
<loadresource property="phpcs.checkstyle">
<propertyresource name="checkstyle.file.name"/>
<filterchain>
<tokenfilter>
<replacestring from="/var/" to="var/"/>
</tokenfilter>
</filterchain>
</loadresource>
<!-- Convert file list string to fileset -->
<!-- This removes files that don't exist on the file system -->
<fileset dir="/" id="phpcs.checkstylefiles" includes="${phpcs.checkstyle}"/>
<!-- Merge filesets -->
<union id="phpcs.files">
<resources refid="phpcs.changedfiles" />
<resources refid="phpcs.checkstylefiles" />
</union>
<!-- Convert merged file list to a string for phpcs -->
<pathconvert pathsep=" " property="phpcs.pathlist" refid="phpcs.files"/>
<!-- Change paths to relative -->
<loadresource property="phpcs.filelist">
<propertyresource name="phpcs.pathlist"/>
<filterchain>
<tokenfilter>
<replacestring from="${basedir}/" to=""/>
</tokenfilter>
</filterchain>
</loadresource>
</target>
<target name="phpcs-full" description="phpcs full runner" unless="phpcs.checkstyle.exists">
<property name="phpcs.filelist" value="${basedir}/public_html/"/>
</target>
<target name="phpcs-ci"
description="Find coding standard violations using PHP_CodeSniffer">
<exec executable="phpcs">
<arg value="--report=checkstyle" />
<arg value="--report-file=${basedir}/build/logs/checkstyle.xml" />
<arg value="--standard=PEAR" />
<arg value="--extensions=php" />
<arg line="${phpcs.filelist}" />
</exec>
</target>
</project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment