-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathwebhook.php
57 lines (47 loc) · 1.51 KB
/
webhook.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
<?php
require_once __DIR__.'/vendor/autoload.php';
use Symfony\Component\Process\Process;
use Symfony\Component\Yaml\Yaml;
if (!file_exists(__DIR__.'/config.yml')) {
echo "Please, define your satis configuration in a config.yml file.\nYou can use the config.yml.dist as a template.";
exit(-1);
}
$defaults = array(
'bin' => 'bin/satis',
'json' => 'satis.json',
'webroot' => 'web/',
'user' => null,
);
$config = Yaml::parse(__DIR__.'/config.yml');
$config = array_merge($defaults, $config);
$errors = array();
if (!file_exists($config['bin'])) {
$errors[] = 'The Satis bin could not be found.';
}
if (!file_exists($config['json'])) {
$errors[] = 'The satis.json file could not be found.';
}
if (!file_exists($config['webroot'])) {
$errors[] = 'The webroot directory could not be found.';
}
if (!empty($errors)) {
echo 'The build cannot be run due to some errors. Please, review them and check your config.yml:'."\n";
foreach ($errors as $error) {
echo '- '.$error."\n";
}
exit(-1);
}
$command = sprintf('%s build %s %s', $config['bin'], $config['json'], $config['webroot']);
if (null !== $config['user']) {
$command = sprintf('sudo -u %s -i %s', $config['user'], $command);
}
$process = new Process($command);
$exitCode = $process->run(function ($type, $buffer) {
if ('err' === $type) {
echo 'E';
error_log($buffer);
} else {
echo '.';
}
});
echo "\n\n" . ($exitCode === 0 ? 'Successful rebuild!' : 'Oops! An error occured!') . "\n";