1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Dandelion\Console\Command; |
6
|
|
|
|
7
|
|
|
use Dandelion\Operation\ReleaserInterface; |
8
|
|
|
use Dandelion\Operation\Result\MessageInterface; |
9
|
|
|
use InvalidArgumentException; |
10
|
|
|
use Symfony\Component\Console\Command\Command; |
11
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
12
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
13
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
14
|
|
|
|
15
|
|
|
use function is_string; |
16
|
|
|
use function sprintf; |
17
|
|
|
|
18
|
|
|
class ReleaseAllCommand extends Command |
19
|
|
|
{ |
20
|
|
|
public const NAME = 'release:all'; |
21
|
|
|
public const DESCRIPTION = 'Releases all packages.'; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var \Dandelion\Operation\ReleaserInterface |
25
|
|
|
*/ |
26
|
|
|
protected $releaser; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @param \Dandelion\Operation\ReleaserInterface $releaser |
30
|
|
|
*/ |
31
|
|
|
public function __construct( |
32
|
|
|
ReleaserInterface $releaser |
33
|
|
|
) { |
34
|
|
|
parent::__construct(); |
35
|
|
|
$this->releaser = $releaser; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @return void |
40
|
|
|
*/ |
41
|
|
|
protected function configure(): void |
42
|
|
|
{ |
43
|
|
|
parent::configure(); |
44
|
|
|
|
45
|
|
|
$this->setName(static::NAME); |
46
|
|
|
$this->setDescription(static::DESCRIPTION); |
47
|
|
|
|
48
|
|
|
$this->addArgument('branch', InputArgument::REQUIRED, 'Branch'); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param \Symfony\Component\Console\Input\InputInterface $input |
53
|
|
|
* @param \Symfony\Component\Console\Output\OutputInterface $output |
54
|
|
|
* |
55
|
|
|
* @return int |
56
|
|
|
*/ |
57
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int |
58
|
|
|
{ |
59
|
|
|
$branch = $input->getArgument('branch'); |
60
|
|
|
|
61
|
|
|
if (!is_string($branch)) { |
62
|
|
|
throw new InvalidArgumentException('Unsupported type for given argument'); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
$output->writeln('Releasing monorepo packages:'); |
66
|
|
|
$output->writeln('---------------------------------'); |
67
|
|
|
|
68
|
|
|
$result = $this->releaser->executeForAllRepositories([$branch]); |
69
|
|
|
|
70
|
|
|
foreach ($result->getMessages() as $message) { |
71
|
|
|
$symbol = $message->getType() === MessageInterface::TYPE_INFO ? '<fg=green>✔</>' : '<fg=red>✗</>'; |
72
|
|
|
$output->writeln(sprintf('%s %s', $symbol, $message->getText())); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
$output->writeln('---------------------------------'); |
76
|
|
|
$output->writeln('Finished'); |
77
|
|
|
|
78
|
|
|
return 0; |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|