Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions recipe/deploy/check_remote.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Deployer;

use Deployer\Exception\ConfigurationException;
use Deployer\Exception\Exception;
use Deployer\Exception\GracefulShutdownException;

Expand All @@ -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
Expand Down Expand Up @@ -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.");
}
Expand Down
16 changes: 13 additions & 3 deletions recipe/deploy/release.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Deployer;

use Deployer\Exception\ConfigurationException;
use Deployer\Exception\Exception;
use Symfony\Component\Console\Helper\Table;

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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[] = [
Expand Down
7 changes: 3 additions & 4 deletions recipe/deploy/update_code.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 .");
Expand All @@ -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");
});