Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions src/Command/DeployCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ protected function configure()
->setDescription('Deploys a Symfony application to one or more remote servers.')
->setHelp('...')
->addArgument('stage', InputArgument::OPTIONAL, 'The stage to deploy to ("production", "staging", etc.)', 'prod')
->addArgument('branch-or-tag', InputArgument::OPTIONAL, 'Branch or tag you would like checked out')
->addOption('configuration', 'c', InputOption::VALUE_REQUIRED, 'Load configuration from the given file path')
->addOption('dry-run', null, InputOption::VALUE_NONE, 'Shows the commands to perform the deployment without actually executing them')
;
Expand Down
11 changes: 9 additions & 2 deletions src/Configuration/DefaultConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ final class DefaultConfiguration extends AbstractConfiguration
private $keepReleases = 5;
private $repositoryUrl;
private $repositoryBranch = 'master';
private $passedBranchOrTag = false;
private $remotePhpBinaryPath = 'php';
private $updateRemoteComposerBinary = false;
private $remoteComposerBinaryPath = '/usr/local/bin/composer';
Expand Down Expand Up @@ -61,11 +62,15 @@ final class DefaultConfiguration extends AbstractConfiguration
private $sharedDirs = [];
private $resetOpCacheFor;

public function __construct(string $localProjectDir)
public function __construct(string $localProjectDir, ?string $branchOrTag)
{
parent::__construct();
$this->localProjectDir = $localProjectDir;
$this->setDefaultConfiguration(Kernel::MAJOR_VERSION, Kernel::MINOR_VERSION);
if (!empty($branchOrTag)) {
$this->repositoryBranch = $branchOrTag;
$this->passedBranchOrTag = true;
}
}

// this proxy method is needed because the autocompletion breaks
Expand Down Expand Up @@ -122,7 +127,9 @@ public function repositoryUrl(string $url): self

public function repositoryBranch(string $branchName): self
{
$this->repositoryBranch = $branchName;
if ($this->passedBranchOrTag === false) {
$this->repositoryBranch = $branchName;
}

return $this;
}
Expand Down
10 changes: 10 additions & 0 deletions src/Deployer/AbstractDeployer.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ abstract class AbstractDeployer
/** @var ConfigurationAdapter */
private $config;

protected $branchOrTag;

abstract public function getRequirements(): array;

abstract public function deploy();
Expand Down Expand Up @@ -132,6 +134,7 @@ public function beforeFinishingRollback()
public function initialize(Context $context): void
{
$this->context = $context;
$this->branchOrTag = $context->getInput()->getArgument('branch-or-tag');
$this->logger = new Logger($context);
$this->taskRunner = new TaskRunner($this->context->isDryRun(), $this->logger);
$this->log('<h1>Initializing configuration</>');
Expand All @@ -141,6 +144,7 @@ public function initialize(Context $context): void
$this->log($this->config);
$this->log('<h2>Checking technical requirements</>');
$this->checkRequirements();

}

abstract protected function getConfigBuilder();
Expand Down Expand Up @@ -169,6 +173,11 @@ final protected function runLocal(string $command): TaskCompleted
return $this->taskRunner->run($task)[0];
}

final protected function getBranchOrTag(): ?string
{
return $this->branchOrTag;
}

/**
* @return TaskCompleted[]
*/
Expand Down Expand Up @@ -231,4 +240,5 @@ private function checkRequirements(): void
$this->log($requirement->getMessage());
}
}

}
7 changes: 6 additions & 1 deletion src/Deployer/DefaultDeployer.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ abstract class DefaultDeployer extends AbstractDeployer

public function getConfigBuilder(): DefaultConfiguration
{
return new DefaultConfiguration($this->getContext()->getLocalProjectRootDir());
return new DefaultConfiguration($this->getContext()->getLocalProjectRootDir(), $this->getBranchOrTag());
}

public function getRequirements(): array
Expand Down Expand Up @@ -245,6 +245,11 @@ private function doGetcodeRevision(): string
$this->log('<h2>Getting the revision ID of the code repository</>');
$result = $this->runLocal(sprintf('git ls-remote %s %s', $this->getConfig(Option::repositoryUrl), $this->getConfig(Option::repositoryBranch)));
$revision = explode("\t", $result->getTrimmedOutput())[0];

if (empty($revision)) {
throw new InvalidConfigurationException(sprintf("No revisions found for %s", $this->getConfig(Option::repositoryBranch)));
}

if ($this->getContext()->isDryRun()) {
$revision = '(the code revision)';
}
Expand Down