-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregenerate.php
45 lines (38 loc) · 1.48 KB
/
regenerate.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
<?php
require_once __DIR__ . '/vendor/autoload.php';
use Composer\Satis\Command\BuildCommand;
use Composer\Satis\Console\Application;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\BufferedOutput;
use Symfony\Component\Console\Output\StreamOutput;
use Github\Client as Github;
function regenerate_fn(GearmanJob $job) {
echo "[worker] Received job: " . $job->handle() . "\n";
// Pull newest satis.json file.
echo "[worker] Downloading latest satis.json...\n";
$github = new Github();
$github->authenticate(getenv('GITHUB_TOKEN'), null, Github::AUTH_HTTP_TOKEN);
$satisjson = $github->api('repo')->contents()->download('lotgd', 'code.lot.gd', 'satis.json');
echo "[worker] Got " . mb_strlen($satisjson, '8bit') . " bytes.\n";
file_put_contents('satis.json', $satisjson);
echo "[worker] Regenerating using Satis...\n";
$application = new Application();
$application->setAutoExit(false);
$input = new ArrayInput(array(
'--no-interaction' => 'true',
'command' => 'build',
'file' => 'satis.json',
'output-dir' => './generated',
'--skip-errors' => 'true'
));
$output = new BufferedOutput();
$ret = $application->run($input, $output);
$content = $output->fetch();
$line = strtok($content, "\n");
while ($line !== false) {
$line = strtok("\n");
echo "[worker] " . $line . "\n";
}
echo "[worker] Satis return value: {$ret}\n";
return $ret;
}