Repository navigation
Expand file tree
/
Copy pathbuild.xml
More file actions
244 lines (227 loc) · 10.8 KB
/
Copy pathbuild.xml
File metadata and controls
244 lines (227 loc) · 10.8 KB
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
<?xml version="1.0" encoding="UTF-8"?>
<project name="gbdb" basedir="." default="main">
<property name="sh" value="/bin/sh" />
<property name="tmp" value="/tmp" />
<property name="package" value="${phing.project.name}" override="true" />
<property name="builddir" value="${tmp}/build/${phing.project.name}" override="true" />
<property name="srcdir" value="${project.basedir}" override="true" />
<property name="gbdburl" value="http://localhost" />
<property name="gbdbdb" value="gbdb_test" />
<property name="gbdbdbuser" value="gbdbtest" />
<property name="gbdbdbpass" value="gbdbtestpass" />
<property name="mysqlhost" value="localhost" />
<property name="mysqlport" value="3306" />
<property name="mysqlprotocol" value="" />
<property name="mysqlrootuser" value="root" />
<property name="mysqlrootpass" value="password" />
<property name="phpunit_command" value="${srcdir}/vendor/bin/phpunit" />
<property name="phpunit_extra_params" value="" />
<property name="screenshot_dir" value="" /><!-- set to a directory name to capture screenshots of failed tests -->
<property name="snooze_multiplier" value="1" /><!-- can be used to slow down Mink tests; increase when tests fail on slow systems -->
<property name="default_test_timeout" value="5000" /><!-- default timeout (in ms) for Mink tests; increase when tests fail on slow systems -->
<property name="mysqlconnectionargs" value="-h ${mysqlhost} -P ${mysqlport} -u ${mysqlrootuser}" />
<!-- Add password if not empty -->
<if>
<not>
<equals arg1="${mysqlrootpass}" arg2="" />
</not>
<then>
<property name="mysqlconnectionargs" override="true" value="${mysqlconnectionargs} -p${mysqlrootpass}" />
</then>
</if>
<!-- Add protocol if not empty -->
<if>
<not>
<equals arg1="${mysqlprotocol}" arg2="" />
</not>
<then>
<property name="mysqlconnectionargs" override="true" value="${mysqlconnectionargs} --protocol ${mysqlprotocol}" />
</then>
</if>
<!-- Main Target -->
<target name="main" description="main target">
<trycatch property="exceptionmsg">
<try>
<phingcall target="startup" />
<phingcall target="ci-tasks" />
<phingcall target="shutdown" />
</try>
<catch>
<phingcall target="shutdown" />
<fail>Unexpected error during continuous integration tasks -- ${exceptionmsg}</fail>
</catch>
</trycatch>
</target>
<!-- Continuous Integration Tasks -->
<target name="ci-tasks" description="continuous integration tasks">
<!-- Create dirs -->
<mkdir dir="${builddir}/reports"/>
<!-- Call standard tasks -->
<phingcall target="php-cs-fixer-dryrun"/>
<phingcall target="phpcs"/>
<phingcall target="phpstan-checkstyle" />
<phingcall target="rector-console"/>
</target>
<!-- Quality Assurance PHP Tasks -->
<target name="qa-console" description="quality assurance tasks">
<phingcall target="phpunitfast"/>
<phingcall target="php-cs-fixer-dryrun"/>
<phingcall target="phpcs-console"/>
<phingcall target="phpstan-console" />
<phingcall target="rector-console"/>
</target>
<!-- Fix PHP Tasks -->
<target name="fix-php" description="quality assurance php tasks">
<!-- Rector may introduce style issues, so run it first -->
<phingcall target="rector"/>
<phingcall target="php-cs-fixer"/>
<phingcall target="phpcbf"/>
</target>
<!-- PHP CodeSniffer -->
<target name="phpcbf">
<!-- Run phpcs first to find any problems (faster than phpcbf): -->
<exec executable="${srcdir}/vendor/bin/phpcs" escape="false" returnProperty="phpcs_retval" outputProperty="phpcs_output">
<arg line="--cache=${srcdir}/tests/phpcs.cache.json --standard=${srcdir}/tests/phpcs.xml" />
</exec>
<if>
<not><equals arg1="${phpcs_retval}" arg2="0" /></not>
<then>
<echo msg="Trying to fix the following issues: " />
<echo msg="${phpcs_output}" />
<!-- Extract file names from phpcs output: -->
<property name="phpcbf_filelist" value="${phpcs_output}">
<filterchain>
<linecontainsregexp>
<regexp pattern="^FILE: (.*)" />
</linecontainsregexp>
<striplinebreaks />
<replaceregexp>
<regexp pattern="FILE: " replace=" " />
</replaceregexp>
</filterchain>
</property>
<!-- Finally, run phpcbf: -->
<exec executable="${srcdir}/vendor/bin/phpcbf" escape="false" passthru="true">
<arg line="--standard=${srcdir}/tests/phpcs.xml ${phpcbf_filelist}" />
</exec>
</then>
</if>
</target>
<target name="phpcs">
<exec executable="${srcdir}/vendor/bin/phpcs" escape="false">
<arg line="--cache=${srcdir}/tests/phpcs.cache.json --standard=${srcdir}/tests/phpcs.xml --report=checkstyle > ${builddir}/reports/checkstyle.xml" />
</exec>
</target>
<target name="phpcs-console">
<exec executable="${srcdir}/vendor/bin/phpcs" escape="false" passthru="true" checkreturn="true">
<arg line="--cache=${srcdir}/tests/phpcs.cache.json --standard=${srcdir}/tests/phpcs.xml" />
</exec>
</target>
<!-- Phpstan -->
<target name="phpstan-checkstyle">
<exec executable="${srcdir}/vendor/bin/phpstan" escape="false" passthru="true" checkreturn="true">
<arg line="--configuration=${srcdir}/tests/phpstan.neon --memory-limit=2G --error-format=checkstyle analyse > ${builddir}/reports/phpstan-checkstyle.xml" />
</exec>
</target>
<target name="phpstan-console">
<exec executable="${srcdir}/vendor/bin/phpstan" escape="false" passthru="true" checkreturn="true">
<arg line="--configuration=${srcdir}/tests/phpstan.neon --memory-limit=2G analyse" />
</exec>
</target>
<!-- php-cs-fixer (first task applies fixes, second task simply checks if they are needed) -->
<target name="php-cs-fixer">
<exec executable="${srcdir}/vendor/bin/php-cs-fixer" passthru="true" escape="false">
<arg line="fix --config=${srcdir}/tests/gbdb.php-cs-fixer.php --verbose" />
</exec>
<exec executable="${srcdir}/vendor/bin/php-cs-fixer" passthru="true" escape="false">
<arg line="fix --config=${srcdir}/tests/gbdb_templates.php-cs-fixer.php --verbose" />
</exec>
</target>
<target name="php-cs-fixer-dryrun">
<exec executable="${srcdir}/vendor/bin/php-cs-fixer" passthru="true" escape="false" checkreturn="true">
<arg line="fix --config=${srcdir}/tests/gbdb.php-cs-fixer.php --dry-run --verbose --diff" />
</exec>
<exec executable="${srcdir}/vendor/bin/php-cs-fixer" passthru="true" escape="false" checkreturn="true">
<arg line="fix --config=${srcdir}/tests/gbdb_templates.php-cs-fixer.php --dry-run --verbose --diff" />
</exec>
</target>
<!-- PHPUnit without logging output -->
<target name="phpunitfast" description="Run tests">
<exec dir="${srcdir}/module/GeebyDeeby/tests" executable="${sh}" passthru="true" checkreturn="true">
<arg line="-c '${phpunit_command} ${phpunit_extra_params}'" />
<env key="GBDB_SCREENSHOT_DIR" value="${screenshot_dir}" />
<env key="GBDB_URL" value="${gbdburl}" />
<env key="GBDB_SNOOZE_MULTIPLIER" value="${snooze_multiplier}" />
<env key="GBDB_DEFAULT_TEST_TIMEOUT" value="${default_test_timeout}" />
</exec>
</target>
<!-- PHPUnit without logging output, stopping at first error or failure -->
<target name="phpunitfaster" description="Run tests">
<exec dir="${srcdir}/module/GeebyDeeby/tests" executable="${sh}" passthru="true" checkreturn="true">
<arg line="-c '${phpunit_command} --stop-on-defect ${phpunit_extra_params}'" />
<env key="GBDB_SCREENSHOT_DIR" value="${screenshot_dir}" />
<env key="GBDB_URL" value="${gbdburl}" />
<env key="GBDB_SNOOZE_MULTIPLIER" value="${snooze_multiplier}" />
<env key="GBDB_DEFAULT_TEST_TIMEOUT" value="${default_test_timeout}" />
</exec>
</target>
<!-- Rector -->
<target name="rector-console">
<exec executable="${srcdir}/vendor/bin/rector" escape="false" passthru="true" checkreturn="true">
<arg line="--config=${srcdir}/tests/rector.php --dry-run" />
</exec>
</target>
<target name="rector">
<exec executable="${srcdir}/vendor/bin/rector" escape="false" passthru="true" checkreturn="true">
<arg line="--config=${srcdir}/tests/rector.php" />
</exec>
</target>
<!-- Set up test database -->
<target name="setup_database" description="clean up existing database and users">
<!-- clean up anything from past runs -->
<phingcall target="teardown_database" />
<!-- create database and user -->
<exec executable="mysql" passthru="true" checkreturn="true">
<arg line="${mysqlconnectionargs} -e "CREATE DATABASE IF NOT EXISTS ${gbdbdb}"" />
</exec>
<exec executable="mysql" passthru="true" checkreturn="true">
<arg line="${mysqlconnectionargs} -e "CREATE USER IF NOT EXISTS '${gbdbdbuser}'@'%' IDENTIFIED BY '${gbdbdbpass}'"" />
</exec>
<!-- load the database definitions -->
<exec executable="mysql" passthru="true" checkreturn="true">
<arg line="${mysqlconnectionargs} ${gbdbdb} < ${srcdir}/data/mysql.sql" />
</exec>
<!-- grant access to new user -->
<exec executable="mysql" passthru="true" checkreturn="true">
<arg line="${mysqlconnectionargs} -e "GRANT ALL ON ${gbdbdb}.* TO '${gbdbdbuser}'@'%'"" />
</exec>
<!-- create superuser role -->
<exec executable="mysql" passthru="true" checkreturn="true">
<arg line="${mysqlconnectionargs} ${gbdbdb} -e "insert into User_Groups(Group_Name, Content_Editor, User_Editor, Approver, Data_Manager) values ('Superuser', 1, 1, 1, 1);"" />
</exec>
<!-- create configuration file -->
<touch file="${srcdir}/config/autoload/testdb.local.php" />
<append destFile="${srcdir}/config/autoload/testdb.local.php" text="<?php return ['geeby-deeby' => ['dbName' => '${gbdbdb}', 'dbUser' => '${gbdbdbuser}', 'dbPass' => '${gbdbdbpass}']]; ?>" />
</target>
<!-- Tear down test database -->
<target name="teardown_database" description="clean up existing database and users">
<exec executable="mysql" passthru="true">
<arg line="${mysqlconnectionargs} -e "DROP DATABASE IF EXISTS ${gbdbdb}"" />
</exec>
<exec executable="mysql" passthru="true">
<arg line="${mysqlconnectionargs} -e "DROP USER IF EXISTS '${gbdbdbuser}'@'%'"" />
</exec>
<delete file="${srcdir}/config/autoload/testdb.local.php" quiet="true" />
</target>
<!-- Set up dependencies -->
<target name="startup" description="set up dependencies and database">
<exec executable="composer">
<arg line="install" />
</exec>
<phingcall target="setup_database" />
</target>
<!-- Clean up -->
<target name="shutdown" description="clean up file system and test database">
<phingcall target="teardown_database" />
</target>
</project>