mirror of
https://github.com/deployphp/deployer.git
synced 2025-02-23 08:45:04 +01:00
Add deploy:check_remote task
This commit is contained in:
parent
d1a6e201ef
commit
85aae9fd68
@ -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
|
||||
|
@ -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.
|
||||
|
||||
|
34
recipe/deploy/check_remote.php
Normal file
34
recipe/deploy/check_remote.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?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;
|
||||
|
||||
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");
|
||||
});
|
@ -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');
|
||||
});
|
||||
|
@ -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');
|
||||
|
Loading…
x
Reference in New Issue
Block a user