forked from DBJRdev/ditt-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RoboFile.php
209 lines (185 loc) · 5.47 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
<?php
use Robo\Tasks;
class RoboFile extends Tasks
{
const ENVS = ['test', 'dev', 'prod'];
const SRC_DIR = __DIR__ . '/src';
const CONFIG_DIR = __DIR__ . '/config';
const CACHE_DIR = __DIR__ . '/var/cache';
const TESTS_DIR = __DIR__ . '/tests';
const TEMPLATES_DIR = __DIR__ . '/templates';
const CODECEPTION_SUITES = ['api', 'unit', 'acceptance'];
const DEPLOYMENT_TAR = 'deployment.tar.gz';
const DEPLOYMENT_FOLDER = 'deployment';
public function install()
{
$this->stopOnFail(true);
$this->createConfigs();
$this->build();
$this->dbCreateProd();
$this->dbCreateTest();
$this->dbMigrateProd();
$this->dbMigrateTest();
$this->test();
}
public function update()
{
$this->stopOnFail(true);
$this->build();
$this->clearCache();
$this->dbMigrateProd();
$this->dbMigrateTest();
$this->build();
$this->test();
}
public function deployFinalize($phpBin = null)
{
$this->stopOnFail(true);
$this->clearCache('prod', $phpBin);
$this->dbMigrateProd($phpBin);
$this->clearCache('prod', $phpBin);
}
public function test()
{
$this->stopOnFail(true);
$this->lintPhp();
$this->lintYaml();
$this->lintTwig();
$this->phpcs();
$this->taskExec('vendor/bin/codecept build')->run();
// Temporary disabled
// $this->phpStan();
$this->codecept();
}
public function codecept($suite = null)
{
$suites = $suite ? [$suite] : self::CODECEPTION_SUITES;
foreach ($suites as $suite) {
$task = $this->taskCodecept('vendor/bin/codecept');
$task = $task->suite($suite);
$task->run();
}
}
private function lintYaml()
{
$this
->taskExec('bin/console lint:yaml')
->args(self::CONFIG_DIR)
->run();
}
private function lintTwig()
{
$this
->taskExec('bin/console lint:twig')
->args(self::TEMPLATES_DIR)
->run();
}
public function lintPhp()
{
$this
->taskExec(vsprintf('find %s -name "*.php" -print0 | xargs -0 -n1 -P8 php -l', [
implode(' ', [
self::SRC_DIR,
self::TESTS_DIR,
]),
]))
->run();
}
public function phpcs()
{
$this
->taskExec('vendor/bin/phpcs')
->args('--standard=.php_cs_ruleset.xml')
->args('--encoding=utf-8')
->args(sprintf('--ignore=%s/**/_bootstrap.php', self::TESTS_DIR))
->args(sprintf('--ignore=%s/_support/*Tester.php', self::TESTS_DIR))
->args(self::SRC_DIR)
->args(self::TESTS_DIR)
->run();
$this
->taskExec('vendor/bin/php-cs-fixer fix')
->args('--dry-run')
->args('--diff')
->args('--config', '.php_cs')
->run();
}
public function phpcsFix()
{
$this
->taskExec('vendor/bin/php-cs-fixer fix')
->args('--diff')
->args('--config', '.php_cs')
->run();
}
public function phpStan()
{
$this
->taskExec('vendor/bin/phpstan')
->args('analyze')
->args(self::SRC_DIR)
->args('-c', 'phpstan.neon')
->args('--level', 7)
->run();
}
public function build()
{
$this->taskComposerInstall()
->optimizeAutoloader()
->run();
$this->clearCache();
$this->taskExec('bin/console assets:install')->run();
}
private function createConfigs()
{
$file = '/.env';
if (!realpath($file) && realpath($file . '.dist')) {
copy($file . '.dist', $file);
}
}
private function dbCreateProd($phpBin = null) {
$this
->taskExec(($phpBin !== null ? $phpBin . ' ' : '') . 'bin/console doctrine:database:create')
->args('--env=prod')
->run();
}
private function dbCreateTest($phpBin = null) {
$this
->taskExec(($phpBin !== null ? $phpBin . ' ' : '') . 'bin/console doctrine:database:create')
->args('--env=test')
->run();
}
private function dbMigrateProd($phpBin = null)
{
$this
->taskExec(($phpBin !== null ? $phpBin . ' ' : '') . 'bin/console doctrine:migrations:migrate')
->args('--no-interaction')
->args('--env=prod')
->run();
}
private function dbMigrateTest($phpBin = null)
{
$this
->taskExec(($phpBin !== null ? $phpBin . ' ' : '') .'bin/console doctrine:migrations:migrate')
->args('--no-interaction')
->args('--env=test')
->run();
}
private function clearCache($env = null, $phpBin = null)
{
$warmUp = function ($env, $phpBin) {
$this
->taskExec(($phpBin !== null ? $phpBin . ' ' : '') . 'bin/console cache:clear')
->args(sprintf('--env=%s', $env))
->run();
};
$this->stopOnFail(true);
$this->taskExec('rm -rf var/cache/*')->run();
if ($env) {
$warmUp($env, $phpBin);
return;
}
foreach (self::ENVS as $env) {
$warmUp($env, $phpBin);
}
}
}