source: iPeer/build.xml

dev
Last change on this file was 75a5dd9, checked in by Compass <pan.luo@…>, 4 years ago

Remove system test from test-ci task

System test will be run as a separate Jenkins job

  • Property mode set to 100644
File size: 14.1 KB
Line 
1<?xml version="1.0" encoding="UTF-8"?>
2
3<project name="iPeer" basedir="." default="build">
4
5    <target name="load-db-config">
6        <phingcall target="pre-test"/>
7        <loadfile property="dbfile" file="app/config/database.php">
8            <filterchain>
9                <stripphpcomments />
10                <linecontainsregexp>
11                        <regexp pattern="^((?!\?php).)*$" />
12                </linecontainsregexp>
13                <replaceregexp>
14                    <regexp pattern="public" replace="public static"/>
15                </replaceregexp>
16            </filterchain>
17        </loadfile>
18        <php expression="${dbfile}"/>
19        <php expression="DATABASE_CONFIG::$default['driver']" returnProperty="db.driver"/>
20        <php expression="DATABASE_CONFIG::$default['host']"   returnProperty="db.host"/>
21        <php expression="DATABASE_CONFIG::$default['login']"  returnProperty="db.username"/>
22        <php expression="DATABASE_CONFIG::$default['password']" returnProperty="db.password"/>
23        <php expression="DATABASE_CONFIG::$default['database']" returnProperty="db.name"/>
24    </target>
25
26    <target name="build"
27        depends="prepare,lint,phploc,pdepend,phpmd,phpcs,phpcpd,phpdoc,test,phpcb"/>
28
29    <target name="build-ci"
30        depends="prepare,lint,phploc,pdepend,phpmd-ci,phpcs-ci,phpcpd,phpdoc,test-ci,phpcb"/>
31
32    <target name="clean" description="Cleanup build artifacts">
33        <delete dir="${project.basedir}/build/api"/>
34        <delete dir="${project.basedir}/build/code-browser"/>
35        <delete dir="${project.basedir}/build/coverage"/>
36        <delete dir="${project.basedir}/build/logs"/>
37        <delete dir="${project.basedir}/build/pdepend"/>
38        <delete dir="${project.basedir}/dist"/>
39    </target>
40
41    <target name="prepare" depends="clean"
42        description="Prepare for build">
43        <mkdir dir="${project.basedir}/build/api"/>
44        <mkdir dir="${project.basedir}/build/code-browser"/>
45        <mkdir dir="${project.basedir}/build/coverage"/>
46        <mkdir dir="${project.basedir}/build/logs"/>
47        <mkdir dir="${project.basedir}/build/pdepend"/>
48        <!-- Needed to enable the API controller tests -->
49        <!-- make ipeer seem to be installed -->
50        <touch file="${project.basedir}/app/tmp/installed.txt" />
51        <!-- let Apache write to cache -->
52        <exec command="chmod -R 777 ${project.basedir}/app/tmp"/>
53    </target>
54
55    <target name="init-test-db" depends="load-db-config">
56        <pdosqlexec url="${db.driver}:host=${db.host};dbname=${db.name}" userid="${db.username}" password="${db.password}">
57            <transaction src="app/config/sql/ipeer_samples_data.sql"/>
58        </pdosqlexec>
59        <!--<exec command="cake/console/cake schema_ci create DbAcl" passthru="true"/>-->
60    </target>
61
62    <target name="lint">
63        <phplint haltonfailure="true" cachefile="${project.basedir}/build/lint.cache">
64            <fileset dir="${project.basedir}/app">
65                <include name="**/*.php" />
66            </fileset>
67        </phplint>
68    </target>
69
70    <target name="phploc" description="Measure project size using PHPLOC">
71        <exec executable="phploc">
72            <arg value="--log-csv" />
73            <arg value="${project.basedir}/build/logs/phploc.csv" />
74            <arg path="${project.basedir}/app" />
75        </exec>
76    </target>
77
78    <target name="pdepend"
79        description="Calculate software metrics using PHP_Depend">
80        <phpdepend>
81            <fileset dir="${project.basedir}/app">
82                <include name="**/*.php" />
83                <exclude name="tests/**" />
84                <exclude name="vendors/**" />
85                <exclude name="plugins/**" />
86                <exclude name="config/**" />
87                <exclude name="webroot/**" />
88            </fileset>
89            <logger type="jdepend-xml" outfile="${project.basedir}/build/logs/jdepend.xml" />
90            <logger type="jdepend-chart" outfile="${project.basedir}/build/pdepend/dependencies.svg" />
91            <logger type="overview-pyramid" outfile="${project.basedir}/build/pdepend/overview-pyramid.svg" />
92        </phpdepend>
93    </target>
94
95    <target name="phpmd"
96        description="Perform project mess detection using PHPMD and print human readable output. Intended for usage on the command line before committing.">
97        <phpmd rulesets="codesize,unusedcode">
98            <fileset dir="${project.basedir}/app">
99                <include name="**/*.php" />
100                <exclude name="tests/**" />
101                <exclude name="vendors/**" />
102                <exclude name="plugins/**" />
103                <exclude name="config/**" />
104                <exclude name="webroot/**" />
105            </fileset>
106        </phpmd>
107    </target>
108
109    <target name="phpmd-ci"
110        description="Perform project mess detection using PHPMD creating a log file for the continuous integration server">
111        <phpmd rulesets="codesize,unusedcode">
112            <fileset dir="${project.basedir}/app">
113                <include name="**/*.php" />
114                <exclude name="tests/**" />
115                <exclude name="vendors/**" />
116                <exclude name="plugins/**" />
117                <exclude name="config/**" />
118                <exclude name="webroot/**" />
119            </fileset>
120            <formatter type="xml" outfile="${project.basedir}/build/logs/pmd.xml"/>
121        </phpmd>
122    </target>
123
124    <target name="phpcs"
125        description="Find coding standard violations using PHP_CodeSniffer and print human readable output. Intended for usage on the command line before committing.">
126        <phpcodesniffer standard="${project.basedir}/build/phpcs.xml">
127            <fileset dir="${project.basedir}/app">
128                <include name="**/*.php" />
129                <exclude name="tests/**" />
130                <exclude name="vendors/**" />
131                <exclude name="plugins/**" />
132                <exclude name="config/**" />
133                <exclude name="webroot/**" />
134            </fileset>
135        </phpcodesniffer>
136    </target>
137
138    <target name="phpcs-ci"
139        description="Find coding standard violations using PHP_CodeSniffer creating a log file for the continuous integration server">
140        <phpcodesniffer standard="${project.basedir}/build/phpcs.xml">
141            <fileset dir="${project.basedir}/app">
142                <include name="**/*.php" />
143                <exclude name="tests/**" />
144                <exclude name="vendors/**" />
145                <exclude name="plugins/**" />
146                <exclude name="config/**" />
147                <exclude name="webroot/**" />
148            </fileset>
149            <formatter type="checkstyle" outfile="${project.basedir}/build/logs/checkstyle.xml" />
150        </phpcodesniffer>
151    </target>
152
153    <target name="phpcpd" description="Find duplicate code using PHPCPD">
154        <phpcpd>
155            <fileset dir="${project.basedir}/app">
156                <include name="**/*.php" />
157                <exclude name="tests/**" />
158                <exclude name="vendors/**" />
159                <exclude name="plugins/**" />
160                <exclude name="config/**" />
161                <exclude name="webroot/**" />
162            </fileset>
163            <formatter type="pmd" outfile="${project.basedir}/build/logs/pmd-cpd.xml" />
164        </phpcpd>
165    </target>
166
167    <target name="phpdoc"
168        description="Generate API documentation using PHPDocumentor">
169        <phpdoc destdir="${project.basedir}/build/api" output="HTML:Smarty:PHP" sourcecode="false" >
170            <fileset dir="${project.basedir}/app">
171                <include name="**/*.php" />
172                <exclude name="tests/**" />
173                <exclude name="vendors/**" />
174                <exclude name="plugins/**" />
175                <exclude name="config/**" />
176                <exclude name="webroot/**" />
177            </fileset>
178        </phpdoc>
179    </target>
180
181    <target name="pre-test" description="prepare to run tests">
182        <copy file="app/config/database.php.default" tofile="app/config/database.php" overwrite="false"/>
183        <copy file="app/plugins/guard/config/guard.php" tofile="app/config/guard.php" overwrite="false"/>
184        <copy file="app/config/database.php" tofile="app/config/database_test_backup.php" overwrite="true"/>
185        <if>
186            <!-- set up database name for Jenkins. Using different db name for different job to avoid conflict when running simultaneously -->
187            <isset property="env.JOB_NAME"/>
188            <then>
189                <reflexive file="app/config/database.php">
190                    <filterchain>
191                        <replaceregexp>
192                            <regexp pattern="'database'.*=>.*'(.*)'" replace="'database'  => '${env.JOB_NAME}'"/>
193                        </replaceregexp>
194                    </filterchain>
195                </reflexive>
196            </then>
197            <else>
198                <reflexive file="app/config/database.php">
199                    <filterchain>
200                        <replaceregexp>
201                            <regexp pattern="'database'.*=>.*'(.*)'" replace="'database'  => '\1_test'"/>
202                        </replaceregexp>
203                    </filterchain>
204                </reflexive>
205            </else>
206        </if>
207    </target>
208
209    <target name="post-test" description="clean up after running tests">
210        <move file="app/config/database_test_backup.php" tofile="app/config/database.php" overwrite="true"/>
211        <chmod file="app/tmp" mode="0777"/>
212    </target>
213
214    <target name="test" description="Run unit tests" depends="init-test-db">
215        <exec command="sh cake/console/cake -app app testsuite app group model" passthru="true"/>
216        <exec command="sh cake/console/cake -app app testsuite app group controller" passthru="true"/>
217        <!-- v1_controller test must be last one as it will change the database -->
218        <phingcall target="post-test"/>
219    </target>
220
221    <target name="test-win" description="Run unit tests" depends="prepare,init-test-db">
222        <exec command="cake\console\cake.bat -app app testsuite app group component" passthru="true"/>
223        <exec command="cake\console\cake.bat -app app testsuite app group model" passthru="true"/>
224        <exec command="cake\console\cake.bat -app app testsuite app group controller" passthru="true"/>
225        <!-- v1_controller test must be last one as it will change the database -->
226        <phingcall target="post-test"/>
227    </target>
228
229    <target name="test-ci" description="Run unit tests for continuous integration(output as xml)" depends="init-test-db">
230        <exec command="cake/console/cake testreport app group model" passthru="true"/>
231        <exec command="cake/console/cake testreport app group controller" passthru="true"/>
232        <!-- <exec command="cake/console/cake testreport app group system" passthru="true"/> -->
233        <!-- v1_controller test must be last one as it will change the database -->
234        <phingcall target="post-test"/>
235    </target>
236
237    <target name="test-ci-integration" description="Run integration tests for continuous integration(output as xml)" depends="prepare,init-test-db">
238        <exec command="cake/console/cake testreport app group system" passthru="true"/>
239        <phingcall target="post-test"/>
240    </target>
241
242    <target name="upgrade" description="Upgrade iPeer">
243        <exec command="cake/console/cake upgrade" passthru="true"/>
244    </target>
245
246    <target name="phpcb"
247        description="Aggregate tool output with PHP_CodeBrowser">
248        <exec executable="phpcb">
249            <arg value="--log" />
250            <arg path="${project.basedir}/build/logs" />
251            <arg value="--source" />
252            <arg path="${project.basedir}/app" />
253            <arg value="--output" />
254            <arg path="${project.basedir}/build/code-browser" />
255        </exec>
256    </target>
257
258    <target name="bump" description="bump a version">
259        <input propertyname="release_option" defaultValue="Minor" validargs="Major,Minor,BugFix" promptChar=":">
260            Please choose a release type
261        </input>
262        <version releasetype="${release_option}" file="version.txt" property="version.number" />
263        <reflexive file="app/config/core.php">
264            <filterchain>
265                <replaceregexp>
266                    <regexp pattern="'IPEER_VERSION', '\d.\d.\d'" replace="'IPEER_VERSION', '${version.number}'"/>
267                </replaceregexp>
268            </filterchain>
269        </reflexive>
270    </target>
271
272    <target name="release" description="Prepare the release" depends="packaging" />
273
274    <target name="packaging" description="Packaging the release">
275        <delete dir="${project.basedir}/dist"/>
276        <mkdir dir="${project.basedir}/dist"/>
277        <loadfile property="version.number" file="version.txt"/>
278        <php function="trim" returnProperty="version.number">
279            <param value="${version.number}" />
280        </php>
281        <echo msg="IPEER_VERSION=${version.number}" file="dist/version_for_jenkins.properties" />
282
283        <tar destfile="dist/${phing.project.name}-${version.number}.tar.gz" compression="gzip">
284            <fileset dir=".">
285                <exclude name="**/.git/" />
286                <exclude name="build/" />
287                <exclude name="dist/" />
288            </fileset>
289        </tar>
290        <filehash file="dist/${phing.project.name}-${version.number}.tar.gz" hashtype="0" />
291        <echo msg="${filehashvalue}" file="dist/${phing.project.name}-${version.number}.tar.gz.md5" />
292
293        <zip destfile="dist/${phing.project.name}-${version.number}.zip">
294            <fileset dir=".">
295                <exclude name="**/.git/" />
296                <exclude name="build/" />
297                <exclude name="dist/" />
298            </fileset>
299        </zip>
300        <filehash file="dist/${phing.project.name}-${version.number}.zip" hashtype="0" />
301        <echo msg="${filehashvalue}" file="dist/${phing.project.name}-${version.number}.zip.md5" />
302
303        <copy file="readme.md" todir="dist/" />
304    </target>
305
306    <target name="extract" description="Extract i18n strings for translation">
307        <delete file="app/locale/default.pot" quiet='true'/>
308        <exec command="cake/console/cake i18n extract -app app -merge yes -output app/locale/ -paths app/" passthru="true"/>
309    </target>
310</project>
Note: See TracBrowser for help on using the repository browser.