-
Notifications
You must be signed in to change notification settings - Fork 9
/
RoboFile.php
206 lines (189 loc) · 5.63 KB
/
RoboFile.php
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
<?php
// @codingStandardsIgnoreStart
/**
* Base tasks for setting up a module to test within a full Drupal environment.
*
* @class RoboFile
* @codeCoverageIgnore
*/
class RoboFile extends \Robo\Tasks {
/**
* Command to build the environment
*
* @return \Robo\Result
* The result of the collection of tasks.
*/
public function jobBuild() {
$collection = $this->collectionBuilder();
$collection->addTaskList($this->copyConfigurationFiles());
$collection->addTaskList($this->runComposer());
return $collection->run();
}
/**
* Command to run unit tests.
*
* @return \Robo\Result
* The result of the collection of tasks.
*/
public function jobUnitTests() {
$collection = $this->collectionBuilder();
$collection->addTaskList($this->runUnitTests());
return $collection->run();
}
/**
* Command to generate a coverage report.
*
* @return \Robo\Result
* The result of the collection of tasks.
*/
public function jobCoverageReport() {
$collection = $this->collectionBuilder();
$collection->addTaskList($this->runCoverageReport());
return $collection->run();
}
/**
* Command to check for Drupal's Coding Standards.
*
* @return \Robo\Result
* The result of the collection of tasks.
*/
public function jobCodingStandards() {
$collection = $this->collectionBuilder();
$collection->addTaskList($this->runCodeSniffer());
return $collection->run();
}
/**
* Command to run existing site tests.
*
* @return \Robo\Result
* The result tof the collection of tasks.
*/
public function jobExistingSiteTests() {
$collection = $this->collectionBuilder();
$collection->addTaskList($this->runUpdateDatabase());
$collection->addTaskList($this->runExistingSiteTests());
return $collection->run();
}
/**
* Command to run Chrome headless.
*
* @return \Robo\Result
* The result tof the task
*/
public function runChromeHeadless() {
return $this->taskExec('google-chrome-unstable --disable-gpu --headless --no-sandbox --remote-debugging-address=0.0.0.0 --remote-debugging-port=9222')->run();
}
/**
* Updates the database.
*
* @return \Robo\Task\Base\Exec[]
* An array of tasks.
*/
protected function runUpdateDatabase() {
$tasks = [];
$tasks[] = $this->drush()
->args('updatedb')
->option('yes')
->option('verbose');
$tasks[] = $this->drush()
->args('config:import')
->option('yes')
->option('verbose');
$tasks[] = $this->drush()->args('cache:rebuild')->option('verbose');
return $tasks;
}
/**
* Run unit tests.
*
* @return \Robo\Task\Base\Exec[]
* An array of tasks.
*/
protected function runUnitTests() {
$tasks = [];
$tasks[] = $this->taskExecStack()
->exec('vendor/bin/phpunit --debug --verbose --testsuite=unit,kernel --log-junit=junit.xml');
return $tasks;
}
/**
* Generates a code coverage report.
*
* @return \Robo\Task\Base\Exec[]
* An array of tasks.
*/
protected function runCoverageReport() {
$tasks = [];
$tasks[] = $this->taskExecStack()
->exec('vendor/bin/phpunit --debug --verbose --coverage-html ../coverage --testsuite=unit,kernel');
return $tasks;
}
/**
* Sets up and runs code sniffer.
*
* @return \Robo\Task\Base\Exec[]
* An array of tasks.
*/
protected function runCodeSniffer() {
$tasks = [];
$tasks[] = $this->taskExecStack()
->exec('vendor/bin/phpcs --config-set installed_paths vendor/drupal/coder/coder_sniffer');
$tasks[] = $this->taskFilesystemStack()
->mkdir('artifacts/phpcs');
$tasks[] = $this->taskExecStack()
->exec('vendor/bin/phpcs --standard=Drupal --report=junit --report-junit=artifacts/phpcs/phpcs.xml web/modules/custom')
->exec('vendor/bin/phpcs --standard=DrupalPractice --report=junit --report-junit=artifacts/phpcs/phpcs.xml web/modules/custom');
return $tasks;
}
/**
* Runs existing site tests.
*
* @return \Robo\Task\Base\Exec[]
* An array of tasks.
*/
protected function runExistingSiteTests() {
$tasks = [];
$tasks[] = $this->taskExec('sed -ri -e \'s!/var/www/html/web!' . getenv('GITHUB_WORKSPACE') . '/web!g\' /etc/apache2/sites-available/*.conf /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf');
$tasks[] = $this->taskExec('service apache2 start');
$tasks[] = $this->taskExec('vendor/bin/phpunit --debug --verbose --bootstrap=vendor/weitzman/drupal-test-traits/src/bootstrap-fast.php --testsuite=existing-site,existing-site-javascript');
return $tasks;
}
/**
* Return drush with default arguments.
*
* @return \Robo\Task\Base\Exec
* A drush exec command.
*/
protected function drush() {
return $this->taskExec('vendor/bin/drush');
}
/**
* Copies configuration files.
*
* @return \Robo\Task\Base\Exec[]
* An array of tasks.
*/
protected function copyConfigurationFiles() {
$force = TRUE;
$tasks = [];
$tasks[] = $this->taskFilesystemStack()
->copy('.github/config/settings.local.php',
'web/sites/default/settings.local.php', $force)
->copy('.github/config/.env',
'.env', $force);
return $tasks;
}
/**
* Runs composer commands.
*
* @return \Robo\Task\Base\Exec[]
* An array of tasks.
*/
protected function runComposer() {
$tasks = [];
$tasks[] = $this->taskComposerValidate()->noCheckPublish();
$tasks[] = $this->taskComposerInstall()
->noInteraction()
->envVars(['COMPOSER_ALLOW_SUPERUSER' => 1, 'COMPOSER_DISCARD_CHANGES' => 1] + getenv())
->optimizeAutoloader();
return $tasks;
}
}