Automatically find the build configuration file

Automatically find and use a `build-configs.yaml` or `build.yaml` if it
exists.

The `--config-file` option is still available if a custom filename needs
to be used, and it's currently used when running snapshot tests.
This commit is contained in:
Oliver Davies 2024-08-03 20:48:44 +01:00
parent 2ca755ee28
commit af3c1fb840
2 changed files with 45 additions and 0 deletions

View file

@ -0,0 +1,43 @@
<?php
declare(strict_types=1);
namespace App\Command;
use Symfony\Component\Filesystem\Filesystem;
final class FindBuildConfigurationFileCommand
{
/**
* Supported build configuration file names.
*/
private static $configFiles = [
'build-configs.yaml',
'build.yaml',
];
public function __construct(private Filesystem $filesystem)
{
}
public function execute(string|null $configFile = null, \Closure $next)
{
if ($configFile !== null) {
if (!$this->filesystem->exists($configFile)) {
throw new \RuntimeException(sprintf('%s not found', $configFile));
}
return $next($configFile);
}
// Search for a configuration file in the order of the filenames within
// the array and continue if one exists.
foreach (self::$configFiles as $i) {
if ($this->filesystem->exists($i)) {
return $next($i);
}
}
throw new \RuntimeException("No configuration file found");
}
}

View file

@ -6,6 +6,7 @@ namespace App\Console\Command;
use App\Command\CreateFinalConfigurationDataCommand;
use App\Command\CreateListOfFilesToGenerateCommand;
use App\Command\FindBuildConfigurationFileCommand;
use App\Command\GenerateConfigurationFilesCommand;
use App\Command\ValidateConfigurationDataCommand;
use App\DataTransferObject\ConfigDto;
@ -67,6 +68,7 @@ class GenerateCommand extends Command
$isDryRun = $input->getOption(name: 'dry-run');
$pipelines = [
new FindBuildConfigurationFileCommand($this->filesystem),
new CreateFinalConfigurationDataCommand(),
new ValidateConfigurationDataCommand(),
new CreateListOfFilesToGenerateCommand(),