deployer/recipe/deploy/update_code.php
Bernhard Zürn 26c3400d53 Added Exception Handling for perhaps missing config param (#1677)
* modify wrong ticket url (#1605)

* moving the name column to the last position to show full name

- bug fix: #1579

* add changelog

* update changelog.md

* update CHANGELOG.md

* modify command to find http user

* modify command to find http user

* modify wrong ticket url

* Remove magento:enable from Magento 2 recipe (#1606)

* Remove magento:enable from Magento 2 recipe

Magento's module states are stored in app/etc/config.php. This task
ignored that and blindly enabled all installed modules.

* Mention the removal of magento:enable in the changelog

* Extend deploy:cleanup with tty allocation when using sudo. (#1607)

* Added option cleanup_tty to allow allocation when using sudo

* Added comment for new option cleanup_tty to CHANGELOG

* Allow to set template path in Drupal 7 Settings recipe (#1613)

* Change drupal:settings task to drupal:configure

* Drupal 7 recipe - Set template file path

* Changelog

* Fixed once() tasks that where being run multiple times with ParallelE… (#1624)

* Fixed once() tasks that where being run multiple times with ParallelExecutor

* CHANGELOG: reorder issue

* Add test case for parallel deploy on ->once() task

* Added cleanup_use_sudo option to all commands in deploy:cleanup (#1632)

* Added option cleanup_tty to allow allocation when using sudo

* Added comment for new option cleanup_tty to CHANGELOG

* Added cleanup_use_sudo option to all commands in cleanup.php

* Fix return types for fluent interface (#1638)

* Add Prestashop 1.6 recipe (#1641)

* Add Prestashop 1.6 recipe

* Update changelog

* Sleep between process status calls to prevent 100% CPU usage (#1654)

* Sleep between progress status calls to prevent 100% CPU usage

* Add changelog entry

* Typo in changelog entry

* Update ParallelExecutor.php

* Update ParallelExecutor.php

* locate binary with less subprocesses (#1634)

* Set custom user for CI environments (#1659)

* Detect CI user

* Update CHANGELOG.md

* Update README.md

* [deploy:writable] chgrp doesn't need http_user (#1660)

* deploy:writable: chgrp doesn't need http_user

* Update CHANGELOG.md

* Add missing deploy:writable entries (#1662)

* Fix missing deploy:shared entries (#1664)

* Added Exception Handling for perhaps missing config param

Sometimes deploy_path is not set and a cd into this folder is not possible. But the deployment can be successful without it.

* style

* #1677 fixes according pull-request feedback

* #1677 code style fixes

* Added Exception Handling for perhaps missing config param

Sometimes deploy_path is not set and a cd into this folder is not possible. But the deployment can be successful without it.

* style

* #1677 fixes according pull-request feedback

* #1677 code style fixes

* Changelog entry for #1677

* Changelog entry for #1677

* Changelog entry for #1677
2018-09-05 19:03:04 +07:00

101 lines
2.9 KiB
PHP

<?php
/* (c) Anton Medvedev <anton@medv.io>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Deployer;
/**
* Get current git HEAD branch as default branch to deploy.
*/
set('branch', function () {
try {
$branch = runLocally('git rev-parse --abbrev-ref HEAD');
} catch (\Throwable $exception) {
$branch = null;
}
if ($branch === 'HEAD') {
$branch = null; // Travis-CI fix
}
if (input()->hasOption('branch') && !empty(input()->getOption('branch'))) {
$branch = input()->getOption('branch');
}
return $branch;
});
/**
* Whether to use git cache.
*
* Faster cloning by borrowing objects from existing clones.
*/
set('git_cache', function () {
$gitVersion = run('{{bin/git}} version');
$regs = [];
if (preg_match('/((\d+\.?)+)/', $gitVersion, $regs)) {
$version = $regs[1];
} else {
$version = "1.0.0";
}
return version_compare($version, '2.3', '>=');
});
desc('Update code');
task('deploy:update_code', function () {
$repository = trim(get('repository'));
$branch = get('branch');
$git = get('bin/git');
$gitCache = get('git_cache');
$recursive = get('git_recursive', true) ? '--recursive' : '';
$depth = $gitCache ? '' : '--depth 1';
$options = [
'tty' => get('git_tty', false),
];
$at = '';
if (!empty($branch)) {
$at = "-b $branch";
}
// If option `tag` is set
if (input()->hasOption('tag')) {
$tag = input()->getOption('tag');
if (!empty($tag)) {
$at = "-b $tag";
}
}
// If option `tag` is not set and option `revision` is set
if (empty($tag) && input()->hasOption('revision')) {
$revision = input()->getOption('revision');
if (!empty($revision)) {
$depth = '';
}
}
// Enter deploy_path if present
if (has('deploy_path')) {
cd('{{deploy_path}}');
}
if ($gitCache && has('previous_release')) {
try {
run("$git clone $at $recursive -q --reference {{previous_release}} --dissociate $repository {{release_path}} 2>&1", $options);
} catch (\Throwable $exception) {
// If {{deploy_path}}/releases/{$releases[1]} has a failed git clone, is empty, shallow etc, git would throw error and give up. So we're forcing it to act without reference in this situation
run("$git clone $at $recursive -q $repository {{release_path}} 2>&1", $options);
}
} else {
// if we're using git cache this would be identical to above code in catch - full clone. If not, it would create shallow clone.
run("$git clone $at $depth $recursive -q $repository {{release_path}} 2>&1", $options);
}
if (!empty($revision)) {
run("cd {{release_path}} && $git checkout $revision");
}
});