98 lines
2.7 KiB
Plaintext
Raw Normal View History

2014-07-04 12:15:38 +04:00
#!/usr/bin/env php
2013-07-11 15:47:09 +04:00
<?php
2016-01-11 12:51:59 +07:00
/* (c) Anton Medvedev <anton@medv.io>
2013-07-11 15:47:09 +04:00
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
// Detect deploy.php location
2020-04-25 23:00:08 +03:00
$deployFile = null;
2020-10-15 22:12:17 +02:00
foreach ($argv as $i => $arg) {
if (preg_match('/^(-f|--file)$/', $arg, $match) && $i + 1 < count($argv)) {
$deployFile = $argv[$i + 1];
break;
2020-10-15 22:12:17 +02:00
}
if (preg_match('/^--file=(?<file>.+)$/', $arg, $match)) {
2020-10-15 22:12:17 +02:00
$deployFile = $match['file'];
break;
2020-10-15 22:12:17 +02:00
}
if (preg_match('/^-f=?(?<file>.+)$/', $arg, $match)) {
$deployFile = $match['file'];
break;
2020-10-15 22:12:17 +02:00
}
}
if (!empty($deployFile)) {
$deployFile = realpath($deployFile);
}
$lookUp = function (string $name): ?string {
2020-10-15 22:12:17 +02:00
$dir = getcwd();
for ($i = 0; $i < 10; $i++) {
$path = "$dir/$name";
if (is_readable($path)) {
return $path;
}
$dir = dirname($dir);
2016-11-07 20:43:31 +07:00
}
return '';
2020-10-15 22:12:17 +02:00
};
if (empty($deployFile)) {
$deployFile = $lookUp('deploy.php');
}
if (empty($deployFile)) {
$deployFile = $lookUp('deploy.yaml');
}
2021-10-21 21:14:30 +02:00
if (empty($deployFile)) {
$deployFile = $lookUp('deploy.yml');
}
2014-07-04 13:39:57 +04:00
// Detect autoload location
2016-11-12 17:02:13 +07:00
$autoload = [
__DIR__ . '/../vendor/autoload.php', // The dep located at "deployer.phar/bin" or in development.
__DIR__ . '/../../../autoload.php', // The dep located at "vendor/deployer/deployer/bin".
__DIR__ . '/../autoload.php', // The dep located at "vendor/bin".
2016-11-12 17:02:13 +07:00
];
$includes = [
__DIR__ . '/..',
2016-11-12 17:02:13 +07:00
__DIR__ . '/../../../deployer/deployer',
__DIR__ . '/../deployer/deployer',
2016-11-12 17:02:13 +07:00
];
$includePath = false;
for ($i = 0; $i < count($autoload); $i++) {
if (file_exists($autoload[$i]) && is_dir($includes[$i])) {
2016-11-12 17:02:13 +07:00
require $autoload[$i];
$includePath = $includes[$i];
break;
2016-11-12 17:02:13 +07:00
}
}
if (empty($includePath)) {
fwrite(STDERR, "Error: The `autoload.php` file not found in:\n");
for ($i = 0; $i < count($autoload); $i++) {
$a = file_exists($autoload[$i]) ? 'true' : 'false';
$b = is_dir($includes[$i]) ? 'true' : 'false';
fwrite(STDERR, " - file_exists($autoload[$i]) = $a\n");
fwrite(STDERR, " is_dir($includes[$i]) = $b\n");
}
exit(1);
}
2016-11-12 17:02:13 +07:00
// Errors to exception
set_error_handler(function ($severity, $message, $filename, $lineno) {
if (error_reporting() == 0) {
return;
}
if (error_reporting() & $severity) {
throw new ErrorException($message, 0, $severity, $filename, $lineno);
}
});
2016-11-12 17:02:13 +07:00
// Enable recipe loading
2016-11-12 17:02:13 +07:00
set_include_path($includePath . PATH_SEPARATOR . get_include_path());
// Deployer constants
define('DEPLOYER', true);
define('DEPLOYER_BIN', __FILE__);
2020-11-04 19:20:23 +01:00
define('DEPLOYER_DEPLOY_FILE', $deployFile);
2022-03-17 20:32:27 +01:00
Deployer\Deployer::run('master', $deployFile);