Skip to content

Instantly share code, notes, and snippets.

@nblair
Created October 9, 2015 15:52
Show Gist options
  • Save nblair/345692c79d673c7edee5 to your computer and use it in GitHub Desktop.
Save nblair/345692c79d673c7edee5 to your computer and use it in GitHub Desktop.
An analogue to the Maven release process using Phing for PHP.
<project name="some-php-project" default="main">
<!-- this script requires http://pear.php.net/package/VersionControl_Git and https://pear.php.net/package/HTTP_Request2/ -->
<!-- build.properties needs to contain 'nexus.username' and 'nexus.password' properties, MUST be .gitignore'd -->
<property file="build.properties" />
<property name="primary.repository" value="[email protected]:group/some-php-project.git" override="false" />
<property name="targetDir" value="target" override="true" />
<property name="groupId" value="com/company/some-php-project" override="false"/>
<property name="repositoryHost" value="https://someartifactrepo.company.com" override="false"/>
<target name="clean">
<delete dir="${targetDir}" failonerror="false"/>
</target>
<!-- Clones the primary repository into a temporary location -->
<target name="release-clone" description="Clones the primary repository into a temporary directory" depends="clean">
<gitclone repository="${primary.repository}" targetPath="${targetDir}/some-php-project" />
</target>
<!-- Creates a new version tag in the primary repository -->
<target name="prepare" depends="release-clone" description="Creates a release tag in the remote repository">
<!-- branch defaults to master if not specified -->
<property name="branch" value="master" override="true" />
<gitcheckout repository="${targetDir}/some-php-project" branchname="${branch}" />
<gittag repository="${targetDir}/some-php-project" name="${version}" force="true" />
<gitpush repository="${targetDir}/some-php-project" tags="true" force="true" />
</target>
<!-- Releases a version to artifact repository -->
<target name="release" depends="release-clone" description="Clones primary repository into temporary directory, checks out a release tag, and uploads to artifact repository">
<property name="releaseFilename" value="${phing.project.name}-${version}.tar.gz" />
<gitcheckout repository="${targetDir}/some-php-project" branchname="${version}" />
<!-- simple script to export git and project version into a properties file, included in the project -->
<exec dir="${targetDir}/some-php-project" command="php buildNumbers.php" passthru="true" checkreturn="true"/>
<tar destfile="${targetDir}/${releaseFilename}" compression="gzip" >
<!-- src/site contains the site code -->
<fileset dir="${targetDir}/some-php-project/src/site">
<exclude name="configuration.ini"/>
</fileset>
</tar>
<exec dir="${targetDir}" passthru="true" checkreturn="true"
command="curl -v --fail -X PUT -u ${nexus.username}:${nexus.password} --upload-file ${releaseFilename} ${repositoryHost}/maven/content/repositories/private-releases/${groupId}/${version}/${releaseFilename}" />
</target>
</project>
@nblair
Copy link
Author

nblair commented Oct 9, 2015

Credit to @ahoffmann-wi for the development of the technique!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment