Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
419 lines (358 sloc) 15.6 KB
<?xml version="1.0" encoding="UTF-8"?>
<!-- Rename this project to something relevant! -->
<project name="mikenovember" default="build">
<tstamp>
<format property="FULLDTIME" pattern="%Y%m%d%H%M%S" />
</tstamp>
<!-- Make sure properties are in existence -->
<available file="${project.basedir}/build/build.properties" property="properties_exist" />
<!-- Has the modules file been created? -->
<available file="${modules.depends.file}" property="modules_file_exists" />
<!-- have we been installed? -->
<available file="${project.basedir}/mysite/local.conf.php" property="installed" />
<property file="${project.basedir}/build/build.properties"></property>
<php expression="trim(file_get_contents('${module.name}/VERSION'))" returnProperty="module.version" />
<if>
<isset property="env.BUILD_NUMBER" />
<then>
<property name="BUILD_STAMP" value="${env.BUILD_NUMBER}" />
</then>
<else>
<property name="BUILD_STAMP" value="${DSTAMP}" />
</else>
</if>
<echo>Creating build ${BUILD_STAMP}</echo>
<!-- Load in the custom tasks -->
<taskdef name="symlink" classname="build.SymlinkTask" classpath="${project.basedir}" />
<taskdef name="copyfolders" classname="build.CopyFoldersTask" classpath="${project.basedir}" />
<taskdef name="sstest" classname="build.SilverStripeTestTask" classpath="${project.basedir}" />
<taskdef name="ssmodules" classname="build.LoadModulesTask" classpath="${project.basedir}" />
<taskdef name="sspatches" classname="build.ApplyPatchesTask" classpath="${project.basedir}" />
<taskdef name="ssdeploy" classname="build.SilverStripeDeployTask" classpath="${project.basedir}" />
<target name="help">
<echo>
SilverStripe Australia Project Build
------------------------------------
This build file contains targets to assist in creating new SilverStripe project builds.
* Delete the .git directory! You'll eventually add this project to a new location, meaning it is unnecessary to keep the existing git info
* Edit this build file and change the project name from rename-me to something more accurate
* Copy the build/build.properties.sample file to build/build.properties
* Edit that file and make any necessary adjustments. In particular, change the rewrite.base variable to match your webroot
* Edit the build/dependent-modules and add in any additional modules you may need. The format for these is
** modulename git|svn.url (the SCM url to retrieve this module) true|false (whether to run dev/build after fetching)
* Run phing, which will fetch all needed modules and run a dev/build for the first time
* Visit http://localhost/pathname/dev/build to ensure all caches are built correctly for the web
Important targets
* build - Retrieves all dependent modules (or updates them if they already exist), applies any relevant patches, and runs dev/build
* test - Executes all unit tests. You can run tests just for a single module by passing a module name, ie phing test -Dmodule=mysite. You can
also optionally pass a single test case to run, eg phing test -Dmodule=mysite -Dtestcase=MyTest
* phing-package - Creates a complete copy of this development environment repository that can be passed to another person, retaining all SVN and Git information
* update-package - Creates a package that excludes several diretories that can be used for extracting over the top of existing installs
* themes-package - Creates a package that contains only the themes dir. This will take the whole themes folder and not attempt to understand changes.
* backup - Takes a database dump of the site before packaging
Other features
* In some cases you will want to provide custom patches to dependent modules. As these can't be committed back to this project's repository,
a mechanism exists to include just the .patch diffs. Drop any diffs into build/patches, and these will be applied during the build target.
</echo>
</target>
<target name="init" depends="non_interactive,check_properties">
<mkdir dir="${build.output.dir}" />
</target>
<!-- Load modules where sensitive dependency exists -->
<target name="update_modules" depends="create_modules_file">
<ssmodules file="${modules.depends.file}" noninteractive="${ni_build}"/>
</target>
<target name="update-composer">
<if>
<available file="composer.json" />
<then>
<if>
<not><available file="composer.phar" /></not>
<then>
<exec command="curl -s http://getcomposer.org/installer | php" passthru="true" />
</then>
</if>
<exec command="php composer.phar install" passthru="true" />
</then>
</if>
</target>
<target name="create_modules_file" unless="modules_file_exists">
<copy file="${modules.depends.file}.default" tofile="${modules.depends.file}" />
</target>
<!--
Add a new module to the system. Run from the commandline, you can pass
in the details of the module as phing add_module -Dmodule=blog -Dmodurl=http://path/to/svn
-->
<target name="add_module">
<ssmodules name="${module}" url="${modurl}" />
</target>
<!-- Ensures the build.properties file exists! -->
<target name="check_properties" unless="properties_exist">
<!-- create a default file only if it doesn't exist -->
<copy tofile="${project.basedir}/build/build.properties" file="${project.basedir}/build/build.properties.sample" />
<property file="${project.basedir}/build/build.properties"></property>
<!-- <fail>!!Please create the build/build.properties file before continuing!!</fail> -->
</target>
<!-- A target that gets executed if the 'ni_build' parameter is set. This is done when
the build is executed from a CI container -->
<target name="non_interactive" if="ni_build">
<!-- we'll make sure that there's a build.properties file, even if we're just using the default -->
<delete file="${project.basedir}/build/build.properties" />
<copy tofile="${project.basedir}/build/build.properties" file="${project.basedir}/build/build.properties.sample" />
<delete dir="assets" />
<delete file="${project.basedir}/mysite/local.conf.php" />
<delete file="${project.basedir}/mysite/_config/local.yml" />
<delete file="${project.basedir}/ssautesting/testing.conf.php" />
<property name="properties_exist" value="true" override="true" />
<property file="${project.basedir}/build/build.properties"></property>
</target>
<!-- Installs a freshly checked-out silverstripe project -->
<target name="build" depends="init">
<!-- if it doesn't exist, create it and the default .htaccess -->
<mkdir dir="assets" />
<echo file="assets/.htaccess" append="false">
RemoveHandler .php .phtml .php3 .php4 .php5 .inc
RemoveType .php .phtml .php3 .php4 .php5 .inc
</echo>
<echo file="mysite/BUILD_NUMBER" append="false">Build ${BUILD_STAMP}</echo>
<!-- Copy the DB configs -->
<copy tofile="mysite/local.conf.php" file="${local.php.config}" overwrite="false">
<filterchain>
<expandproperties />
</filterchain>
</copy>
<copy tofile="mysite/_config/local.yml" file="${local.yml.config}" overwrite="false">
<filterchain>
<expandproperties />
</filterchain>
</copy>
<!-- Copy the configs to be used for testing. Set the required variables in the build.properties file -->
<copy tofile="ssautesting/testing.conf.php" file="${testing.config}" overwrite="false">
<filterchain>
<expandproperties />
</filterchain>
</copy>
<!-- Copy the htaccess -->
<copy tofile=".htaccess" file="${htaccess.config}" overwrite="true">
<filterchain>
<expandproperties />
</filterchain>
</copy>
<phingcall target="update_modules" />
<phingcall target="update-composer" />
<phingcall target="apply_patches" />
<!-- Trigger /dev/build for the new system -->
<exec command="php framework/cli-script.php dev/build"></exec>
</target>
<target name="apply_patches">
<mkdir dir="${patches.dir}" />
<sspatches patchdir="${patches.dir}" />
</target>
<!-- Create a deployable package to use as the base for installing a new site FROM SCRATCH.
Please use the update-package target for creating a package to use for an update -->
<target name="package" depends="init">
<property name="currentpackage" value="${build.output.dir}/${package.name}" />
<property name="packagetype" value="deploy" />
<phingcall target="archive-package" />
<tar destfile="${build.output.dir}/${package.name}" compression="gzip">
<fileset dir="${project.basedir}">
<include name="**/**" />
<exclude name="silverstripe-cache/" />
<exclude name="sitemap.xml" />
<exclude name="google*.html" />
<exclude name="assets/**" />
<exclude name="build/**" />
<exclude name="build.xml" />
<exclude name="mysite/local.conf.php" />
<exclude name="mysite/_config/local.yml" />
<exclude name="mysite/db.conf.php" />
<exclude name="mysite/*.log" />
<exclude name="**/.svn/**" />
<exclude name="**/.git/**" />
<exclude name="nbproject/**" />
<exclude name="**/.gitignore" />
<exclude name=".htaccess" />
<exclude name="**/.project" />
<exclude name="**/.buildpath" />
<exclude name="**/.settings" />
<exclude name="phpunit.*" />
</fileset>
</tar>
</target>
<!-- a package that includes all items that the phing build normally downloads, which can
be just extracted over the top of whatever is pulled out of git. This preserves all the
.svn files for dependent modules etc -->
<target name="phing-package" depends="">
<property name="currentpackage" value="${build.output.dir}/${phing-package.name}" />
<property name="packagetype" value="development" />
<phingcall target="archive-package" />
<!-- make sure we're on master... hudson kinda screws this up! -->
<exec command="git branch ${git.branch}"></exec> <!-- this might cause a fatal, but that's okay... -->
<exec command="git checkout ${git.branch}"></exec>
<exec command="git pull origin ${git.branch}"></exec>
<tar destfile="${build.output.dir}/${phing-package.name}" compression="gzip" defaultexcludes="false">
<fileset dir="${project.basedir}">
<include name="**/**" />
<exclude name="sitemap.xml" />
<exclude name="google*.html" />
<exclude name="silverstripe-cache/" />
<exclude name="build/archive/**" />
<exclude name="nbproject/**" />
<exclude name="**/.project" />
<exclude name="**/.buildpath" />
<exclude name="**/.settings" />
</fileset>
</tar>
<chmod file="${build.output.dir}/${phing-package.name}" mode="0664" />
</target>
<!-- A package that doesn't include files that are commonly overridden
on remote sites -->
<target name="update-package">
<property name="currentpackage" value="${build.output.dir}/${update-package.name}" />
<property name="packagetype" value="update" />
<phingcall target="archive-package" />
<tar destfile="${build.output.dir}/${update-package.name}" compression="gzip" includeemptydirs="false">
<fileset dir="${project.basedir}">
<include name="**/**" />
<exclude name="sitemap.xml" />
<exclude name="google*.html" />
<exclude name="mysite/db.conf.php" />
<exclude name="mysite/local.conf.php" />
<exclude name="mysite/_config/local.yml" />
<exclude name="mysite/*.log" />
<exclude name="build/**" />
<exclude name="build.xml" />
<exclude name="_ss_environment.php" />
<exclude name=".htaccess" />
<exclude name="**/.svn/**" />
<exclude name="nbproject/**" />
<exclude name="**/.project" />
<exclude name="**/.buildpath" />
<exclude name="**/.settings" />
<exclude name="**/.git/**" />
<exclude name="phpunit.*" />
<exclude name="assets/**" />
<exclude name="cms/**" />
<exclude name="framework/**" />
<exclude name="silverstripe-cache/" />
</fileset>
</tar>
<chmod file="${build.output.dir}/${update-package.name}" mode="0664" />
</target>
<!-- A package that includes only the themes files -->
<target name="themes-package">
<property name="currentpackage" value="${build.output.dir}/${themes-package.name}" />
<property name="packagetype" value="themes" />
<phingcall target="archive-package" />
<tar destfile="${build.output.dir}/${themes-package.name}" compression="gzip">
<fileset dir="${project.basedir}">
<include name="**/themes**" />
</fileset>
</tar>
<chmod file="${build.output.dir}/${themes-package.name}" mode="0664" />
</target>
<target name="package-module">
<property name="currentpackage" value="${module.file}" />
<property name="packagetype" value="module" />
<phingcall target="archive-package" />
<echo file="${module.name}/BUILD_NUMBER" append="false">Build ${BUILD_STAMP}</echo>
<mkdir dir="${build.output.dir}" />
<delete file="${module.file}" />
<tar destfile="${module.file}" compression="gzip">
<fileset dir="${project.basedir}">
<include name="${module.name}/**" />
<exclude name="**/.svn/" />
<exclude name="**/.git/" />
</fileset>
</tar>
</target>
<!-- Creates a backup of the existing project, including the MySQL dump -->
<target name="backup">
<echo file="README.txt" append="false">
To restore this backup:
* Import the database file in backups/${phing.project.name}.sql
* Copy configs/silverstripe/local.conf.php.sample to mysite/local.conf.php
* Edit DB settings in local.conf as appropriate (typically, use MySQLDatabase as the db.type)
* Run 'php framework/cli-script.php dev/build'
</echo>
<mkdir dir="${backup.dir}" />
<echo file="${backup.dir}/.htaccess" append="false">
Deny from all
</echo>
<exec command="mysqldump -u${db.user} -p${db.pass} ${db.name} > ${backup.sql}"></exec>
<phingcall target="package" />
</target>
<target name="ci_test" depends="build">
<!-- lets get rid of files that we don't want tested -->
<delete file="${project.basedir}/framework/tests/WebserverRoutingTest.php" />
<phingcall target="test" />
</target>
<!-- Execute all the test cases -->
<target name="test">
<!-- Make sure the log directory exists -->
<mkdir dir="${testing.logdir}" />
<mkdir dir="assets" />
<!-- Copy the configs - done so that we can override the reporter type from an exernal source -->
<copy tofile="ssautesting/testing.conf.php" file="${testing.config}" overwrite="false">
<filterchain>
<expandproperties />
</filterchain>
</copy>
<exec command="php framework/cli-script.php dev/build"></exec>
<sstest module="${module}" testcase="${testcase}" />
</target>
<target name="archive-package">
<copy todir="${build.archive.dir}">
<fileset dir="${build.output.dir}">
<include name="*-${packagetype}*.tar.gz" />
</fileset>
</copy>
<!-- delete all similar files from the output -->
<delete>
<fileset dir="${build.output.dir}">
<include name="*-${packagetype}*.tar.gz" />
</fileset>
</delete>
</target>
<target name="deploy">
<if>
<isset property="deploy.incremental" />
<then>
<phingcall target="update-package" />
</then>
<else>
<phingcall target="package" />
</else>
</if>
<foreach list="${deploy.targets}" param="deptarget" target="deploy-target" />
</target>
<target name="deploy-target">
<if>
<isset property="deploy.incremental" />
<then>
<property name="deploy.package" value="${update-package.name}" />
</then>
<else>
<property name="deploy.package" value="${package.name}" />
</else>
</if>
<ssdeploy
username="${deploy.${deptarget}.user}"
password="${deploy.${deptarget}.pass}"
pubkeyfile="${deploy.${deptarget}.pubkey}"
privkeyfile="${deploy.${deptarget}.privkey}"
host="${deploy.${deptarget}.host}"
port="${deploy.${deptarget}.port}"
ignoreerrors="${deploy.first}"
incremental="${deploy.incremental}"
localpath="${build.output.dir}"
remotepath="${deploy.${deptarget}.path}"
package="${deploy.package}"
apachegroup="${deploy.${deptarget}.apache-group}"
/>
</target>
<target name="clean">
<mkdir dir="${build.output.dir}" />
<delete file="${database_dump.name}"></delete>
</target>
</project>
Something went wrong with that request. Please try again.