-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathbuild.xml
267 lines (213 loc) · 11 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
<?xml version="1.0" encoding="UTF-8" ?>
<project name="Skautske hospodareni" basedir="." default="main">
<property name="tempDir" value="temp"/>
<target name="main" description="Runs tests and prepares deployable tarball">
<exec command="composer install" passthru="true"/>
<phingcall target="static-analysis"/>
<phingcall target="coding-standard"/>
<exec command="bin/console orm:validate-schema --skip-sync"/>
<phingcall target="tests"/>
</target>
<target name="prepare-tarball" description="Prepares deployable tarball with everything built">
<exec command="git rev-parse --short HEAD" outputProperty="build.hash"/>
<property name="build.dir" value="${tempDir}/builds/${build.hash}"/>
<delete dir="${build.dir}"/>
<mkdir dir="${build.dir}"/>
<copy todir="${build.dir}">
<fileset dir=".">
<include name="app/**"/>
<include name="bin/console"/>
<include name="migrations/**"/>
<include name="temp/**"/>
<include name="vendor/**"/>
<include name="composer.*"/>
<include name="www/**"/>
<include name="frontend/**"/>
<include name="package.json"/>
<include name="postcss.config.js"/>
<include name="tsconfig.json"/>
<include name="webpack.config.js"/>
<include name="yarn.lock"/>
<exclude name="app/config/*local.neon"/>
<exclude name="**/.gitignore"/>
</fileset>
</copy>
<property environment="env"/>
<copy file="./app/config/config.${env.ENVIRONMENT}.local.neon" tofile="${build.dir}/app/config/config.local.neon">
<filterchain>
<replacetokens begintoken="__" endtoken="__">
<token key="CONFIG_DATABASE_PASSWORD" value="${env.CONFIG_DATABASE_PASSWORD}"/>
<token key="CONFIG_SENTRY_DSN" value="${env.CONFIG_SENTRY_DSN}"/>
<token key="CONFIG_RELEASE_HASH" value="${build.hash}"/>
</replacetokens>
<expandproperties/>
</filterchain>
</copy>
<echo file="${build.dir}/app/config/google-credentials.json">${env.CONFIG_GOOGLE_CREDENTIALS}</echo>
<exec command="composer --working-dir=${build.dir} install
--no-interaction
--optimize-autoloader
--classmap-authoritative
--no-dev"
passthru="true"/>
<!-- Build frontend assets -->
<exec dir="${build.dir}" command="yarn install && yarn build" passthru="true" checkreturn="true"/>
<delete>
<fileset dir="${build.dir}">
<!-- Temp files -->
<include name="temp/**"/>
<!-- Frontend sources -->
<include name="frontend/**"/>
<include name="node_modules/**"/>
<!-- Webloader -->
<include name="www/webtemp/**"/>
<exclude name="**/.htaccess"/>
</fileset>
</delete>
<tar destfile="${build.dir}.tar.gz" compression="gzip">
<fileset dir="${tempDir}/builds">
<include name="${build.hash}/**"/>
</fileset>
</tar>
<delete dir="${build.dir}" />
</target>
<target name="deploy:ssh">
<echo message="${comment}..."/>
<echo message="`${command}`"/>
<exec command="ssh ${deploy.ssh.target} -i ${deploy.ssh.privateKeyFile} -p ${deploy.ssh.port} '${command}'"
passthru="true"
checkreturn="true" />
</target>
<target name="deploy:copy-tarball">
<property name="command" value="scp -i ${deploy.ssh.privateKeyFile} -P ${port} ${file} '${target}:${toDirectory}'"/>
<echo message="Copying files to ${deploy.ssh.target}"/>
<echo message="${command}"/>
<exec command="${command}" passthru="true" checkreturn="true"/>
</target>
<target name="deploy:cleanup">
<echo message="Getting previous releases"/>
<property name="command" value="echo $(ssh -i ${deploy.ssh.privateKeyFile} -p ${deploy.ssh.port} ${deploy.ssh.target} 'ls ${deploy.releasesDir}' | grep -v '^${deploy.releaseHash}$')"/>
<echo message="${command}"/>
<exec outputProperty="previousReleases" command="${command}" checkreturn="true"/>
<phingcall target="deploy:ssh">
<property name="comment" value="Deleting files"/>
<property name="command" value="cd ${deploy.releasesDir} && rm -rf ${previousReleases}"/>
</phingcall>
</target>
<target name="deploy">
<tstamp/>
<!-- Prepare variables -->
<property environment="env"/>
<property name="deploy.rootDir" refid="env.ROOT_DIR"/>
<property name="deploy.releasesDir" value="${deploy.rootDir}/releases"/>
<exec command="git rev-parse --short HEAD" outputProperty="build.hash"/>
<property name="deploy.ssh.host" value="www.skauting.cz"/>
<property name="deploy.ssh.port" value="28"/>
<property name="deploy.ssh.username" refid="env.SSH_USERNAME"/>
<property name="deploy.ssh.privateKeyFile" refid="env.SSH_KEY_FILE"/>
<property name="deploy.ssh.target" value="${deploy.ssh.username}@${deploy.ssh.host}"/>
<property name="deploy.releaseHash" value="${DSTAMP}-${TSTAMP}-${build.hash}"/>
<property name="deploy.release" value="${deploy.releasesDir}/${deploy.releaseHash}"/>
<!-- Build tarball -->
<phingcall target="prepare-tarball">
<property name="build.hash" value="${deploy.releaseHash}"/>
</phingcall>
<phingcall target="deploy:copy-tarball">
<property name="target" value="${deploy.ssh.target}"/>
<property name="port" value="${deploy.ssh.port}"/>
<property name="file" value="${tempDir}/builds/${deploy.releaseHash}.tar.gz"/>
<property name="toDirectory" value="${deploy.releasesDir}"/>
</phingcall>
<property name="tarball" value="${deploy.release}.tar.gz"/>
<phingcall target="deploy:ssh">
<property name="comment" value="Extracting tarball to release directory"/>
<property name="command" value="tar -xzf ${tarball} -C ${deploy.releasesDir}"/>
</phingcall>
<phingcall target="deploy:ssh">
<property name="comment" value="Removing tarball"/>
<property name="command" value="rm ${tarball}"/>
</phingcall>
<phingcall target="deploy:ssh">
<property name="comment" value="Symlink logs"/>
<property name="command" value="ln -s ${deploy.rootDir}/log ${deploy.release}/log"/>
</phingcall>
<phingcall target="deploy:ssh">
<property name="comment" value="Symlinking uploads"/>
<property name="command" value="ln -s ${deploy.rootDir}/uploads ${deploy.release}/uploads"/>
</phingcall>
<phingcall target="deploy:app-command">
<property name="comment" value="Generating doctrine proxies"/>
<property name="command" value="orm:generate-proxies"/>
</phingcall>
<phingcall target="deploy:app-command">
<property name="comment" value="Running database migrations"/>
<property name="command" value="migrations:migrate --no-interaction"/>
</phingcall>
<phingcall target="deploy:ssh">
<property name="comment" value="Swapping release to ${deploy.releaseHash}"/>
<property name="command" value="rm www && ln -s ${deploy.release}/www www"/>
</phingcall>
<phingcall target="deploy:cleanup"/>
</target>
<target name="deploy:app-command">
<phingcall target="deploy:ssh">
<property name="command"
value="php81-cli "${deploy.release}/bin/console ${command}""/>
</phingcall>
</target>
<target name="tests-init">
<exec command="bin/console nette:cache:purge" passthru="true" checkreturn="false"/>
<exec command="bin/console migrations:drop-all-tables-views --no-interaction" passthru="true" checkreturn="true"/>
<exec command="bin/console migrations:migrate --no-interaction" passthru="true"/>
</target>
<target name="tests-unit">
<exec command="vendor/bin/codecept run unit" passthru="true" checkreturn="true"/>
</target>
<target name="tests-integration">
<exec command="vendor/bin/codecept run integration" passthru="true" checkreturn="true"/>
</target>
<target name="tests-acceptance">
<exec command="bin/console nette:cache:purge" passthru="true" checkreturn="false"/>
<exec command="bin/console migrations:drop-all-tables-views --no-interaction" passthru="true" checkreturn="true"/>
<exec command="bin/console migrations:migrate --no-interaction" passthru="true"/>
<exec command="bin/console orm:generate-proxies --no-interaction" passthru="true"/>
<exec command="vendor/bin/codecept run acceptance -vv" passthru="true" checkreturn="true"/>
</target>
<target name="tests">
<phingcall target="tests-init"/>
<phingcall target="tests-unit"/>
<phingcall target="tests-integration"/>
<phingcall target="tests-acceptance"/>
</target>
<target name="tests-with-coverage">
<exec command="php -d php -d zend_extension=xdebug.so -d xdebug.mode=coverage vendor/bin/codecept run unit,integration --coverage-xml"
passthru="true"
checkreturn="true"/>
</target>
<target name="static-analysis">
<exec command="bin/console nette:cache:purge " passthru="true" checkreturn="false"/>
<exec command="php -d memory_limit=2G vendor/bin/phpstan analyse -l 6 -c phpstan.neon app tests --no-progress"
passthru="true" checkreturn="true"/>
</target>
<target name="coding-pretty">
<exec command="vendor/bin/phpcbf app" passthru="true" checkreturn="true"/>
</target>
<target name="coding-standard">
<exec command="vendor/bin/phpcbf app" passthru="true" checkreturn="true"/>
<exec command="vendor/bin/phpcs" passthru="true" checkreturn="true"/>
</target>
<target name="coding-standard-ci">
<exec command="vendor/bin/phpcs" passthru="true" checkreturn="true"/>
</target>
<target name="app-init">
<!-- Create config.local.neon -->
<copy file="app/config/config.sample.local.neon" tofile="app/config/config.local.neon"/>
<!-- Install dependencies -->
<exec command="composer install" passthru="true" checkreturn="true"/>
<exec command="yarn install" passthru="true" checkreturn="true"/>
<!-- Build frontend assets -->
<exec command="yarn build" passthru="true" checkreturn="true"/>
<!-- Prepare database schema -->
<exec command="bin/console migrations:migrate --no-interaction" passthru="true" checkreturn="true"/>
</target>
</project>