forked from PHP-Belarus/php.of.by
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.xml
452 lines (399 loc) · 21.2 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
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
<?xml version="1.0"?>
<project name="php-of-by" default="build" basedir="." description="PHP UG BY site build plan">
<property file="build.properties"/>
<property name="project-version" value="${env.TRAVIS_TAG}.${env.TRAVIS_BUILD_NUMBER}"/>
<property name="project-prod-db-host" value="${env.DEPLOY_DB_HOST}"/>
<property name="project-prod-db-name" value="${env.DEPLOY_DB_NAME}"/>
<property name="project-prod-db-user" value="${env.DEPLOY_DB_USER}"/>
<property name="project-prod-db-password" value="${env.DEPLOY_DB_PASSWORD}"/>
<property name="project-config-dir" value="config" />
<property name="project-file-config-version" value="${project-config-dir}/services.yaml"/>
<property name="project-file-config-ci" value=".env.dist_ci"/>
<property name="project-file-config-prod" value=".env.dist_prod"/>
<property name="project-file-config" value=".env"/>
<property name="project-resources-dir" value="Resources" />
<property name="project-resources-configs-dir" value="${project-resources-dir}/configs"/>
<property name="project-resources-configs-phpmd-dir" value="${project-resources-configs-dir}/phpmd"/>
<property name="project-file-config-phpmd" value="${project-resources-configs-phpmd-dir}/phpmd.xml"/>
<property name="project-bin-dir" value="bin" />
<property name="project-vendor-dir" value="vendor" />
<property name="project-vendor-bin-dir" value="vendor/bin" />
<property name="project-src-dir" value="src" />
<property name="project-tests-dir" value="tests" />
<property name="env" value="/usr/bin/env" />
<property name="php-bin" value="php" />
<property name="project-composer-phar" value="composer.phar" />
<property name="php-cs-fixer-bin" value="${project-vendor-bin-dir}/php-cs-fixer" />
<property name="php-cpd-bin" value="${project-vendor-bin-dir}/phpcpd" />
<property name="project-web-dir" value="web"/>
<property name="project-web-bundles-dir" value="${project-web-dir}/bundles"/>
<property name="project-web-css-dir" value="${project-web-dir}/css"/>
<property name="project-web-js-dir" value="${project-web-dir}/js"/>
<property name="project-build-dir" value="build"/>
<property name="project-build-output-dir" value="${project-build-dir}/output"/>
<property name="project-file-doctrine-database-scheme" value="db-scheme.sql"/>
<property name="project-doctrine-database-scheme" value="${project-build-output-dir}/${project-file-doctrine-database-scheme}"/>
<property name="project-file-package" value="${project-build-output-dir}/${phing.project.name}-${project-version}.tar.gz"/>
<property name="project-file-package-version" value="version.txt"/>
<property name="project-resources-doc-dir" value="${project-resources-dir}/doc"/>
<property name="symfony-bin-console" value="${project-bin-dir}/console"/>
<property name="project-var-dir" value="var"/>
<property name="project-var-cache-dir" value="${project-var-dir}/cache" />
<property name="project-var-log-dir" value="${project-var-dir}/log" />
<property name="node-modules-dir" value="node_modules" />
<property name="project-bin-console" value="${project-bin-dir}/console" />
<!-- Filesets -->
<fileset dir="${project-src-dir}" id="src-php">
<include name="**/*.php"/>
</fileset>
<fileset dir="${project.basedir}" id="package">
<include name="${project-config-dir}/**"/>
<include name="${project-src-dir}/**"/>
<include name="${project-vendor-dir}/**/*"/>
<include name="${project-web-dir}/**"/>
<include name="${project-bin-dir}/**"/>
<include name="${project-var-dir}/**"/>
<include name="db/**"/>
<include name="templates/**"/>
<include name="translations/**"/>
<include name="${project-resources-doc-dir}/**"/>
<include name="${project-file-package-version}"/>
<include name="${project-file-doctrine-database-scheme}"/>
<include name="${project-file-config}" />
<include name="composer.json" />
<include name="composer.lock" />
</fileset>
<fileset dir="${project.basedir}" id="symfony-temp">
<include name="${project-var-cache-dir}/**"/>
<include name="${project-var-log-dir}/**"/>
</fileset>
<fileset dir="${project.basedir}" id="symfony-dev-only-files">
<include name="${project-web-dir}/check.php"/>
<include name="${project-config-dir}/routes/dev"/>
<include name="${project-config-dir}/packages/dev"/>
<include name="${project-config-dir}/packages/test"/>
</fileset>
<fileset dir="${project-resources-doc-dir}" id="doc-rst">
<include name="**/*.rst"/>
</fileset>
<target name="projectdoc" description="Generates project documentation in HTML format from rst using python docutils">
<!--
Next two lines is workaround for phing, which wants to include particular tasks for performing this job.
Also prepend here works better then append.
-->
<includepath classpath="${project-vendor-dir}/pear/pear-core-minimal/src" mode="prepend"/>
<includepath classpath="${project-vendor-dir}/pear/console_getopt" mode="prepend"/>
<rST format="html">
<fileset refid="doc-rst"/>
</rST>
</target>
<target name="composer-validate" description="Validate composer file">
<composer composer="${project-composer-phar}" command="validate" />
</target>
<target name="check-environment" description="Check that environment is suitable for symfony">
<exec executable="${php-bin}" checkReturn="true" logoutput="true" >
<arg value="${project-vendor-bin-dir}/requirements-checker" />
</exec>
</target>
<target name="dependencies-install" description="Install all dependencies using composer" depends="make-console-executable">
<delete dir="${project-vendor-dir}" />
<delete dir="${project-build-output-dir}" />
<delete dir="${node-modules-dir}" />
<delete includeemptydirs="true">
<fileset refid="symfony-temp"/>
</delete>
<composer composer="${project-composer-phar}" command="install">
<arg value="--optimize-autoloader"/>
</composer>
<exec executable="${project.yarn-bin}" passthru="true" >
<arg value="install" />
</exec>
</target>
<target name="dependencies-install-prod" description="Install only prod dependencies using composer" depends="make-console-executable">
<delete dir="${project-vendor-dir}" />
<delete dir="${node-modules-dir}" />
<composer composer="${project-composer-phar}" command="install">
<arg value="--optimize-autoloader" />
<arg value="--no-dev" />
</composer>
<exec executable="${project.yarn-bin}" passthru="true" >
<arg value="install" />
<arg value="--prod" />
</exec>
</target>
<target name="dependencies-list-updates" description="Check updates for all dependencies">
<composer composer="${project-composer-phar}" command="update">
<arg value="--dry-run"/>
</composer>
</target>
<target name="clean" description="Clean build artifacts">
<delete dir="${project-web-bundles-dir}"/>
<delete dir="${project-web-css-dir}"/>
<delete dir="${project-web-js-dir}"/>
<delete dir="${project-build-output-dir}"/>
<delete includeemptydirs="true">
<fileset refid="symfony-temp"/>
</delete>
</target>
<target name="clean-dev-only-files" description="Clean dev files">
<delete>
<fileset refid="symfony-dev-only-files"/>
</delete>
</target>
<target name="symfony-twig-lint" description="Check twig templates syntax in directories">
<foreach list="${project.twig-templates-dirs}" param="templates.dir" target="symfony-twig-lint-dir"/>
</target>
<target name="symfony-twig-lint-dir" description="Check twig templates syntax in directory">
<SymfonyConsole command="lint:twig" checkReturn="true" console="${symfony-bin-console}">
<arg value="${templates.dir}" />
<arg value="--no-interaction" />
</SymfonyConsole>
</target>
<target name="symfony-yaml-lint" description="Check yaml syntax in directories">
<foreach list="${project.yaml-dirs}" param="yamls.dir" target="symfony-yaml-lint-dir"/>
</target>
<target name="symfony-yaml-lint-dir" description="Check yaml syntax in directory">
<SymfonyConsole command="lint:yaml" checkReturn="true" console="${symfony-bin-console}">
<arg value="${yamls.dir}" />
<arg value="--no-interaction" />
</SymfonyConsole>
</target>
<target name="phplint" description="Perform syntax check of sourcecode files">
<phplint haltonfailure="true" deprecatedAsError="true">
<fileset refid="src-php"/>
</phplint>
</target>
<target name="make-console-executable" description="Make symfony console script executable">
<chmod file="${project-bin-console}" mode="770" />
</target>
<target name="php-cs-fixer" description="Fixes most issues in code as defined in the PSR-1 and PSR-2 documents">
<exec executable="${php-bin}" logoutput="true">
<arg path="${php-cs-fixer-bin}" />
<arg value="fix"/>
</exec>
</target>
<target name="php-cs-fixer-ci" description="Fixes most issues in code as defined in the PSR-* documents">
<exec executable="${php-bin}" logoutput="true" checkreturn="true">
<arg path="${php-cs-fixer-bin}" />
<arg value="fix"/>
<arg value="--dry-run"/>
<arg value="--diff"/>
</exec>
</target>
<target name="symfony-regenerate-cache-dev" description="Regenerate symfony cache in dev mode">
<SymfonyConsole command="cache:clear" checkReturn="true" console="${symfony-bin-console}">
<arg name="env" value="dev" />
<arg value="--no-interaction" />
</SymfonyConsole>
<SymfonyConsole command="cache:pool:prune" checkReturn="true" console="${symfony-bin-console}">
<arg name="env" value="dev" />
<arg value="--no-interaction" />
</SymfonyConsole>
</target>
<target name="symfony-regenerate-cache-prod" description="Regenerate symfony cache in prod mode">
<SymfonyConsole command="cache:clear" checkReturn="true" console="${symfony-bin-console}">
<arg name="env" value="prod" />
<arg value="--no-debug" />
<arg value="--no-interaction" />
</SymfonyConsole>
<SymfonyConsole command="cache:pool:prune" checkReturn="true" console="${symfony-bin-console}">
<arg name="env" value="prod" />
<arg value="--no-debug" />
<arg value="--no-interaction" />
</SymfonyConsole>
</target>
<target name="symfony-assets-install-dev" description="Install assets in dev mode">
<SymfonyConsole command="assets:install" checkReturn="true" console="${symfony-bin-console}">
<arg name="env" value="dev" />
<arg value="--no-interaction" />
<arg value="${project-web-dir}" />
</SymfonyConsole>
</target>
<target name="symfony-assets-install-prod" description="Install assets in prod mode">
<SymfonyConsole command="assets:install" checkReturn="true" console="${symfony-bin-console}">
<arg name="env" value="prod" />
<arg value="--no-debug" />
<arg value="--no-interaction" />
<arg value="${project-web-dir}" />
</SymfonyConsole>
</target>
<target name="encore-build-assets-dev" description="Dumps all assets to the filesystem for dev environment">
<exec executable="${project.yarn-bin}" dir="." checkreturn="false" outputProperty="encore-dev-results" returnProperty="encore-dev-return">
<arg value="run" />
<arg value="encore" />
<arg value="dev" />
</exec>
<echo message="${encore-dev-results}" />
<if>
<istrue value="${encore-dev-return}" />
<then>
<fail /> <!-- Fail build in case of errors -->
</then>
</if>
</target>
<target name="encore-build-assets-prod" description="Dumps all assets to the filesystem for prod environment">
<exec executable="${project.yarn-bin}" dir="." checkreturn="false" outputProperty="encore-prod-results" returnProperty="encore-prod-return">
<arg value="run" />
<arg value="encore" />
<arg value="production" />
</exec>
<echo message="${encore-prod-results}" />
<if>
<istrue value="${encore-prod-return}" />
<then>
<fail /> <!-- Fail build in case of errors -->
</then>
</if>
</target>
<target name="symfony-doctrine-migrations-migrate" description="Executes migrations">
<if>
<istrue value="${project.symfony-doctrine-migrations-enable}"/>
<then>
<SymfonyConsole command="doctrine:migrations:migrate" checkReturn="true" console="${symfony-bin-console}">
<arg name="no-interaction"/>
</SymfonyConsole>
</then>
</if>
</target>
<target name="symfony-doctrine-schema-validate" description="Validates the doctrine mapping files"
depends="symfony-doctrine-migrations-migrate">
<SymfonyConsole command="doctrine:schema:validate" checkReturn="true" console="${symfony-bin-console}">
<arg name="no-interaction"/>
</SymfonyConsole>
</target>
<target name="initialize-autoload" description="Initialize autoloader">
<autoloader />
</target>
<target name="phpmd" description="Run phpmd checks" depends="initialize-autoload">
<phpmd rulesets="${project-file-config-phpmd}">
<fileset refid="src-php"/>
</phpmd>
</target>
<target name="phpcpd" description="Find duplicates in code" depends="initialize-autoload">
<exec executable="${php-bin}" logoutput="true" checkreturn="true">
<arg path="${php-cpd-bin}" />
<arg value="${project-src-dir}/" />
</exec>
<!-- <phpcpd>-->
<!-- <fileset refid="src-php"/>-->
<!-- <formatter type="default" useFile="false"/>-->
<!-- </phpcpd>-->
</target>
<target name="phpcs" description="Run code style checks" depends="initialize-autoload">
<exec executable="${project-vendor-bin-dir}/phpcs" dir="." checkReturn="false" outputProperty="phpcs-results" returnProperty="phpcs-return" >
<arg value="--standard=PSR12" />
<arg value="${project-src-dir}" />
<arg value="${project-tests-dir}" />
</exec>
<echo message="${phpcs-results}" />
<if>
<istrue value="${phpcs-return}" />
<then>
<fail /> <!-- fail build in case of errors -->
</then>
</if>
</target>
<target name="symfony-doctrine-dump-schema" description="Dump current database scheme">
<SymfonyConsole command="doctrine:schema:create" checkReturn="true" propertyName="scheme.sql" console="${symfony-bin-console}">
<arg name="dump-sql"/>
<arg name="no-interaction"/>
</SymfonyConsole>
<echo msg="${scheme.sql}" file="${project-doctrine-database-scheme}" append="false"/>
</target>
<target name="package-db-schema" description="Stores DB schema in the package">
<copy file="${project-doctrine-database-scheme}" tofile="${project-file-doctrine-database-scheme}" haltonerror="true"
overwrite="true"/>
</target>
<target name="copy-configs-ci" description="Copy configs for CI server">
<copy file="${project-file-config-ci}" tofile="${project-file-config}"
overwrite="true" haltonerror="true"/>
</target>
<target name="copy-configs-prod" description="Copy configs for CI server">
<copy file="${project-file-config-prod}" tofile="${project-file-config}"
overwrite="true" haltonerror="true"/>
</target>
<target name="prepare" description="Create some dirs for build">
<mkdir dir="${project-build-output-dir}"/>
</target>
<target name="package-version" description="Stores package version in text file">
<echo msg="${project-version}" file="${project-file-package-version}" append="false"/>
</target>
<target name="build-timestamp" description="Generates timestamp for the build">
<tstamp>
<format property="project-timestamp" pattern="%Y-%m-%d %H:%M"/>
</tstamp>
</target>
<target name="file-update-version" description="Updates application version in the text file" depends="build-timestamp">
<reflexive file="${project-file-config-version}">
<filterchain>
<replacetokens begintoken="~" endtoken="~">
<token key="PROJECT_VERSION" value="${project-version} ${project-timestamp}" />
</replacetokens>
</filterchain>
</reflexive>
</target>
<target name="file-generate-secret" description="Generate random string for symfony secret">
<exec escape="false" command="php -r 'echo substr(md5(uniqid()), 0, 30), PHP_EOL;'" outputProperty="randomString" />
</target>
<target name="file-update-deploy-config" description="Set proper data to prod config" depends="file-generate-secret">
<reflexive file="${project-file-config}">
<filterchain>
<replacetokens begintoken="~" endtoken="~">
<token key="PROJECT_DB_HOST" value="${project-prod-db-host}"/>
<token key="PROJECT_DB_NAME" value="${project-prod-db-name}"/>
<token key="PROJECT_DB_USER" value="${project-prod-db-user}"/>
<token key="PROJECT_DB_PASSWORD" value="${project-prod-db-password}"/>
<token key="PROJECT_SECRET" value="${randomString}"/>
</replacetokens>
</filterchain>
</reflexive>
</target>
<target name="package-prepare-files" description="Prepare package files for archiving">
<copy todir="${project-build-dir}" includeemptydirs="true" overwrite="true">
<fileset refid="package" />
</copy>
</target>
<target name="package-archive" description="Create package for deploy to prod" depends="package-prepare-files">
<!--
Next three lines is workaround for phing, which wants to include particular tasks for performing this job.
Also prepend here works better then append.
-->
<includepath classpath="${project-vendor-dir}/pear/pear-core-minimal/src" mode="prepend"/>
<includepath classpath="${project-vendor-dir}/pear/console_getopt" mode="prepend"/>
<includepath classpath="${project-vendor-dir}/pear/archive_tar" mode="prepend"/>
<tar destfile="package.tgz" includeemptydirs="true" compression="gzip">
<fileset dir="${project-build-dir}" >
<include name="**" />
</fileset>
</tar>
</target>
<target name="psalm" description="Run static code analysis">
<exec executable="${project-vendor-bin-dir}/psalm" dir="." checkReturn="false" outputProperty="psalm-results" returnProperty="psalm-return" />
<echo message="${psalm-results}" />
<if>
<istrue value="${psalm-return}" />
<then>
<fail /> <!-- fail build in case of errors -->
</then>
</if>
</target>
<target name="dependencies-list-outdated" description="Check for new versions of dependencies">
<composer composer="${project-composer-phar}" command="outdated">
<arg value="-D"/>
</composer>
<exec executable="${project.yarn-bin}" passthru="true">
<arg value="outdated" />
</exec>
</target>
<target name="package" description="Create tar package for deployment" depends="copy-configs-prod,file-update-deploy-config,
clean,prepare,composer-validate,file-update-version,dependencies-install-prod,symfony-regenerate-cache-prod,
symfony-assets-install-prod,encore-build-assets-prod,clean-dev-only-files,package-version,package-archive" />
<target name="build" description="Runs build locally" depends="clean,prepare,check-environment,projectdoc,
composer-validate,phplint, psalm, symfony-twig-lint, symfony-yaml-lint, symfony-doctrine-schema-validate, phpmd, php-cs-fixer, phpcs,
phpcpd,symfony-regenerate-cache-dev,symfony-regenerate-cache-prod,symfony-assets-install-dev,encore-build-assets-dev,
symfony-assets-install-prod,encore-build-assets-prod,dependencies-list-updates, dependencies-list-outdated" />
<target name="build-ci" description="Runs CI build" depends="copy-configs-ci,dependencies-install,clean,prepare,check-environment,
projectdoc,composer-validate,phplint, psalm, symfony-twig-lint,symfony-yaml-lint,symfony-doctrine-schema-validate,phpmd,
php-cs-fixer-ci, phpcs,phpcpd,symfony-regenerate-cache-dev,symfony-regenerate-cache-prod,symfony-assets-install-dev,encore-build-assets-dev,
symfony-assets-install-prod,encore-build-assets-prod,dependencies-list-updates, dependencies-list-outdated" />
</project>