deploy-pusher
#!/usr/bin/env php
<?php
if (file_exists(__DIR__.'/../../autoload.php')) {
require __DIR__.'/../../autoload.php';
} else {
require __DIR__.'/vendor/autoload.php';
}
use CapsLockStudio\Deploy\Pusher\Option;
use CapsLockStudio\Deploy\Pusher\Context;
$wrapper = stream_get_wrappers();
$json = (new Option())->get();
if (!in_array("http", $wrapper)) {
echo "HTTP wrapper is required", PHP_EOL;
exit(1);
}
if (!in_array("https", $wrapper)) {
echo "HTTPS Wrapper is required.", PHP_EOL;
exit(1);
}
if (!($json["dist"] && $json["owner"] && $json["repo"])) {
echo "I cannot find config file :(", PHP_EOL;
exit(1);
}
$success = [];
$failed = [];
$lost = [];
$deploy = getenv("DEPLOY_HOST") ?: "";
$deploy = explode(",", $deploy);
foreach ($deploy as $host) {
echo "host: {$host}, deploying ...", PHP_EOL;
$header = (new Context())->set($json)->execute($host)->getHeader();
switch (true) {
case $header->isFatal():
case $header->isError():
$failed[] = $host;
break;
case $header->isTimeout():
$lost[] = $host;
break;
default:
$success[] = $host;
break;
}
}
if ($failed && !$json["rollback"]) {
$json["tag"] = false;
foreach ($success as $host) {
(new Context())->set($json)->execute($host);
}
exit(1);
}