forked from techdivision/import-cli-simple
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RoboFile.php
298 lines (258 loc) · 8.52 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
<?php
/**
* RoboFile.php
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
*
* PHP version 5
*
* @author Tim Wagner <t.wagner@techdivision.com>
* @copyright 2016 TechDivision GmbH <info@techdivision.com>
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @link https://github.com/techdivision/import-cli-simple
* @link http://www.techdivision.com
*/
use Lurker\Event\FilesystemEvent;
use Symfony\Component\Finder\Finder;
/**
* Defines the available build tasks.
*
* @author Tim Wagner <t.wagner@techdivision.com>
* @copyright 2016 TechDivision GmbH <info@techdivision.com>
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @link https://github.com/techdivision/import-cli-simple
* @link http://www.techdivision.com
*/
class RoboFile extends \Robo\Tasks
{
/**
* The build properties.
*
* @var array
*/
protected $properties = array(
'base.dir' => __DIR__,
'etc.dir' => __DIR__ . '/etc',
'dist.dir' => __DIR__ . '/dist',
'vendor.dir' => __DIR__ . '/vendor',
'target.dir' => __DIR__ . '/target',
'symfony.dir' => __DIR__ . '/symfony',
'webapp.name' => 'import-cli-simple',
'webapp.version' => '3.7.4'
);
/**
* Run's the composer install command.
*
* @return void
*/
public function composerInstall()
{
// optimize autoloader with custom path
$this->taskComposerInstall()
->preferDist()
->optimizeAutoloader()
->run();
}
/**
* Run's the composer update command.
*
* @return void
*/
public function composerUpdate()
{
// optimize autoloader with custom path
$this->taskComposerUpdate()
->preferDist()
->optimizeAutoloader()
->run();
}
/**
* Clean up the environment for a new build.
*
* @return void
*/
public function clean()
{
$this->taskDeleteDir($this->properties['target.dir'])->run();
}
/**
* Prepare's the environment for a new build.
*
* @return void
*/
public function prepare()
{
$this->taskFileSystemStack()
->mkdir($this->properties['dist.dir'])
->mkdir($this->properties['target.dir'])
->mkdir(sprintf('%s/reports', $this->properties['target.dir']))
->run();
}
/**
* Creates the a PHAR archive from the sources.
*
* @return void
*/
public function createPhar()
{
// run the build process
$this->build();
// prepare the PHAR archive name
$archiveName = sprintf(
'%s/%s.phar',
$this->properties['target.dir'],
$this->properties['webapp.name']
);
// prepare the target directory
$targetDir = $this->properties['target.dir'] . DIRECTORY_SEPARATOR . $this->properties['webapp.version'];
// copy the composer.json file
$this->taskFilesystemStack()
->copy(
__DIR__ . DIRECTORY_SEPARATOR . 'composer.json',
$targetDir. DIRECTORY_SEPARATOR. 'composer.json'
)->run();
// copy the .semver file
$this->taskFilesystemStack()
->copy(
__DIR__ . DIRECTORY_SEPARATOR . '.semver',
$targetDir. DIRECTORY_SEPARATOR. '.semver'
)->run();
// copy the bootstrap.php file
$this->taskFilesystemStack()
->copy(
__DIR__ . DIRECTORY_SEPARATOR . 'bootstrap.php',
$targetDir. DIRECTORY_SEPARATOR. 'bootstrap.php'
)->run();
// install the composer dependencies
$this->taskComposerInstall()
->dir($targetDir)
->noDev()
->optimizeAutoloader()
->run();
// prepare the task
$pharTask = $this->taskPackPhar($archiveName)
->compress()
->stub('stub.php');
// load a list with all the source files from the vendor directory
$finder = Finder::create()->files()
->name('*.php')
->name('.semver')
->name('services.xml')
->name('services-1.0.xsd')
->name('techdivision-import.json')
->in($targetDir)
->ignoreDotFiles(false);
// iterate over the source files of the vendor directory and add them to the PHAR archive
foreach ($finder as $file) {
$pharTask->addFile($file->getRelativePathname(), $file->getRealPath());
}
// create the PHAR archive
$pharTask->run();
// verify PHAR archive is packed correctly
$this->_exec(sprintf('php %s', $archiveName));
// prepare the PHAR archive distribution name
$distArchiveName = sprintf('%s/%s.phar', $this->properties['dist.dir'], $this->properties['webapp.name']);
// clean up the dist directory
$this->taskCleanDir($this->properties['dist.dir'])->run();
// copy the latest PHAR archive to the dist directory
$this->taskFilesystemStack()->copy($archiveName, $distArchiveName)->run();
}
/**
* Run's the PHPUnit testsuite.
*
* @return void
*/
public function runTestsUnit()
{
// run PHPUnit
$this->taskPHPUnit(sprintf('%s/bin/phpunit --testsuite "techdivision/import-cli-simple PHPUnit testsuite"', $this->properties['vendor.dir']))
->configFile('phpunit.xml')
->run();
}
/**
* Run's the integration testsuite.
*
* This task uses the Magento 2 docker image generator from https://github.com/techdivision/magento2-docker-imgen. To execute
* this task, it is necessary that you've setup a running container with the domain name, passed as argument.
*
* @return void
*/
public function runTestsIntegration($containerName, $domainName)
{
// prepare the filesystem
$this->prepare();
// initialize the variables to query whether or not the docker container has been started successfully
$counter = 0;
$magentoNotAvailable = true;
do {
// reset the result of the CURL request
$res = null;
// query whether or not the image already has been loaded
exec(
str_replace(
array('{domain-name}'),
array($domainName),
'curl --resolve {domain-name}:80:127.0.0.1 http://{domain-name}/magento_version'
),
$res
);
// query whether or not the Docker has been started
foreach ($res as $val) {
if (strstr($val, 'Magento/')) {
$magentoNotAvailable = false;
}
}
// raise the counter
$counter++;
// sleep while the docker container is not available
if ($magentoNotAvailable === true) {
sleep(1);
}
} while ($magentoNotAvailable && $counter < 30);
// grant the privilieges to connection from outsite the container
$this->taskDockerExec($containerName)
->interactive()
->exec('mysql -uroot -proot -e \'GRANT ALL ON *.* TO "magento"@"%" IDENTIFIED BY "magento"\'')
->run();
// flush the privileges
$this->taskDockerExec($containerName)
->interactive()
->exec('mysql -uroot -proot -e "FLUSH PRIVILEGES"')
->run();
// run the integration testsuite
$this->taskPHPUnit(
sprintf(
'%s/bin/phpunit --testsuite "techdivision/import-cli-simple PHPUnit integration testsuite"',
$this->properties['vendor.dir']
)
)
->configFile('phpunit.xml')
->run();
}
/**
* Raising the semver version number.
*
* @return void
*/
public function semver()
{
$this->taskSemVer('.semver')
->prerelease('beta')
->run();
}
/**
* The complete build process.
*
* @return void
*/
public function build()
{
$this->clean();
$this->prepare();
$this->runTestsUnit();
}
}