Skip to content

Instantly share code, notes, and snippets.

@nblair
Created November 30, 2015 20:14
Show Gist options
  • Save nblair/7324476b8045cec456c2 to your computer and use it in GitHub Desktop.
Save nblair/7324476b8045cec456c2 to your computer and use it in GitHub Desktop.
Phing build file for publishing snapshot build to any Maven artifact repository
<project name="project-name" default="main">
<!-- Global Build Properties -->
<property file="build.properties" />
<property name="repository.blessed" value="[email protected]:group/project-name.git" override="false" />
<property name="targetDir" value="target" override="true" />
<property name="releaseFilename" value="project-name.tar.gz" override="true" />
<property name="phpunit.coverage" value="false" />
<property name="maven.executable" value="mvn" override="true" />
<property name="project.version" value="1.0.0-SNAPSHOT"/>
<!-- Updates composer, updates all dependencies, dumps autoload classes -->
<target name="main" depends="composer-update, bower-install, phpunit, build-properties" />
<!-- Updates composer dependencies -->
<target name="composer-update" depends="get-composer">
<exec command="php composer.phar update" passthru="true" checkreturn="true" />
</target>
<target name="composer-install-no-dev" depends="get-composer">
<exec command="php composer.phar install --no-dev" passthru="true" checkreturn="true" />
</target>
<!-- Downloads composer.phar -->
<target name="get-composer">
<if>
<not>
<available file="composer.phar" />
</not>
<then>
<echo msg="composer.phar not found. Downloading..." />
<httpget url="https://getcomposer.org/composer.phar" dir="." sslVerifyPeer="false"/>
</then>
<else>
<echo msg="composer.phar already exists" />
</else>
</if>
</target>
<!-- Runs PHPUnit tests -->
<target name="phpunit" depends="composer-update">
<property name="phpunit.opts.withCoverage" value="" />
<if>
<equals arg1="${phpunit.coverage}" arg2="true" />
<then>
<property
name="phpunit.opts.withCoverage"
value="--coverage-clover reports/phpunit.coverage.xml --coverage-html reports/phpunit.coverage" override="true"
/>
</then>
</if>
<exec command="php vendor/phpunit/phpunit/phpunit ${phpunit.opts.withCoverage}" dir="." passthru="true"
checkreturn="true" />
</target>
<!-- Bower -->
<target name="bower-install">
<exec command="bower --config.interactive=false install" dir="." passthru="true" checkreturn="true" />
</target>
<target name="clean">
<delete dir="target"/>
<delete dir="vendor"/>
</target>
<target name="archive" depends="main, clean, composer-install-no-dev" description="Package a deployable tarball artifact">
<copy todir="${targetDir}" includeemptydirs="true" >
<fileset dir="." defaultexcludes="true">
<include name="bootstrap/**" />
<include name="source/**" />
<include name="buildNumbers.properties" />
<exclude name="html/phpinfo.php" />
</fileset>
</copy>
<tar destfile="${targetDir}/${releaseFilename}" compression="gzip" >
<fileset dir="${targetDir}">
<exclude name="site-configuration.ini"/>
</fileset>
</tar>
</target>
<target name="publish" depends="clean,archive" description="Publish artifact to Maven repository">
<exec
dir="${targetDir}"
passthru="true"
checkreturn="true"
command="${maven.executable} deploy:deploy-file
-DgroupId=edu.yourorganization
-DartifactId=project-name
-Dversion=${project.version}
-Dpackaging=tar.gz
-Dfile=${releaseFilename}
-DrepositoryId=your-internal-snapshots
-Durl=https://repository.yourorganization.edu/maven/content/repositories/internal-snapshots/
"
/>
</target>
<target name="build-properties" >
<!-- simple script to interact with git to record project revision information -->
<exec command="php buildNumbers.php" passthru="true" checkreturn="true"/>
</target>
</project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment