-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.xml
419 lines (359 loc) · 15.7 KB
/
build.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
<?xml version="1.0" encoding="UTF-8"?>
<!-- Rename this project to something relevant! -->
<project name="council-demo-ss3" 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>
Symbiote 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}/silverstripe-test-assist/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="silverstripe-test-assist/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" />
<delete file="${project.basedir}/framework/tests/travis/_config.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="silverstripe-test-assist/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>