Skip to content

Instantly share code, notes, and snippets.

@frne
Last active December 11, 2015 05:48
Show Gist options
  • Save frne/4554400 to your computer and use it in GitHub Desktop.
Save frne/4554400 to your computer and use it in GitHub Desktop.
Make your PHP Build Workflow Env-Independent

Make your PHP Build Workflow Env-Independent

Problem

One of the major problems we identified with our build workflow were the many dependencies to different qa-tools. So in case of we want to run PHPUnit, we had to ensure that on every system which runs the workflow, PEAR and PHPUnit have to be installed. Different versions of the tools do not make this problem easier...

Enforce people

We tried to enforce people to install the needed qa-tools on every system the build-workflow runs, but keeping all the systems up to date and the build running for over 20 Developers on different machines took to much time.

Automaticly install PEAR with dependent tools

We tried to run kind of a "bundled dependency manager" which downloads PEAR and installs it in a project subdirectory. After that, we installed all the tools needed via the recently downloaded PEAR installer. Theoretically, that worked really well, but there were too much problems with installation locations, file permissions, version differences and the build took four times longer to install all the PEAR stuff as we needed to run the tests and metrics.

Automaticly install all Dependencies with Composer

Our final solution was to install the dependent tools using composer. There are many advantages in using this packet manager to install the qa-tools:

  • No dependencies on the systems which execute the ant tasks
  • Automated setup for the qa-tools
  • Centralized bin directory
  • Locking for tool versions, so everyone use the same version of the tools

Setup

All we had to do, was adding a "require-dev":{} section to our existing composer configuration and changeing the build-targets to the vendor/bin/ directory from composer.

<?xml version="1.0" encoding="UTF-8"?>
<project name="build" default="phpunit">
<target name="phpunit" depends="composer-install">
<exec executable="vendor/bin/phpunit" failonerror="true">
<!-- include group unit -->
<arg line="--group unit"/>
<!-- arg for test directory -->
<arg value="./"/>
</exec>
</target>
<target name="composer-install" depends="-composer-download">
<exec executable="php">
<arg line="composer.phar install --dev"/>
</exec>
</target>
<target name="-composer-download" depends="-composer-check" unless="composer.available">
<exec executable="wget" failonerror="true">
<arg value="-nc" />
<arg value="http://getcomposer.org/composer.phar" />
</exec>
</target>
<target name="-composer-check">
<condition property="composer.available">
<available file="composer.phar"/>
</condition>
</target>
</project>
{
"require":{
"php":">=5.4.0"
},
"require-dev":{
"phpunit/phpunit": "3.7.10",
"pdepend/pdepend": "dev-master",
"phpmd/phpmd": "1.4.0",
"squizlabs/php_codesniffer": "1.4.3",
"phploc/phploc": "1.7.3"
},
"minimum-stability": "dev"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment