diff --git a/src/Command/DeployCommand.php b/src/Command/DeployCommand.php index a3c6a5c..ce2fe0a 100644 --- a/src/Command/DeployCommand.php +++ b/src/Command/DeployCommand.php @@ -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') ; diff --git a/src/Configuration/DefaultConfiguration.php b/src/Configuration/DefaultConfiguration.php index 1abe5ac..95a8e24 100644 --- a/src/Configuration/DefaultConfiguration.php +++ b/src/Configuration/DefaultConfiguration.php @@ -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'; @@ -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 = null) { 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 @@ -122,7 +127,9 @@ public function repositoryUrl(string $url): self public function repositoryBranch(string $branchName): self { - $this->repositoryBranch = $branchName; + if (false === $this->passedBranchOrTag) { + $this->repositoryBranch = $branchName; + } return $this; } diff --git a/src/Deployer/AbstractDeployer.php b/src/Deployer/AbstractDeployer.php index fbc7c64..5c3dd21 100644 --- a/src/Deployer/AbstractDeployer.php +++ b/src/Deployer/AbstractDeployer.php @@ -35,6 +35,8 @@ abstract class AbstractDeployer /** @var ConfigurationAdapter */ private $config; + protected $branchOrTag; + abstract public function getRequirements(): array; abstract public function deploy(); @@ -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('