generated from ghostwriter/wip
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MatrixCommand.php
43 lines (36 loc) · 1.33 KB
/
MatrixCommand.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
declare(strict_types=1);
namespace Ghostwriter\Compliance\Command;
use Ghostwriter\Compliance\Event\GenerateMatrixEvent;
use Ghostwriter\Compliance\Event\OutputEvent;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Throwable;
use function sprintf;
final class MatrixCommand extends AbstractCommand
{
protected function configure(): void
{
$this->setDescription('Generates a job matrix for Github Actions.');
$this->addArgument('job', InputArgument::OPTIONAL, 'JSON string representing the job to run.');
}
/**
* Execute the command.
*
* @throws Throwable
*
* @return int 0 if everything went fine, or an exit code
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
/** @var GenerateMatrixEvent $generateMatrixEvent */
$generateMatrixEvent = $this->dispatcher->dispatch(
new GenerateMatrixEvent($this->dispatcher, $input, $this->symfonyStyle)
);
$this->dispatcher->dispatch(
new OutputEvent(sprintf('::set-output name=matrix::%s', $generateMatrixEvent->getMatrix()))
);
return $generateMatrixEvent->isPropagationStopped() ? self::FAILURE : self::SUCCESS;
}
}