112 lines
3.3 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];
}
if (preg_match('/^(-f|--file)=(?<file>.+?)$/', $arg, $match)) {
$deployFile = $match['file'];
}
2020-04-25 23:00:08 +03:00
2020-10-15 22:12:17 +02:00
if (!empty($deployFile)) {
$deployFile = ($deployFile[0] === '/' ? '' : getcwd() . '/') . $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
}
2020-10-15 22:12:17 +02:00
return null;
};
if (empty($deployFile)) {
$deployFile = $lookUp('deploy.php');
}
if (empty($deployFile)) {
$deployFile = $lookUp('deploy.yaml');
}
2014-07-04 13:39:57 +04:00
2021-10-14 20:05:46 +02:00
// Find project-local Deployer installation
2021-10-19 17:25:03 +02:00
if (!isset($localBinaryOverrideFound)) {
$binaries = [
dirname($deployFile) . '/vendor/bin/dep',
dirname($deployFile) . '/deployer.phar',
getcwd() . '/vendor/bin/dep',
getcwd() . '/deployer.phar',
];
foreach ($binaries as $binary) {
if (file_exists($binary)) {
2021-10-19 23:14:23 +02:00
if (realpath($binary) === realpath(__FILE__)) {
break; // Already required this binary
}
2021-10-19 17:25:03 +02:00
$localBinaryOverrideFound = true; // Only do it once.
require $binary;
exit;
2021-10-14 20:05:46 +02:00
}
}
}
2016-11-12 17:02:13 +07: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__);
2021-10-19 21:15:45 +00:00
define('DEPLOYER_VERSION', '7.0.0-master');
2020-11-04 19:20:23 +01:00
define('DEPLOYER_DEPLOY_FILE', $deployFile);
define('DEPLOYER_ROOT', getenv('DEPLOYER_ROOT') !== false ? getenv('DEPLOYER_ROOT') : dirname($deployFile));
Deployer\Deployer::run(DEPLOYER_VERSION, $deployFile);