forked from redCOMPONENT-COM/redSHOP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RoboFile.php
323 lines (286 loc) · 8.81 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
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
<?php
/**
* This is project's console commands configuration for Robo task runner.
*
* Download robo.phar from http://robo.li/robo.phar and type in the root of the repo: $ php robo.phar
* Or do: $ composer update, and afterwards you will be able to execute robo like $ php vendor/bin/robo
*
* @see http://robo.li/
* @copyright Copyright (C) 2008 - 2020 redCOMPONENT.com. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
require_once 'vendor/autoload.php';
/**
* Class RoboFile
*
* @since 1.0.0
*/
class RoboFile extends \Robo\Tasks
{
// Load tasks from composer, see composer.json
use Joomla\Testing\Robo\Tasks\LoadTasks;
/**
* @var array
* @var array
* @since __DEPLOY_VERSION__
*/
private $defaultArgs = [
'--tap',
'--fail-fast'
];
/**
* Downloads and prepares a Joomla CMS site for testing
*
* @param integer $use_htaccess (1/0) Rename and enable embedded Joomla .htaccess file
* @param integer $cleanUp Clean up the directory when present (or skip the cloning process)
*
* @return void
* @since 1.0.0
*/
public function testsSitePreparation($use_htaccess = 1, $cleanUp = 1)
{
$skipCleanup = false;
// Get Joomla Clean Testing sites
if (is_dir('tests/joomla-cms'))
{
if (!$cleanUp)
{
$skipCleanup = true;
$this->say('Using cached version of Joomla CMS and skipping clone process');
}
else
{
$this->taskDeleteDir('tests/joomla-cms')->run();
}
}
if (!$skipCleanup)
{
$version = 'staging';
/*
* When joomla Staging branch has a bug you can uncomment the following line as a tmp fix for the tests layer.
* Use as $version value the latest tagged stable version at: https://github.com/joomla/joomla-cms/releases
*/
$version = '3.9.18';
$this->_exec("git clone -b $version --single-branch --depth 1 https://github.com/joomla/joomla-cms.git tests/joomla-cms");
$this->say("Joomla CMS ($version) site created at tests/joomla-cms");
}
// Optionally uses Joomla default htaccess file
if ($use_htaccess == 1)
{
$this->_copy('tests/joomla-cms/htaccess.txt', 'tests/joomla-cms/.htaccess');
$this->_exec('sed -e "s,# RewriteBase /,RewriteBase /tests/joomla-cms/,g" --in-place tests/joomla-cms/.htaccess');
}
}
/**
* Downloads Paid Extensions for Integration Testing testing
*
* @param integer $cleanUp Clean up the directory when present (or skip the cloning process)
*
* @return void
* @since 2.1.2
*/
public function testsPaidExtensionsForIntegrationTests($cleanUp = 1)
{
// Delete any previous core
if (is_dir('tests/extension/paid-extensions'))
{
if (!$cleanUp)
{
$this->say('Using cached version of Aesir Core and skipping clone process');
return;
}
$this->taskDeleteDir('tests/extension/paid-extensions')->run();
}
$version = 'master';
$this->_exec("git clone --recursive -b $version --single-branch https://REDWEB_QA_TOKEN:[email protected]/redshop-extensions/redshop-paid-extensions tests/extension/paid-extensions");
$this->say("paid-extensions ($version) cloned at tests/extension/");
}
/**
* Tests setup
*
* @param boolean $debug Add debug to the parameters
* @param boolean $steps Add steps to the parameters
* @param boolean $extraVerbose Add extra verbosity
*
* @return void
* @since __DEPLOY_VERSION__
*/
public function testsSetup($debug = true, $steps = true, $extraVerbose = false)
{
$args = [];
if ($debug)
{
$args[] = '--debug';
}
if ($steps)
{
$args[] = '--steps';
}
if ($extraVerbose)
{
$args[] = '-vvv';
}
$args = array_merge(
$args,
$this->defaultArgs
);
// Sets the output_append variable in case it's not yet
if (getenv('output_append') === false)
{
putenv('output_append=');
}
// Builds codeception
$this->_exec("vendor/bin/codecept build");
// Executes the initial set up
$this->taskCodecept()
->args($args)
->arg('tests/acceptance/install/core')
->run()
->stopOnFail();
}
/**
* Individual test folder execution
*
* @param string $folder Folder to execute codecept run to
* @param boolean $debug Add debug to the parameters
* @param boolean $steps Add steps to the parameters
* @param boolean $extraVerbose Add extra verbosity
*
* @return void
* @since __DEPLOY_VERSION__
*/
public function testsRun($folder, $debug = true, $steps = true, $extraVerbose = false)
{
$args = [];
if ($debug)
{
$args[] = '--debug';
}
if ($steps)
{
$args[] = '--steps';
}
if ($extraVerbose)
{
$args[] = '-vvv';
}
$args = array_merge(
$args,
$this->defaultArgs
);
// Sets the output_append variable in case it's not yet
if (getenv('output_append') === false)
{
putenv('output_append=');
}
// Codeception build
$this->_exec("vendor/bin/codecept build");
// Actual execution of Codeception test
$this->taskCodecept()
->args($args)
->arg('tests/' . $folder . '/')
->run()
->stopOnFail();
}
/**
* Sends the build report error back to Slack
*
* @param string $cloudinaryName Cloudinary cloud name
* @param string $cloudinaryApiKey Cloudinary API key
* @param string $cloudinaryApiSecret Cloudinary API secret
* @param string $githubRepository GitHub repository (owner/repo)
* @param string $githubPRNo GitHub PR #
* @param string $slackWebhook Slack Webhook URL
* @param string $slackChannel Slack channel
* @param string $buildURL Build URL
*
* @return void
* @since __DEPLOY_VERSION__
*/
public function sendBuildReportErrorSlack($cloudinaryName, $cloudinaryApiKey, $cloudinaryApiSecret, $githubRepository, $githubPRNo, $slackWebhook, $slackChannel, $buildURL = '')
{
$directories = glob('tests/_output/*' , GLOB_ONLYDIR);
foreach ($directories as $directory)
{
$this->sendBuildReportErrorSlackDirectory($directory, $cloudinaryName, $cloudinaryApiKey, $cloudinaryApiSecret, $githubRepository, $githubPRNo, $slackWebhook, $slackChannel, $buildURL);
}
}
/**
* Sends the build report error back to Slack
*
* @param string $directory Directory to explore
* @param string $cloudinaryName Cloudinary cloud name
* @param string $cloudinaryApiKey Cloudinary API key
* @param string $cloudinaryApiSecret Cloudinary API secret
* @param string $githubRepository GitHub repository (owner/repo)
* @param string $githubPRNo GitHub PR #
* @param string $slackWebhook Slack Webhook URL
* @param string $slackChannel Slack channel
* @param string $buildURL Build URL
*
* @return void
* @since __DEPLOY_VERSION__
*/
public function sendBuildReportErrorSlackDirectory($directory, $cloudinaryName, $cloudinaryApiKey, $cloudinaryApiSecret, $githubRepository, $githubPRNo, $slackWebhook, $slackChannel, $buildURL = '')
{
$errorSelenium = true;
$reportError = false;
$reportFile = $directory . '/selenium.log';
$errorLog = 'Selenium log in ' . $directory . ':' . chr(10). chr(10);
$this->say('Starting to Prepare Build Report');
$this->say('Exploring folder ' . $directory . ' for error reports');
// Loop through Codeception snapshots
if (file_exists($directory) && $handler = opendir($directory))
{
$reportFile = $directory . '/report.tap.log';
$errorLog = 'Codeception tap log in ' . $directory . ':' . chr(10). chr(10);
$errorSelenium = false;
}
if (file_exists($reportFile))
{
$this->say('Report File Prepared');
if ($reportFile)
{
$errorLog .= file_get_contents($reportFile, null, null, 15);
}
if (!$errorSelenium)
{
$handler = opendir($directory);
$errorImage = '';
while (!$reportError && false !== ($errorSnapshot = readdir($handler)))
{
// Avoid sending system files or html files
if (!('png' === pathinfo($errorSnapshot, PATHINFO_EXTENSION)))
{
continue;
}
$reportError = true;
$errorImage = $directory . '/' . $errorSnapshot;
}
}
if ($reportError || $errorSelenium)
{
// Sends the error report to Slack
$this->say('Sending Error Report');
$reportingTask = $this->taskReporting()
->setCloudinaryCloudName($cloudinaryName)
->setCloudinaryApiKey($cloudinaryApiKey)
->setCloudinaryApiSecret($cloudinaryApiSecret)
->setGithubRepo($githubRepository)
->setGithubPR($githubPRNo)
->setBuildURL($buildURL . 'display/redirect')
->setSlackWebhook($slackWebhook)
->setSlackChannel($slackChannel)
->setTapLog($errorLog);
if (!empty($errorImage))
{
$reportingTask->setImagesToUpload($errorImage)
->publishCloudinaryImages();
}
$reportingTask->publishBuildReportToSlack()
->run()
->stopOnFail();
}
}
}
}