diff --git a/CHANGELOG.md b/CHANGELOG.md index 5cad1b47..ec8022a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,13 @@ # Changelog +## master +[v6.4.7...master](https://github.com/deployphp/deployer/compare/v6.4.7...master) + +### Added +- Added `deploy:check_remote` task [#1755] + + ## v6.4.7 [v6.4.6...v6.4.7](https://github.com/deployphp/deployer/compare/v6.4.6...v6.4.7) @@ -515,7 +522,7 @@ [#1775]: https://github.com/deployphp/deployer/pull/1775 [#1764]: https://github.com/deployphp/deployer/pull/1764 [#1758]: https://github.com/deployphp/deployer/pull/1758 -[#1755]: https://github.com/deployphp/deployer/pull/1755 +[#1755]: https://github.com/deployphp/deployer/issues/1755 [#1709]: https://github.com/deployphp/deployer/issues/1709 [#1708]: https://github.com/deployphp/deployer/pull/1708 [#1677]: https://github.com/deployphp/deployer/pull/1677 diff --git a/recipe/common.php b/recipe/common.php index eb66ecba..df7725fe 100644 --- a/recipe/common.php +++ b/recipe/common.php @@ -56,8 +56,6 @@ set('target', function () { */ set('keep_releases', 5); -// By setting this to true, deployer will avoid unnecessary new release by checking the remote git HEAD without cloning the repo. -set('check_remote_head', false); set('repository', ''); // Repository to deploy. diff --git a/recipe/deploy/check_remote.php b/recipe/deploy/check_remote.php new file mode 100644 index 00000000..4ee93a02 --- /dev/null +++ b/recipe/deploy/check_remote.php @@ -0,0 +1,34 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Deployer; + +use Deployer\Exception\GracefulShutdownException; + +// Check and save the remote HEAD/revision and compare it with the existing saved one (if any). +// This avoid unnecessary releases when the last commit id matches the existing one (HEAD). +desc('Check remote head'); +task('deploy:check_remote', function () { + if (empty(get('repository'))) { + return; + } + + $repository = get('repository'); + $revision = input()->getOption('revision') ?? null; + $remoteHead = $revision ?? run(sprintf('%s ls-remote %s HEAD | tr -d "HEAD"', get('bin/git'), $repository)); + + if (null == input()->getOption('tag')) { + $headPath = get('deploy_path') . '/.dep/HEAD'; + $headContents = run(sprintf('test -e %s && cat %1$s', $headPath)); + // Check if HEAD file is exists and then compare it. + if (trim($headContents) === trim($remoteHead)) { + throw new GracefulShutdownException("Already up-to-date."); + } + } + + run("cd {{deploy_path}} && echo $remoteHead > .dep/HEAD"); +}); diff --git a/recipe/deploy/prepare.php b/recipe/deploy/prepare.php index 7ddcc47b..836467b3 100644 --- a/recipe/deploy/prepare.php +++ b/recipe/deploy/prepare.php @@ -7,7 +7,7 @@ namespace Deployer; -use Deployer\Exception\GracefulShutdownException; +use Deployer\Exception\Exception; use function Deployer\Support\str_contains; desc('Preparing host for deploy'); @@ -26,7 +26,7 @@ task('deploy:prepare', function () { // Check for existing /current directory (not symlink) $result = test('[ ! -L {{deploy_path}}/current ] && [ -d {{deploy_path}}/current ]'); if ($result) { - throw new \RuntimeException('There already is a directory (not symlink) named "current" in ' . get('deploy_path') . '. Remove this directory so it can be replaced with a symlink for atomic deployments.'); + throw new Exception('There already is a directory (not symlink) named "current" in ' . get('deploy_path') . '. Remove this directory so it can be replaced with a symlink for atomic deployments.'); } // Create metadata .dep dir. @@ -37,20 +37,4 @@ task('deploy:prepare', function () { // Create shared dir. run("cd {{deploy_path}} && if [ ! -d shared ]; then mkdir shared; fi"); - - // Check and save the remote HEAD/revision and compare it with the existing saved one (if any) - // This avoid unnecessary releases when the last commit id matches the existing one (HEAD) - $repository = trim(get('repository')); - $revision = input()->getOption('revision') ?? null; - $remoteHead = $revision ?? run(sprintf('%s ls-remote %s HEAD | tr -d "HEAD"', get('bin/git'), $repository)); - - if (true === get('check_remote_head') && null == input()->getOption('tag')) { - $headPath = trim(get('deploy_path').'/.dep/HEAD'); - $headContents = run(sprintf('test -e %s && cat %1$s', $headPath)); - //check if HEAD file is exists and then compare it - if (trim($headContents) === trim($remoteHead)) { - throw new GracefulShutdownException("Already up-to-date."); - } - } - run("cd {{deploy_path}} && echo ".$remoteHead.' > .dep/HEAD'); }); diff --git a/recipe/deploy/update_code.php b/recipe/deploy/update_code.php index 3946a3ed..765be3ad 100644 --- a/recipe/deploy/update_code.php +++ b/recipe/deploy/update_code.php @@ -46,7 +46,7 @@ set('git_cache', function () { desc('Update code'); task('deploy:update_code', function () { - $repository = trim(get('repository')); + $repository = get('repository'); $branch = get('branch'); $git = get('bin/git'); $gitCache = get('git_cache');