Skip to content

Instantly share code, notes, and snippets.

@seanhagen
Last active December 28, 2015 03:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seanhagen/7437952 to your computer and use it in GitHub Desktop.
Save seanhagen/7437952 to your computer and use it in GitHub Desktop.
Template for Phing build files
<?xml version="1.0" encoding="UTF-8" ?>
<project name="==PROJECT NAME HERE==" basedir="." default="main">
<!--
This is a file that should be in the same directory as this file.
It defines some basic variables for use in this build file.
Some variables are required for each project, regardless of type:
version: defines the current version of your project.
branch: defines the default branch to build
url: should always be defined, but empty
urlBase: defines the base url to use for building urls
-->
<property file="project.properties" />
<!--
Dummy main target. If someone runs phing without specifying a target, this will be run.
-->
<target name="main" description="Dummy main target">
<echo>Main doesn't do anything, you need to specify a build task!</echo>
<echo>Use 'phing -l' to get a list of valid build targets.</echo>
</target>
<!-- needs to exist in every project -->
<target name="version-bump">
<phingcall target="-exec.grunt">
<property name="grunt-args" value="bumpup:${version}" />
</phingcall>
</target>
<!--
Build Targets
These targets may not be used by Jenkins, depending on the setup of the builds for your project.
However, these four targets will be used as a reference for how to proceed through building a project, so they always need
to be defined for each project.
-->
<target name="build-pr">
<echo>Pull Request built!</echo>
</target>
<target name="build-qa">
<echo>QA built!</echo>
</target>
<target name="build-dev">
<echo>Dev built!</echo>
</target>
<target name="build-prod">
<echo>Production built!</echo>
</target>
<!--
These two steps set up the environment to do a build or run tests.
Setting up the test environment may depend on the build environment being set up first.
-->
<target name="setup-envs" depends="setup-build-env,setup-test-env">
<echo>All environments setup</echo>
</target>
<target name="setup-build-env" depends="-setup.temp.dir,-setup.build-tmp.dir,-setup.build.dir">
<echo>Build environment setup properly!</echo>
</target>
<target name="setup-test-env" depends="-setup.temp.dir">
<echo>Test environment setup properly!</echo>
</target>
<target name="-setup.build-tmp.dir">
<delete dir="${phing.dir}/build-tmp" />
<mkdir dir="${phing.dir}/build-tmp" />
</target>
<target name="-setup.build.dir">
<delete dir="${phing.dir}/build" />
<mkdir dir="${phing.dir}/build" />
</target>
<target name="-setup.temp.dir">
<delete dir="${phing.dir}/tmp" />
<mkdir dir="${phing.dir}/tmp" />
</target>
<!--
This will run the full suite of unit and integration tests.
-->
<target name="test" depends="unit-tests-full,integration-tests-full"></target>
<!--
There are two suites of unit and integration tests.
The 'partial' suite are the tests relating to the branch you're working on, or smoke tests that are required to always run.
The 'full' suite is meant for testing by Jenkins when it does a CI build.
Unit tests test specific units of code. Integration tests should test the output of an API endpoint or the behavior of a webpage.
API projects should use Codeception for integration tests. Front-end projects should use Jasmine, Mocha, and Sinon.
-->
<target name="unit-tests-full"></target>
<target name="unit-tests-partial"></target>
<target name="integration-tests-full"></target>
<target name="integration-tests-partial"></target>
<!--
'analyze' will run the full suite of analysis tools, and can take quite a while
'analyze-quick' will run the faster tools, and can be used check each commit
-->
<target name="analyze" depends="setup-test-env,-phplint,-phploc,-pdepend,-phpcpd,-phpmd,-phpcs">
<echo>Full analysis complete!</echo>
</target>
<target name="analyze-quick" depends="setup-test-env,-phplint,-phploc,-phpcs">
<echo>Quick analysis completed!</echo>
</target>
<!-- PHP Lint -->
<target name="-phplint">
<phingcall target="-exec.grunt">
<property name="grunt-args" value="lint" />
</phingcall>
</target>
<!-- PHP Lines Of Code -->
<target name="-phploc">
<phingcall target="-exec.composer.vendor">
<property name="vendor-name" value="phploc" />
<property name="vendor-args" value="--progress --git-repository ../. --log-xml tmp/phploc.xml <path/to/your/project/src>" />
</phingcall>
</target>
<!-- PHP Depend; in depth analysis -->
<target name="-pdepend">
<phingcall target="-exec.composer.vendor">
<property name="vendor-name" value="pdepend" />
<property name="vendor-args" value="--jdepend-xml='tmp/app-pdepend.xml' --overview-pyramid='tmp/app-pdepend-pyramid.png' --summary-xml='tmp/app-pdepend-summary.xml' <path/to/your/project/src>" />
</phingcall>
</target>
<!-- PHP Mess Detector -->
<target name="-phpmd">
<phingcall target="-exec.grunt">
<property name="grunt-args" value="md" />
</phingcall>
</target>
<!-- PHP Copy-Paste Detector -->
<target name="-phpcpd">
<phingcall target="-exec.grunt">
<property name="grunt-args" value="cpd" />
</phingcall>
</target>
<!-- PHP Code Sniffer -->
<target name="-phpcs">
<phingcall target="-exec.grunt">
<property name="grunt-args" value="cs" />
</phingcall>
</target>
<!--
The following two targets may not be required by your project, but leave them in anyways.
Jenkins may require these targets to be present for some build flows
-->
<target name="compile"></target>
<target name="minify"></target>
<!--
'clean' resets the project back to the same state it'd be in if you had just checked out the project.
'clean-tmp' removes any build artifacts ( test data, compile output, etc ) from the project
-->
<target name="clean" depends="-remove.build,-remove.build-tmp,-remove.tmp">
<echo>All build artifacts removed!</echo>
</target>
<target name="clean-tmp" depends="-remove.build-tmp,-remove.tmp">
<echo>Temporary files removed!</echo>
</target>
<target name="-remove.tmp">
<delete dir="${phing.dir}/tmp" />
</target>
<target name="-remove.build-tmp">
<delete dir="${phing.dir}/build-tmp" />
</target>
<target name="-remove.build">
<delete dir="${phing.dir}/build" />
</target>
<!-- these are phing targets that are used by other tasks, to reduce the amount of copypasta -->
<target name="-exec.grunt">
<exec executable="${phing.dir}/node_modules/grunt-cli/bin/grunt"
passthru="true"
checkreturn="true">
<arg line="${grunt-args}" />
</exec>
</target>
<target name="-exec.composer.vendor">
<exec executable="${phing.dir}/bin/${vendor-name}"
passthru="true"
checkreturn="true">
<arg line="${vendor-args}" />
</exec>
</target>
</project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment