forked from WyriHaximus/github-action-wait-for-status
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwait.php
52 lines (48 loc) · 1.87 KB
/
wait.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
<?php declare(strict_types=1);
use ApiClients\Client\Github\Authentication\Token;
use Bramus\Monolog\Formatter\ColoredLineFormatter;
use Monolog\Logger;
use React\EventLoop\Loop;
use WyriHaximus\GithubAction\WaitForStatus\App;
use WyriHaximus\Monolog\FormattedPsrHandler\FormattedPsrHandler;
use WyriHaximus\React\PSR3\Stdio\StdioLogger;
use function Safe\json_decode;
use function Safe\file_get_contents;
require __DIR__ . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
const REPOSITORY = 'GITHUB_REPOSITORY';
const TOKEN = 'GITHUB_TOKEN';
const SHA = 'GITHUB_SHA';
const EVENT = 'GITHUB_EVENT_NAME';
const EVENT_PATH = 'GITHUB_EVENT_PATH';
const API_BASE_URL = 'GITHUB_API_URL';
const ACTIONS = 'INPUT_IGNOREACTIONS';
const INTERVAL = 'INPUT_CHECKINTERVAL';
const WAIT_FOR_CHECK = 'INPUT_WAITFORCHECK';
(function () {
$consoleHandler = new FormattedPsrHandler(StdioLogger::create(Loop::get())->withHideLevel(true));
$consoleHandler->setFormatter(new ColoredLineFormatter(
null,
'[%datetime%] %channel%.%level_name%: %message%',
'Y-m-d H:i:s.u',
true,
false
));
$logger = new Logger('wait');
$logger->pushHandler($consoleHandler);
$shas = [];
$shas[] = getenv(SHA);
if (getenv(EVENT) === 'pull_request') {
$logger->notice('Pull Request detected');
$shas[] = json_decode(file_get_contents(getenv(EVENT_PATH)))->pull_request->head->sha;
}
App::boot($logger, new Token(getenv(TOKEN)), getenv(API_BASE_URL))->wait(
getenv(REPOSITORY),
getenv(ACTIONS),
(float) getenv(INTERVAL) > 0.0 ? (float) getenv(INTERVAL) : 13,
getenv(WAIT_FOR_CHECK) != "",
...$shas,
)->then(function (string $state) use($logger) {
$logger->info('Final status: ' . $state);
echo PHP_EOL, '::set-output name=status::' . $state, PHP_EOL;
})->done();
})();