diff --git a/recipe/deploy/check_remote.php b/recipe/deploy/check_remote.php index 8364b6c6d..e0b75b950 100644 --- a/recipe/deploy/check_remote.php +++ b/recipe/deploy/check_remote.php @@ -2,6 +2,7 @@ namespace Deployer; +use Deployer\Exception\ConfigurationException; use Deployer\Exception\Exception; use Deployer\Exception\GracefulShutdownException; @@ -12,8 +13,18 @@ $repository = get('repository'); // Skip if there is no current deployment to compare - if (!test('[ -d {{current_path}}/.git ]')) { - return; + if (get('update_code_strategy') === 'archive') { + if (!test('[ -f {{current_path}}/REVISION ]')) { + return; + } + $lastDeployedRevision = run('cat {{current_path}}/REVISION'); + } elseif (get('update_code_strategy') === 'clone') { + if (!test('[ -d {{current_path}}/.git ]')) { + return; + } + $lastDeployedRevision = trim(run(sprintf('cd {{current_path}} && %s rev-parse HEAD', get('bin/git')))); + } else { + throw new ConfigurationException(parse("Unknown `update_code_strategy` option: {{update_code_strategy}}.")); } // Determine the hash of the remote revision about to be deployed @@ -41,7 +52,6 @@ // Compare commit hashes. We use strpos to support short versions. $targetRevision = trim($targetRevision); - $lastDeployedRevision = run('cat {{current_path}}/REVISION'); if ($targetRevision && strpos($lastDeployedRevision, $targetRevision) === 0) { throw new GracefulShutdownException("Already up-to-date."); } diff --git a/recipe/deploy/release.php b/recipe/deploy/release.php index 980677097..d6778b24f 100644 --- a/recipe/deploy/release.php +++ b/recipe/deploy/release.php @@ -2,6 +2,7 @@ namespace Deployer; +use Deployer\Exception\ConfigurationException; use Deployer\Exception\Exception; use Symfony\Component\Console\Helper\Table; @@ -70,7 +71,14 @@ // Current release revision. Usually a git hash. set('release_revision', function () { - return run('cat {{release_path}}/REVISION'); + if (get('update_code_strategy') === 'archive') { + return run('cat {{release_path}}/REVISION'); + } + if (get('update_code_strategy') === 'clone') { + return trim(run(sprintf('cd {{release_path}} && %s rev-parse HEAD', get('bin/git')))); + } + + throw new ConfigurationException(parse("Unknown `update_code_strategy` option: {{update_code_strategy}}.")); }); // Return the release path during a deployment @@ -183,9 +191,11 @@ if ($release === $currentRelease) { $status .= ' (current)'; } - try { + if (test("[ -f releases/$release/REVISION ]")) { $revision = run("cat releases/$release/REVISION"); - } catch (\Throwable $e) { + } elseif (test("[ -d releases/$release/.git ]")) { + $revision = trim(run(sprintf('cd releases/%s && %s rev-parse HEAD', $release, get('bin/git')))); + } else { $revision = 'unknown'; } $table[] = [ diff --git a/recipe/deploy/update_code.php b/recipe/deploy/update_code.php index 13956780a..6d36188ac 100644 --- a/recipe/deploy/update_code.php +++ b/recipe/deploy/update_code.php @@ -109,6 +109,9 @@ // Copy to release_path. if (get('update_code_strategy') === 'archive') { run("$git archive $targetWithDir | tar -x -f - -C {{release_path}} 2>&1"); + // Save git revision in REVISION file. + $rev = escapeshellarg(run("$git rev-list $target -1")); + run("echo $rev > {{release_path}}/REVISION"); } elseif (get('update_code_strategy') === 'clone') { cd('{{release_path}}'); run("$git clone -l $bare ."); @@ -117,8 +120,4 @@ } else { throw new ConfigurationException(parse("Unknown `update_code_strategy` option: {{update_code_strategy}}.")); } - - // Save git revision in REVISION file. - $rev = escapeshellarg(run("$git rev-list $target -1")); - run("echo $rev > {{release_path}}/REVISION"); });