Skip to content

Commit 658dfdb

Browse files
committed
feat: Allow run-task command to configure server / build stage
1 parent 7c74c30 commit 658dfdb

File tree

5 files changed

+35
-20
lines changed

5 files changed

+35
-20
lines changed

src/Command/Build.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ protected function configure()
3333
*/
3434
protected function execute(InputInterface $input, OutputInterface $output)
3535
{
36-
return $this->deployRunner->run($output, 'build', DeployRunner::TASK_BUILD);
36+
return $this->deployRunner->run($output, 'build', DeployRunner::TASK_BUILD, true, false);
3737
}
3838
}

src/Command/ComposerAuth.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ protected function configure()
3434
*/
3535
protected function execute(InputInterface $input, OutputInterface $output)
3636
{
37-
return $this->deployRunner->run($output, 'build', 'deploy:vendors:auth');
37+
return $this->deployRunner->run($output, 'build', 'deploy:vendors:auth', false, false);
3838
}
3939
}

src/Command/Deploy.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ protected function configure()
3838
*/
3939
protected function execute(InputInterface $input, OutputInterface $output)
4040
{
41-
$result = $this->deployRunner->run($output, $input->getArgument('stage'), DeployRunner::TASK_DEPLOY);
41+
$result = $this->deployRunner->run($output, $input->getArgument('stage'), DeployRunner::TASK_DEPLOY, false, true);
4242

4343
if ($result === 0) {
4444
$this->reportWriter->write($this->deployRunner->getDeploymentReport());

src/Command/RunTask.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,17 @@
66
use Symfony\Component\Console\Command\Command;
77
use Symfony\Component\Console\Input\InputArgument;
88
use Symfony\Component\Console\Input\InputInterface;
9+
use Symfony\Component\Console\Input\InputOption;
910
use Symfony\Component\Console\Output\OutputInterface;
1011
use Throwable;
1112

1213
class RunTask extends Command
1314
{
15+
private const ARGUMENT_STAGE = 'stage';
16+
private const ARGUMENT_TASK = 'task';
17+
private const OPTION_CONFIGURE_BUILD_STAGE = 'configure-build-stage';
18+
private const OPTION_CONFIGURE_SERVERS = 'configure-servers';
19+
1420
/**
1521
* @var DeployRunner
1622
*/
@@ -27,15 +33,23 @@ protected function configure()
2733
parent::configure();
2834
$this->setName('run-task');
2935
$this->setDescription('Run a seperate deployer task');
30-
$this->addArgument('stage', InputArgument::REQUIRED, 'Stage');
31-
$this->addArgument('task', InputArgument::REQUIRED, 'Task to run');
36+
$this->addArgument(self::ARGUMENT_STAGE, InputArgument::REQUIRED, 'Stage');
37+
$this->addArgument(self::ARGUMENT_TASK, InputArgument::REQUIRED, 'Task to run');
38+
$this->addOption(self::OPTION_CONFIGURE_BUILD_STAGE, 'b', InputOption::VALUE_NONE, 'Configure build stage before running task');
39+
$this->addOption(self::OPTION_CONFIGURE_SERVERS, 's', InputOption::VALUE_NONE, 'Configure servers before running task');
3240
}
3341

3442
/**
3543
* @throws Throwable
3644
*/
3745
protected function execute(InputInterface $input, OutputInterface $output)
3846
{
39-
return $this->deployRunner->run($output, $input->getArgument('stage'), $input->getArgument('task'));
47+
return $this->deployRunner->run(
48+
$output,
49+
$input->getArgument(self::ARGUMENT_STAGE),
50+
$input->getArgument(self::ARGUMENT_TASK),
51+
$input->getOption(self::OPTION_CONFIGURE_BUILD_STAGE),
52+
$input->getOption(self::OPTION_CONFIGURE_SERVERS),
53+
);
4054
}
4155
}

src/DeployRunner.php

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function __construct(
7373
* @throws Throwable
7474
* @throws Exception
7575
*/
76-
public function run(OutputInterface $output, string $stage, string $task = self::TASK_DEPLOY): int
76+
public function run(OutputInterface $output, string $stage, string $task, bool $configureBuildStage, bool $configureServers): int
7777
{
7878
$console = new Application();
7979
$deployer = new Deployer($console);
@@ -87,7 +87,7 @@ public function run(OutputInterface $output, string $stage, string $task = self:
8787
);
8888

8989
try {
90-
$this->initializeDeployer($deployer, $task);
90+
$this->initializeDeployer($deployer, $configureBuildStage, $configureServers);
9191
} catch (InvalidConfigurationException $e) {
9292
$output->write($e->getMessage());
9393
return 1;
@@ -104,13 +104,20 @@ public function run(OutputInterface $output, string $stage, string $task = self:
104104
* @throws Throwable
105105
* @throws InvalidConfigurationException
106106
*/
107-
private function initializeDeployer(Deployer $deployer, string $task): void
107+
private function initializeDeployer(Deployer $deployer, bool $configureBuildStage, bool $configureServers): void
108108
{
109109
$this->recipeLoader->load('common.php');
110110
$tasks = $this->taskFactory->loadAll();
111111
$config = $this->getConfiguration($deployer);
112112
$config->setLogger($this->log);
113-
$this->configureStages($config, $task);
113+
114+
if ($configureBuildStage) {
115+
$this->initializeBuildStage($config);
116+
}
117+
118+
if ($configureServers) {
119+
$this->configureServers($config);
120+
}
114121

115122
foreach ($tasks as $task) {
116123
$task->configure($config);
@@ -180,17 +187,11 @@ private function getConfiguration(Deployer $deployer): Configuration
180187
}
181188
}
182189

183-
private function configureStages(Configuration $config, string $task): void
190+
private function configureServers(Configuration $config): void
184191
{
185-
if ($task === self::TASK_BUILD) {
186-
$this->initializeBuildStage($config);
187-
}
188-
189-
if ($task === self::TASK_DEPLOY) {
190-
foreach ($config->getStages() as $stage) {
191-
foreach ($stage->getServers() as $server) {
192-
$this->configureStageServer($stage, $server, $config);
193-
}
192+
foreach ($config->getStages() as $stage) {
193+
foreach ($stage->getServers() as $server) {
194+
$this->configureStageServer($stage, $server, $config);
194195
}
195196
}
196197
}

0 commit comments

Comments
 (0)