-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathbuild.xml
152 lines (123 loc) · 5.8 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
<?xml version="1.0" encoding="UTF-8"?>
<project name="php-circuit-breaker" default="ci" basedir=".">
<!-- ===================================== CUSTOM PROPERTIES =================================================== -->
<property name="product" value="php-circuit-breaker"/>
<property name="version" value="0.1.1"/>
<!-- ==================================== GENERIC PROPERTIES =================================================== -->
<tstamp>
<format property="build.time" pattern="yyyyMMdd-HHmmss" />
</tstamp>
<tstamp>
<format property="build.time.serial" pattern="yyyyMMddHHmmss" />
</tstamp>
<tstamp>
<format property="build.time.full" pattern="yyyy-MM-dd HH:mm:ss" />
</tstamp>
<property name="build.name" value="${product}-${version}-${build.time}" />
<!-- ======================================== PREPARATIONS ===================================================== -->
<target name="clean">
<delete dir="${basedir}/build" />
</target>
<target name="init">
<mkdir dir="${basedir}/build" />
<mkdir dir="${basedir}/build/logs" />
<mkdir dir="${basedir}/build/doc" />
<mkdir dir="${basedir}/build/coverage" />
<mkdir dir="${basedir}/build/dist" />
</target>
<target name="quick" depends="clean,init"/>
<!-- ========================================== COMPOSER ====================================================== -->
<target name="check-composer">
<available property="composer.phar.exists" file="composer.phar"/>
</target>
<target name="fetch-composer" depends="check-composer" unless="composer.phar.exists">
<exec executable="/bin/bash" failonerror="on">
<arg value="-c" />
<arg value="curl -s https://getcomposer.org/installer | php" />
</exec>
</target>
<target name="setup" depends="fetch-composer">
<exec executable="php" dir="${basedir}" failonerror="on">
<arg line="composer.phar update" />
</exec>
</target>
<!-- ============================================= FULL ======================================================== -->
<target name="phpunit" depends="quick">
<exec executable="phpunit" dir="${basedir}/tests" failonerror="on">
</exec>
<delete>
<fileset dir="/tmp" includes="unit-test*"/>
</delete>
</target>
<target name="phpunitExtended" depends="quick">
<exec executable="phpunit" dir="${basedir}/tests" failonerror="on">
<arg line="--configuration phpunit-extended.xml" />
</exec>
<delete>
<fileset dir="/tmp" includes="unit-test*"/>
</delete>
</target>
<target name="phpdoc" depends="quick">
<exec executable="phpdoc" dir="${basedir}" failonerror="off">
<arg line="-d src/ -t build/doc" />
</exec>
</target>
<!-- Depending on how we want to distribute/deploy code, we might want to build some type of release here -->
<!-- For now i think a tgz archive is a good start but we could consider some better way of packaging -->
<target name="package" depends="init">
<tar destfile="${basedir}/build/dist/${build.name}.tar.gz" compression="gzip" longfile="gnu">
<tarfileset dir="${basedir}">
<include name="*/**" />
<exclude name="**/.git/**"/>
<exclude name=".gitignore" />
<exclude name="tests/"/>
<exclude name="build/" />
<exclude name="build.xml" />
</tarfileset>
</tar>
</target>
<!-- print coverage -->
<target name="print-code-coverage">
<exec executable="bash" dir="${basedir}" failonerror="off" >
<arg value="-c" />
<arg value="cat build/logs/clover.xml | awk '/files/ {lines = $10; covered = $11; gsub(/[^0-9]*/, "", lines); gsub(/[^0-9]*/, "", covered); coverage = (covered * 100) / lines; printf "Total code coverage: %.2f %%", coverage}'" />
</exec>
</target>
<!-- ======================================== GIT RELATED ====================================================== -->
<target name="git-check-status">
<exec executable="/bin/bash" failonerror="on" outputproperty="git-status-not-empty">
<arg value="-c" />
<arg value="git status -s" />
</exec>
</target>
<target name="git-fetch-tags">
<exec executable="/bin/bash" failonerror="on">
<arg value="-c" />
<arg value="git fetch --tags" />
</exec>
</target>
<target name="git-create-tag" depends="git-check-status">
<fail message="Can not tag a dirty folder. Commit or revert first.">
<condition>
<not>
<equals arg1="${git-status-not-empty}" arg2=""/>
</not>
</condition>
</fail>
<exec executable="/bin/bash" failonerror="on">
<arg value="-c" />
<arg value="git tag -m 'taggin ${version}' ${version}" />
</exec>
</target>
<target name="git-push-tags">
<exec executable="/bin/bash" failonerror="on">
<arg value="-c" />
<arg value="git push --tags" />
</exec>
</target>
<target name="git-tag" depends="git-fetch-tags,git-create-tag,git-push-tags"/>
<!-- ===================================== COMPOUND SHORTCUTS ================================================== -->
<target name="ci" depends="phpunitExtended,phpdoc,print-code-coverage"/>
<!-- reload dependencies and run full CI build -->
<target name="full" depends="setup,phpunitExtended,phpdoc,package,print-code-coverage"/>
</project>