deployer/recipe/deploy/check_remote.php
Jono Menz b7a728b7b3
Fixes for check_remote task and SS recipe (#1991)
* Fix check_remote task

* Check remote head contents locally
* Ensure .dep/HEAD file is available so error isn’t thrown
* Document task usage

Fixes #1990

* Fix Silverstripe recipe

* Additionally check shared directory for assets since this directory is commonly excluded from project git repos
* Ensure shared_assets returns a non-null value so the release folder can’t get accidentally deleted

Fixes #1989

* Update CHANGELOG.md

* Clarified contribution instructions

* Update issue templates

Added a bug report template
2020-01-29 11:13:11 +03:00

36 lines
1.2 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;
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 () {
$repository = get('repository');
if (empty($repository)) {
return;
}
$revision = input()->getOption('revision') ?? null;
$remoteHead = $revision ?? runLocally(sprintf('%s ls-remote %s HEAD | tr -d "HEAD"', get('bin/git'), $repository));
if (null == input()->getOption('tag')) {
// Init HEAD file if it doesn't exist, then compare
$headPath = get('deploy_path') . '/.dep/HEAD';
run("touch $headPath");
$headContents = run("cat $headPath");
if (trim($headContents) === trim($remoteHead)) {
throw new GracefulShutdownException("Already up-to-date.");
}
}
run("cd {{deploy_path}} && echo $remoteHead > .dep/HEAD");
});