1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Builder; |
4
|
|
|
|
5
|
|
|
use ByJG\DbMigration\Database\MySqlDatabase; |
6
|
|
|
use ByJG\DbMigration\Migration; |
7
|
|
|
use ByJG\Util\Uri; |
8
|
|
|
use Composer\Script\Event; |
9
|
|
|
|
10
|
|
|
class Scripts extends _Lib |
11
|
|
|
{ |
12
|
|
|
public function __construct() |
13
|
|
|
{ |
14
|
|
|
parent::__construct(); |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @throws \ByJG\Config\Exception\ConfigNotFoundException |
19
|
|
|
* @throws \ByJG\Config\Exception\EnvironmentException |
20
|
|
|
* @throws \ByJG\Config\Exception\KeyNotFoundException |
21
|
|
|
* @throws \Psr\SimpleCache\InvalidArgumentException |
22
|
|
|
*/ |
23
|
|
|
public static function dockerBuild() |
24
|
|
|
{ |
25
|
|
|
$build = new Scripts(); |
26
|
|
|
$build->execDockerBuild(); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @throws \ByJG\Config\Exception\ConfigNotFoundException |
31
|
|
|
* @throws \ByJG\Config\Exception\EnvironmentException |
32
|
|
|
* @throws \ByJG\Config\Exception\KeyNotFoundException |
33
|
|
|
* @throws \Psr\SimpleCache\InvalidArgumentException |
34
|
|
|
*/ |
35
|
|
|
public static function dockerRun() |
36
|
|
|
{ |
37
|
|
|
$build = new Scripts(); |
38
|
|
|
$build->execDockerRun(); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param \Composer\Script\Event $event |
|
|
|
|
43
|
|
|
* @throws \ByJG\Config\Exception\ConfigNotFoundException |
44
|
|
|
* @throws \ByJG\Config\Exception\EnvironmentException |
45
|
|
|
* @throws \ByJG\Config\Exception\KeyNotFoundException |
46
|
|
|
* @throws \ByJG\DbMigration\Exception\InvalidMigrationFile |
47
|
|
|
* @throws \Psr\SimpleCache\InvalidArgumentException |
48
|
|
|
*/ |
49
|
|
|
public static function migrate(Event $event) |
50
|
|
|
{ |
51
|
|
|
$migrate = new Scripts(); |
52
|
|
|
$migrate->runMigrate($event->getArguments()); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @throws \ByJG\Config\Exception\ConfigNotFoundException |
57
|
|
|
* @throws \ByJG\Config\Exception\EnvironmentException |
58
|
|
|
* @throws \ByJG\Config\Exception\KeyNotFoundException |
59
|
|
|
* @throws \Psr\SimpleCache\InvalidArgumentException |
60
|
|
|
*/ |
61
|
|
|
public static function genRestDocs() |
62
|
|
|
{ |
63
|
|
|
$build = new Scripts(); |
64
|
|
|
$build->runGenRestDocs(); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @throws \ByJG\Config\Exception\ConfigNotFoundException |
70
|
|
|
* @throws \ByJG\Config\Exception\EnvironmentException |
71
|
|
|
* @throws \ByJG\Config\Exception\KeyNotFoundException |
72
|
|
|
* @throws \Psr\SimpleCache\InvalidArgumentException |
73
|
|
|
*/ |
74
|
|
|
public function execDockerBuild() |
75
|
|
|
{ |
76
|
|
|
$build = Psr11::container()->get('BUILDER_DOCKER_BUILD'); |
77
|
|
|
|
78
|
|
|
if (empty($build)) { |
79
|
|
|
return; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
$this->liveExecuteCommand($build); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @throws \ByJG\Config\Exception\ConfigNotFoundException |
87
|
|
|
* @throws \ByJG\Config\Exception\EnvironmentException |
88
|
|
|
* @throws \ByJG\Config\Exception\KeyNotFoundException |
89
|
|
|
* @throws \Psr\SimpleCache\InvalidArgumentException |
90
|
|
|
*/ |
91
|
|
|
public function execDockerRun() |
92
|
|
|
{ |
93
|
|
|
$deployCommand = Psr11::container()->get('BUILDER_DOCKER_RUN'); |
94
|
|
|
|
95
|
|
|
if (empty($deployCommand)) { |
96
|
|
|
return; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
$this->liveExecuteCommand($deployCommand); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @param $arguments |
105
|
|
|
* @throws \ByJG\Config\Exception\ConfigNotFoundException |
106
|
|
|
* @throws \ByJG\Config\Exception\EnvironmentException |
107
|
|
|
* @throws \ByJG\Config\Exception\KeyNotFoundException |
108
|
|
|
* @throws \ByJG\DbMigration\Exception\InvalidMigrationFile |
109
|
|
|
* @throws \Psr\SimpleCache\InvalidArgumentException |
110
|
|
|
*/ |
111
|
|
|
public function runMigrate($arguments) |
112
|
|
|
{ |
113
|
|
|
$dbConnection = Psr11::container()->get('DBDRIVER_CONNECTION'); |
114
|
|
|
|
115
|
|
|
$migration = new Migration(new Uri($dbConnection), $this->workdir . "/db"); |
116
|
|
|
$migration->registerDatabase("mysql", MySqlDatabase::class); |
117
|
|
|
$migration->addCallbackProgress(function ($cmd, $version) { |
118
|
|
|
echo "Doing $cmd, $version\n"; |
119
|
|
|
}); |
120
|
|
|
|
121
|
|
|
$argumentList = $this->extractArguments($arguments); |
122
|
|
|
|
123
|
|
|
$exec['reset'] = function () use ($migration, $argumentList) { |
|
|
|
|
124
|
|
|
if (!$argumentList["--yes"]) { |
125
|
|
|
throw new \Exception("Reset require the argument --yes"); |
126
|
|
|
} |
127
|
|
|
$migration->prepareEnvironment(); |
128
|
|
|
$migration->reset(); |
129
|
|
|
}; |
130
|
|
|
|
131
|
|
|
|
132
|
|
|
$exec["update"] = function () use ($migration, $argumentList) { |
133
|
|
|
$migration->update($argumentList["--up-to"], $argumentList["--force"]); |
134
|
|
|
}; |
135
|
|
|
|
136
|
|
|
if (isset($exec[$argumentList['command']])) { |
|
|
|
|
137
|
|
|
$exec[$argumentList['command']](); |
138
|
|
|
} |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* @param $arguments |
143
|
|
|
* @param bool $hasCmd |
144
|
|
|
* @return array |
145
|
|
|
*/ |
146
|
|
|
protected function extractArguments($arguments, $hasCmd = true) { |
147
|
|
|
$ret = [ |
148
|
|
|
'--up-to' => null, |
149
|
|
|
'--yes' => null, |
150
|
|
|
'--force' => false, |
151
|
|
|
]; |
152
|
|
|
|
153
|
|
|
$start = 0; |
154
|
|
|
if ($hasCmd) { |
155
|
|
|
$ret['command'] = isset($arguments[0]) ? $arguments[0] : null; |
156
|
|
|
$start = 1; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
for ($i=$start; $i < count($arguments); $i++) { |
|
|
|
|
160
|
|
|
$args = explode("=", $arguments[$i]); |
161
|
|
|
$ret[$args[0]] = isset($args[1]) ? $args[1] : true; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
return $ret; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* @throws \ByJG\Config\Exception\ConfigNotFoundException |
169
|
|
|
* @throws \ByJG\Config\Exception\EnvironmentException |
170
|
|
|
* @throws \ByJG\Config\Exception\KeyNotFoundException |
171
|
|
|
* @throws \Psr\SimpleCache\InvalidArgumentException |
172
|
|
|
*/ |
173
|
|
|
public function runGenRestDocs() |
174
|
|
|
{ |
175
|
|
|
$docPath = $this->workdir . '/web/docs/'; |
176
|
|
|
chdir($this->workdir); |
177
|
|
|
$this->liveExecuteCommand( |
178
|
|
|
$this->fixDir("vendor/bin/swagger") |
179
|
|
|
. " --output \"$docPath\" " |
180
|
|
|
. "--exclude vendor " |
181
|
|
|
. "--exclude docker " |
182
|
|
|
. "--exclude fw " |
183
|
|
|
. "--processor OperationId" |
184
|
|
|
); |
185
|
|
|
|
186
|
|
|
$docs = file_get_contents("$docPath/swagger.json"); |
187
|
|
|
$docs = str_replace('__HOSTNAME__', Psr11::container()->get('API_SERVER'), $docs); |
188
|
|
|
file_put_contents("$docPath/swagger.json", $docs); |
189
|
|
|
} |
190
|
|
|
} |
191
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths