From af3c1fb840b9deb25d46584d3dd2910f826104a8 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Sat, 3 Aug 2024 20:48:44 +0100 Subject: [PATCH] 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. --- .../FindBuildConfigurationFileCommand.php | 43 +++++++++++++++++++ src/Console/Command/GenerateCommand.php | 2 + 2 files changed, 45 insertions(+) create mode 100644 src/Command/FindBuildConfigurationFileCommand.php diff --git a/src/Command/FindBuildConfigurationFileCommand.php b/src/Command/FindBuildConfigurationFileCommand.php new file mode 100644 index 0000000..ab7e93f --- /dev/null +++ b/src/Command/FindBuildConfigurationFileCommand.php @@ -0,0 +1,43 @@ +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"); + } +} diff --git a/src/Console/Command/GenerateCommand.php b/src/Console/Command/GenerateCommand.php index 25482a3..5d4dc3f 100644 --- a/src/Console/Command/GenerateCommand.php +++ b/src/Console/Command/GenerateCommand.php @@ -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(),