|
1 | 1 | #!/usr/bin/env php |
2 | 2 | <?php |
3 | 3 |
|
4 | | -use Symfony\Component\Console\Input\ArrayInput; |
5 | | -use Symfony\Component\Console\Output\ConsoleOutput; |
| 4 | +use Symfony\Component\Console\Input\InputInterface; |
| 5 | +use Symfony\Component\Console\Output\OutputInterface; |
| 6 | +use Symfony\Component\Console\SingleCommandApplication; |
6 | 7 | use Symfony\Component\Console\Style\SymfonyStyle; |
7 | 8 | use Symfony\Component\Process\Process; |
8 | 9 | use Symfony\Component\Yaml\Yaml; |
9 | 10 |
|
10 | 11 | require_once __DIR__ . '/../../vendor/autoload.php'; |
11 | 12 |
|
12 | | -$action = Yaml::parseFile(__DIR__ . '/../../.github/actions/install/action.yml'); |
13 | | -$composer = \array_filter(\explode(\PHP_EOL, $action['runs']['steps'][1]['run'])); |
| 13 | +(new SingleCommandApplication()) |
| 14 | + ->setCode(function (InputInterface $input, OutputInterface $output) { |
| 15 | + $return = 0; |
14 | 16 |
|
15 | | -$io = new SymfonyStyle(new ArrayInput([]), new ConsoleOutput()); |
| 17 | + $action = Yaml::parseFile(__DIR__ . '/../../.github/actions/install/action.yml'); |
| 18 | + $composer = \array_filter(\explode(\PHP_EOL, $action['runs']['steps'][1]['run'])); |
16 | 19 |
|
17 | | -$execute = function (array $job, string|null $php = null, string|null $symfony = null) use ($io, $composer) { |
18 | | - $io->section($job['name']); |
| 20 | + $io = new SymfonyStyle($input, $output); |
19 | 21 |
|
20 | | - if ($php === null && $symfony === null) { |
21 | | - ['php-version' => $php, 'symfony-version' => $symfony] = $job['steps'][1]['with']; |
22 | | - } else { |
23 | | - $io->definitionList( |
24 | | - ['PHP' => $php], |
25 | | - ['Symfony' => $symfony], |
26 | | - ); |
27 | | - } |
| 22 | + $execute = function (array $job, string|null $php = null, string|null $symfony = null) use ($io, $composer) { |
| 23 | + $io->section($job['name']); |
28 | 24 |
|
29 | | - $process = function (string $command, bool $output) use ($io, $php) { |
30 | | - $container = 'php' . \str_replace('.', '', $php); |
31 | | - $command = "led in -s {$container} -- {$command}"; |
| 25 | + if ($php === null && $symfony === null) { |
| 26 | + ['php-version' => $php, 'symfony-version' => $symfony] = $job['steps'][1]['with']; |
| 27 | + } else { |
| 28 | + $io->definitionList( |
| 29 | + ['PHP' => $php], |
| 30 | + ['Symfony' => $symfony], |
| 31 | + ); |
| 32 | + } |
32 | 33 |
|
33 | | - $callback = null; |
34 | | - if ($output) { |
35 | | - $io->writeln($command); |
36 | | - $callback = function ($type, $buffer) { |
37 | | - echo $buffer; |
| 34 | + $process = function (string $command, bool $output) use ($io, $php) { |
| 35 | + $container = 'php' . \str_replace('.', '', $php); |
| 36 | + $command = "led in -s {$container} -- {$command}"; |
| 37 | + |
| 38 | + $callback = null; |
| 39 | + if ($output) { |
| 40 | + $io->writeln($command); |
| 41 | + $callback = function ($type, $buffer) { |
| 42 | + echo $buffer; |
| 43 | + }; |
| 44 | + } |
| 45 | + |
| 46 | + Process::fromShellCommandline($command)->mustRun($callback); |
38 | 47 | }; |
| 48 | + |
| 49 | + foreach ($composer as $command) { |
| 50 | + $process(\str_replace('${{ inputs.symfony-version }}', $symfony, $command), false); |
| 51 | + } |
| 52 | + $process($job['steps'][2]['run'], true); |
| 53 | + }; |
| 54 | + |
| 55 | + $tests = Yaml::parseFile(__DIR__ . '/../../.github/workflows/tests.yml'); |
| 56 | + |
| 57 | + try { |
| 58 | + $execute($tests['jobs']['checkstyke']); |
| 59 | + $execute($tests['jobs']['phpstan']); |
| 60 | + $execute($tests['jobs']['conventions']); |
| 61 | + |
| 62 | + $phpunitTestingMatrix = $tests['jobs']['phpunit']['strategy']['matrix']['include']; |
| 63 | + foreach ($phpunitTestingMatrix as ['php-version' => $php, 'symfony-version' => $symfony]) { |
| 64 | + $execute($tests['jobs']['phpunit'], $php, $symfony); |
| 65 | + } |
| 66 | + } catch (\Throwable) { |
| 67 | + $return = 1; |
| 68 | + $io->error('An error occurred, abort tests.'); |
39 | 69 | } |
40 | 70 |
|
41 | | - Process::fromShellCommandline($command)->mustRun($callback); |
42 | | - }; |
43 | | - |
44 | | - foreach ($composer as $command) { |
45 | | - $process(\str_replace('${{ inputs.symfony-version }}', $symfony, $command), false); |
46 | | - } |
47 | | - $process($job['steps'][2]['run'], true); |
48 | | -}; |
49 | | - |
50 | | -$tests = Yaml::parseFile(__DIR__ . '/../../.github/workflows/tests.yml'); |
51 | | - |
52 | | -try { |
53 | | - $execute($tests['jobs']['checkstyke']); |
54 | | - $execute($tests['jobs']['phpstan']); |
55 | | - $execute($tests['jobs']['conventions']); |
56 | | - |
57 | | - $phpunitTestingMatrix = $tests['jobs']['phpunit']['strategy']['matrix']['include']; |
58 | | - foreach ($phpunitTestingMatrix as ['php-version' => $php, 'symfony-version' => $symfony]) { |
59 | | - $execute($tests['jobs']['phpunit'], $php, $symfony); |
60 | | - } |
61 | | -} catch (\Throwable) { |
62 | | - $io->error('An error occurred, abort tests.'); |
63 | | -} |
64 | | - |
65 | | -$io->success('Revert changes made to composer.json'); |
66 | | -Process::fromShellCommandline('git restore composer.json')->mustRun(); |
67 | | -Process::fromShellCommandline('led in -- composer update')->mustRun(); |
| 71 | + $io->success('Revert changes made to composer.json'); |
| 72 | + Process::fromShellCommandline('git restore composer.json')->mustRun(); |
| 73 | + Process::fromShellCommandline('led in -- composer update')->mustRun(); |
| 74 | + |
| 75 | + return $return; |
| 76 | + }) |
| 77 | + ->run(); |
0 commit comments