forked from acquia/blt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.xml
300 lines (264 loc) · 13.7 KB
/
setup.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
<project name="setup" default="setup">
<target name="setup" description="Install dependencies, builds docroot, installs Drupal."
depends="setup:build, setup:drupal:install, install-alias">
<echo>For a full list of available Phing targets, run:</echo>
<echo>blt -l</echo>
<echo></echo>
</target>
<target name="setup:behat" description="Generates tests/behat/local.yml file for executing Behat tests locally.">
<mkdir dir="${reports.localDir}/behat"/>
<echo level="${blt.level}">Attempting to generate tests/behat/local.yml.</echo>
<copy file="${repo.root}/tests/behat/example.local.yml" tofile="${repo.root}/tests/behat/local.yml" verbose="true">
<filterchain>
<expandproperties level="verbose" />
</filterchain>
</copy>
</target>
<!-- setup:composer:install must run prior to setup:drupal:settings to ensure that scaffold files are present. -->
<target name="setup:build" description="Generates all required files for a full build. E.g., (re)builds docroot, etc."
depends="setup:git-hooks, setup:composer:install, setup:drupal:settings, setup:behat, frontend">
<if>
<equals arg1="${simplesamlphp}" arg2="true"/>
<then>
<phingcall target="simplesamlphp:build:config"/>
</then>
</if>
<phingcall target="target-hook:invoke">
<property name="hook-name" value="post-setup-build"/>
</phingcall>
</target>
<target name="setup:composer:clean" description="Wipes all composer managed directories and clears composer cache.">
<echo>Removing all composer managed dependencies.</echo>
<delete verbose="true">
<fileset dir="${repo.root}">
<include name="docroot/core"/>
<include name="docroot/libraries"/>
<include name="docroot/modules/contrib"/>
<include name="docroot/profiles/contrib"/>
<include name="docroot/themes/contrib"/>
<include name="drush/contrib"/>
<include name="vendor"/>
</fileset>
</delete>
<exec dir="${repo.root}" command="composer clear-cache" logoutput="true" checkreturn="true" level="${blt.exec_level}" passthru="true"/>
</target>
<target name="setup:composer:install" description="Installs project dependencies, including drupal core and contrib.">
<!-- Prefer distributions locally so that the downloaded archives are cached. -->
<exec dir="${repo.root}" command="export COMPOSER_EXIT_ON_PATCH_FAILURE=1; composer install --ansi --no-interaction" logoutput="true" checkreturn="true" level="${blt.exec_level}" passthru="true" />
</target>
<!-- We intentionally do not run setup:behat because we'd like to delay setting values in local.yml until just before they are run. -->
<target name="setup:settings" depends="setup:drupal:settings, setup:drush:settings" description="Creates settings files for Drupal and drush.">
</target>
<target name="setup:drupal:settings" description="Create local settings files using default settings files.">
<echo>Making ${docroot}/sites/default writable.</echo>
<chmod mode="0755" file="${docroot}/sites/default" failonerror="false" verbose="true" />
<!-- Ensure that settings.php exists and that it requires BLT settings files. -->
<if>
<not><available file="${docroot}/sites/default/settings.php"/></not>
<then>
<if>
<not><available file="${docroot}/sites/default/default.settings.php"/></not>
<then>
<echo level="verbose">Downloading scaffold files so that default.settings.php is available...</echo>
<exec dir="${repo.root}" command="composer drupal-scaffold" logoutput="true" checkreturn="true" level="${blt.exec_level}" passthru="true" />
</then>
</if>
<echo>Generating settings.php from default.settings.php...</echo>
<copy file="${docroot}/sites/default/default.settings.php" tofile="${docroot}/sites/default/settings.php" verbose="true"/>
</then>
</if>
<echo>Making ${docroot}/sites/default/settings.php writable...</echo>
<chmod mode="0644" failonerror="false" file="${docroot}/sites/default/settings.php"/>
<echo>Ensuring that blt.settings.php is required by settings.php...</echo>
<exec dir="${docroot}/sites/default" command="grep vendor/acquia/blt/settings/blt.settings.php settings.php || echo 'require DRUPAL_ROOT . "/../vendor/acquia/blt/settings/blt.settings.php";' >> settings.php" logoutput="true" checkreturn="true" level="${blt.exec_level}"/>
<exec dir="${docroot}/sites/default" command="grep trusted_host.settings.php settings.php || echo '// require DRUPAL_ROOT . "/sites/default/settings/trusted_host.settings.php";' >> settings.php" logoutput="true" checkreturn="true" level="${blt.exec_level}"/>
<echo>Generating local settings files.</echo>
<if>
<not><available file="${blt.config-files.local}" type="file" /></not>
<then>
<copy file="${blt.config-files.example-local}" tofile="${blt.config-files.local}" verbose="true" />
</then>
</if>
<if>
<not><available file="${docroot}/sites/${multisite.name}/settings/local.settings.php" type="file" /></not>
<then>
<if>
<available file="${docroot}/sites/${multisite.name}/settings/default.local.settings.php" type="file" />
<then>
<copy file="${docroot}/sites/${multisite.name}/settings/default.local.settings.php" tofile="${docroot}/sites/${multisite.name}/settings/local.settings.php" verbose="true"/>
</then>
<else>
<copy file="${blt.root}/settings/default.local.settings.php" tofile="${docroot}/sites/${multisite.name}/settings/default.local.settings.php" verbose="true"/>
<copy file="${blt.root}/settings/default.local.settings.php" tofile="${docroot}/sites/${multisite.name}/settings/local.settings.php" verbose="true" />
</else>
</if>
</then>
</if>
</target>
<target name="setup:drush:settings" description="Create local drush settings files.">
<if>
<not><available file="${docroot}/sites/${multisite.name}/local.drushrc.php" type="file" /></not>
<then>
<if>
<available file="${docroot}/sites/${multisite.name}/default.local.drushrc.php" type="file" />
<then>
<copy file="${docroot}/sites/${multisite.name}/default.local.drushrc.php" tofile="${docroot}/sites/${multisite.name}/local.drushrc.php"/>
</then>
<else>
<copy file="${blt.root}/settings/default.local.drushrc.php" tofile="${docroot}/sites/${multisite.name}/default.local.drushrc.php"/>
<copy file="${blt.root}/settings/default.local.drushrc.php" tofile="${docroot}/sites/${multisite.name}/local.drushrc.php"/>
</else>
</if>
</then>
</if>
<echo level="verbose">Expanding Phing variables in ${docroot}/sites/${multisite.name}/local.drushrc.php...</echo>
<reflexive file="${docroot}/sites/${multisite.name}/local.drushrc.php">
<filterchain>
<expandproperties level="verbose" />
</filterchain>
</reflexive>
<!-- Re-extract value of $options['uri'] in case it was not yet set. -->
<!-- @todo Add multisite support. -->
<phpVariable file="${repo.root}/drush/drushrc.php" variable="options[uri]" outputProperty="local_url" />
</target>
<target name="setup:drupal:install"
description="Installs a specific Drupal site."
depends="setup:drupal:settings, setup:drush:settings, setup:hash-salt">
<if>
<istrue value="${drush.verbose}"/>
<then>
<echo level="verbose">Printing drush status...</echo>
<drush command="status"/>
</then>
</if>
<echo>Installing Drupal...</echo>
<drush command="site-install">
<option name="site-name">"${project.human_name}"</option>
<option name="site-mail">"${drupal.account.mail}"</option>
<option name="account-name">"${drupal.account.name}"</option>
<option name="account-pass">"${drupal.account.password}"</option>
<option name="account-mail">"${drupal.account.mail}"</option>
<param>"${project.profile.name}"</param>
<param>"install_configure_form.update_status_module='array(FALSE,FALSE)'"</param>
</drush>
<phingcall target="setup:update"/>
<!-- Set sites directory file permissions. -->
<echo level="verbose">Making ${docroot}/sites/default writable...</echo>
<chmod mode="0755" failonerror="false">
<fileset dir="${docroot}/sites/default">
<type type="dir" />
<exclude name="files/**" />
</fileset>
</chmod>
<chmod mode="0644" failonerror="false">
<fileset dir="${docroot}/sites/default">
<type type="file" />
<exclude name="files/**" />
</fileset>
</chmod>
</target>
<target name="setup:config-import" description="Import configuration from the config directory.">
<echo>Importing configuration...</echo>
<drush command="pm-enable" assume="yes" alias="${drush.alias}">
<param>config</param>
</drush>
<!-- Rebuild caches in case service definitions have changed. -->
<!-- @see https://www.drupal.org/node/2826466 -->
<drush command="cr" alias="${drush.alias}"/>
<!-- Import configuration before executing updates, in case any db updates are dependent on new configs to be imported. -->
<drush command="config-import" assume="yes" alias="${drush.alias}">
<option name="partial"></option>
<param>${cm.core.config-dir}</param>
</drush>
<!-- Execute db updates. -->
<drush command="updb" assume="yes" alias="${drush.alias}">
<option name="entity-updates"></option>
</drush>
<!-- Import configuration. -->
<drush command="config-import" assume="yes" alias="${drush.alias}">
<option name="partial"></option>
<param>${cm.core.config-dir}</param>
</drush>
<if>
<isset property="cm.features.bundle"/>
<then>
<!-- Enable features module. -->
<drush command="en" assume="yes" alias="${drush.alias}">
<param>features</param>
</drush>
<!-- Clear drush caches to register features drush commands. -->
<drush command="cc" assume="yes" alias="${drush.alias}">
<param>drush</param>
</drush>
<!-- Revert all features. -->
<foreach list="${cm.features.bundle}" param="bundle" target="setup:update:features-import" />
</then>
</if>
<!-- Rebuild caches. -->
<drush command="cr" alias="${drush.alias}"/>
</target>
<target name="setup:git-hooks" description="Installs git hooks to local .git/hooks directory from version controlled scripts/git-hooks directory.">
<exec dir="${repo.root}/.git" command="mkdir -p hooks" logoutput="true" checkreturn="true" level="${blt.exec_level}" passthru="true"/>
<delete file="${repo.root}/.git/hooks/pre-commit" failonerror="false" quiet="true" verbose="${blt.verbose}"/>
<delete file="${repo.root}/.git/hooks/commit-msg" failonerror="false" quiet="true" verbose="${blt.verbose}"/>
<if>
<not><equals arg1="${git.hooks.pre-commit}" arg2="false"/></not>
<then>
<echo level="info">Symlinking ${repo.root}/scripts/git-hooks/pre-commit to ${git.hooks.pre-commit}/pre-commit</echo>
<exec dir="${repo.root}/.git/hooks" command="ln -snv ${git.hooks.pre-commit}/pre-commit pre-commit" logoutput="true" checkreturn="true" level="${blt.exec_level}" passthru="true"/>
</then>
</if>
<if>
<not><equals arg1="${git.hooks.commit-msg}" arg2="false"/></not>
<then>
<echo level="verbose">Symlinking ${repo.root}/scripts/git-hooks/commit-msg to ${git.hooks.pre-commit}/commit-msg</echo>
<exec dir="${repo.root}/.git/hooks" command="ln -snv ${git.hooks.commit-msg}/commit-msg commit-msg" logoutput="true" checkreturn="true" level="${blt.exec_level}" passthru="true"/>
</then>
</if>
<!-- Grant execution permissions. -->
<echo level="verbose">Making git hooks executable.</echo>
<chmod mode="0755" verbose="false">
<fileset dir="${blt.root}/scripts/git-hooks">
<exclude name="**/*.sample" />
<exclude name="**/README.md" />
</fileset>
</chmod>
</target>
<target name="setup:hash-salt" description="Generates and writes a hash salt to ${repo.root}/salt.txt if one does not exist.">
<!-- If a hash salt does not exist, generate one. -->
<echo>Checking for hash salt in ${repo.root}/salt.txt</echo>
<if>
<not><available file="${repo.root}/salt.txt"/></not>
<then>
<echo>Writing hash salt to ${repo.root}/salt.txt</echo>
<randomstring propertyName="project.hash_salt" />
<exec dir="${repo.root}" command="echo '${project.hash_salt}' > salt.txt" logoutput="true" checkreturn="true" level="${blt.exec_level}"/>
</then>
<else>
<echo>${repo.root}/salt.txt already exists.</echo>
</else>
</if>
</target>
<target name="setup:update" description="Update current database to reflect the state of the Drupal file system." depends="setup:config-import">
<phingcall target="setup:toggle-modules"/>
</target>
<target name="setup:update:features-import" description="Perform a features import on the specified bundle.">
<drush command="fra" assume="yes" alias="${drush.alias}">
<option name="bundle">${bundle}</option>
</drush>
</target>
<target name="setup:toggle-modules" description="Enables and uninstalls specified modules.">
<if>
<isset property="${environment}"/>
<then>
<drush command="pm-enable" assume="yes">
<param>${modules.${environment}.enable}</param>
<option name="skip"></option>
</drush>
<drush command="pm-uninstall" assume="yes">
<param>${modules.${environment}.uninstall}</param>
</drush>
</then>
</if>
</target>
</project>