From fafff6eccb1af61779bb75236eda60864b9d64a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20H=C3=A4u=C3=9Fler?= Date: Tue, 2 Apr 2024 19:44:26 +0200 Subject: [PATCH] [TASK] Run tests on Windows and macOS as well --- .github/workflows/tests.yaml | 19 ++++++++++++++++--- src/Builder/BuildInstructions.php | 5 ++--- src/Builder/Config/ConfigFactory.php | 7 +++---- src/Builder/Config/ConfigReader.php | 2 +- .../Step/InstallComposerDependenciesStep.php | 4 ++-- .../Step/ProcessSharedSourceFilesStep.php | 3 ++- src/Console/Application.php | 5 +++-- src/Console/Simulation.php | 4 ++-- src/DependencyInjection/ContainerFactory.php | 12 ++++++------ src/Helper/FilesystemHelper.php | 15 ++++++++++++--- src/Paths.php | 5 +++++ src/Resource/Local/Composer.php | 2 +- src/Template/Provider/BaseProvider.php | 4 ++-- .../Step/GenerateBuildArtifactStepTest.php | 2 +- 14 files changed, 58 insertions(+), 31 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 12497dc4..c25b8626 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -9,14 +9,26 @@ on: jobs: tests: - name: Tests (PHP ${{ matrix.php-version }}, Composer ${{ matrix.composer-version }} & ${{ matrix.dependencies }} dependencies) - runs-on: ubuntu-latest + name: Tests (PHP ${{ matrix.php-version }}, Composer ${{ matrix.composer-version }} & ${{ matrix.dependencies }} dependencies on ${{ matrix.os }}) + runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: php-version: ["8.1", "8.2", "8.3"] composer-version: ["2.1", "2.2", "2.3", "2.4", "2.5", "2.6", "2.7"] dependencies: ["highest", "lowest"] + os: ["ubuntu-latest"] + include: + # Windows tests + - php-version: "8.3" + composer-version: "2.7" + dependencies: "highest" + os: "windows-latest" + # macOS tests + - php-version: "8.3" + composer-version: "2.7" + dependencies: "highest" + os: "macos-latest" steps: - uses: actions/checkout@v4 with: @@ -28,6 +40,7 @@ jobs: with: php-version: ${{ matrix.php-version }} tools: composer:v${{ matrix.composer-version }} + extensions: sockets coverage: none # Install dependencies @@ -36,7 +49,7 @@ jobs: with: dependency-versions: ${{ matrix.dependencies }} # Composer < 2.7 is not compatible with symfony/console 7.x - composer-options: ${{ matrix.composer-version != '2.7' && '--with symfony/console:<7' }} + composer-options: ${{ matrix.composer-version != '2.7' && '--with symfony/console:<7' || '' }} # Run tests - name: Run tests diff --git a/src/Builder/BuildInstructions.php b/src/Builder/BuildInstructions.php index 0bb85e88..108c665a 100644 --- a/src/Builder/BuildInstructions.php +++ b/src/Builder/BuildInstructions.php @@ -26,7 +26,6 @@ use ArrayObject; use CPSIT\ProjectBuilder\Helper; use CPSIT\ProjectBuilder\Paths; -use Symfony\Component\Filesystem; use function dirname; @@ -62,12 +61,12 @@ public function getTemplateDirectory(): string public function getSourceDirectory(): string { - return Filesystem\Path::join($this->getTemplateDirectory(), Paths::TEMPLATE_SOURCES); + return Helper\FilesystemHelper::path($this->getTemplateDirectory(), Paths::TEMPLATE_SOURCES); } public function getSharedSourceDirectory(): string { - return Filesystem\Path::join($this->getTemplateDirectory(), Paths::TEMPLATE_SHARED_SOURCES); + return Helper\FilesystemHelper::path($this->getTemplateDirectory(), Paths::TEMPLATE_SHARED_SOURCES); } public function getTemporaryDirectory(): string diff --git a/src/Builder/Config/ConfigFactory.php b/src/Builder/Config/ConfigFactory.php index 93883dad..be8233c9 100644 --- a/src/Builder/Config/ConfigFactory.php +++ b/src/Builder/Config/ConfigFactory.php @@ -99,8 +99,7 @@ public function buildFromString(string $content, string $identifier, FileType $f private function validateConfig(stdClass $parsedContent): JsonSchema\ValidationResult { - $schemaFile = Filesystem\Path::join(Helper\FilesystemHelper::getProjectRootPath(), Paths::PROJECT_SCHEMA_CONFIG); - $schemaReference = 'file://'.$schemaFile; + $schemaFile = Helper\FilesystemHelper::path(Helper\FilesystemHelper::getProjectRootPath(), Paths::PROJECT_SCHEMA_CONFIG); $schemaResolver = $this->validator->resolver(); // @codeCoverageIgnoreStart @@ -110,9 +109,9 @@ private function validateConfig(stdClass $parsedContent): JsonSchema\ValidationR } // @codeCoverageIgnoreEnd - $schemaResolver->registerFile($schemaReference, $schemaFile); + $schemaResolver->registerFile(Paths::PROJECT_SCHEMA_REFERENCE, $schemaFile); - return $this->validator->validate($parsedContent, $schemaReference); + return $this->validator->validate($parsedContent, Paths::PROJECT_SCHEMA_REFERENCE); } private function generateMapperSource(string $content, string $identifier, FileType $fileType): Mapper\Source\Source diff --git a/src/Builder/Config/ConfigReader.php b/src/Builder/Config/ConfigReader.php index e2a9374a..12c439eb 100644 --- a/src/Builder/Config/ConfigReader.php +++ b/src/Builder/Config/ConfigReader.php @@ -65,7 +65,7 @@ private function __construct( public static function create(?string $templateDirectory = null): self { - $templateDirectory ??= Filesystem\Path::join(Helper\FilesystemHelper::getProjectRootPath(), Paths::PROJECT_TEMPLATES); + $templateDirectory ??= Helper\FilesystemHelper::path(Helper\FilesystemHelper::getProjectRootPath(), Paths::PROJECT_TEMPLATES); return new self(ConfigFactory::create(), $templateDirectory); } diff --git a/src/Builder/Generator/Step/InstallComposerDependenciesStep.php b/src/Builder/Generator/Step/InstallComposerDependenciesStep.php index fd9e0621..ba4cef6d 100644 --- a/src/Builder/Generator/Step/InstallComposerDependenciesStep.php +++ b/src/Builder/Generator/Step/InstallComposerDependenciesStep.php @@ -25,10 +25,10 @@ use Composer\IO as ComposerIO; use CPSIT\ProjectBuilder\Builder; +use CPSIT\ProjectBuilder\Helper; use CPSIT\ProjectBuilder\IO; use CPSIT\ProjectBuilder\Resource; use Symfony\Component\Console; -use Symfony\Component\Filesystem; /** * InstallComposerDependenciesStep. @@ -49,7 +49,7 @@ public function __construct( public function run(Builder\BuildResult $buildResult): bool { - $composerJson = Filesystem\Path::join($buildResult->getInstructions()->getTemplateDirectory(), 'composer.json'); + $composerJson = Helper\FilesystemHelper::path($buildResult->getInstructions()->getTemplateDirectory(), 'composer.json'); $exitCode = $this->runComposerInstall($composerJson); $buildResult->applyStep($this); diff --git a/src/Builder/Generator/Step/ProcessSharedSourceFilesStep.php b/src/Builder/Generator/Step/ProcessSharedSourceFilesStep.php index d229be3e..0d415c77 100644 --- a/src/Builder/Generator/Step/ProcessSharedSourceFilesStep.php +++ b/src/Builder/Generator/Step/ProcessSharedSourceFilesStep.php @@ -24,6 +24,7 @@ namespace CPSIT\ProjectBuilder\Builder\Generator\Step; use CPSIT\ProjectBuilder\Builder; +use CPSIT\ProjectBuilder\Helper; use CPSIT\ProjectBuilder\IO; use CPSIT\ProjectBuilder\Paths; use CPSIT\ProjectBuilder\Resource; @@ -95,7 +96,7 @@ public static function supports(string $type): bool private function listSharedSourceFiles(Builder\BuildInstructions $instructions): Finder\Finder { - $basePath = Filesystem\Path::join( + $basePath = Helper\FilesystemHelper::path( $instructions->getSharedSourceDirectory(), // Include all installed shared source packages '*', diff --git a/src/Console/Application.php b/src/Console/Application.php index 39d8ce1a..0a5cc703 100644 --- a/src/Console/Application.php +++ b/src/Console/Application.php @@ -27,6 +27,7 @@ use CPSIT\ProjectBuilder\DependencyInjection; use CPSIT\ProjectBuilder\Error; use CPSIT\ProjectBuilder\Exception; +use CPSIT\ProjectBuilder\Helper; use CPSIT\ProjectBuilder\IO; use CPSIT\ProjectBuilder\Paths; use CPSIT\ProjectBuilder\Resource; @@ -127,8 +128,8 @@ public function run(bool $disableTemplateSourceCache = false): int private function mirrorSourceFiles(): void { $this->filesystem->mirror( - Filesystem\Path::join($this->targetDirectory, Paths::PROJECT_SOURCES), - Filesystem\Path::join($this->targetDirectory, '.build', Paths::PROJECT_SOURCES), + Helper\FilesystemHelper::path($this->targetDirectory, Paths::PROJECT_SOURCES), + Helper\FilesystemHelper::path($this->targetDirectory, '.build', Paths::PROJECT_SOURCES), ); } diff --git a/src/Console/Simulation.php b/src/Console/Simulation.php index f1f8a220..31b9c082 100644 --- a/src/Console/Simulation.php +++ b/src/Console/Simulation.php @@ -65,7 +65,7 @@ public static function create(): self new Resource\Local\Composer($filesystem), Factory::createOutput(), $rootPath, - Filesystem\Path::join($rootPath, '.build', uniqid('simulate_')), + Helper\FilesystemHelper::path($rootPath, '.build', uniqid('simulate_')), ); } @@ -88,7 +88,7 @@ public function prepare(): string // Install project $exitCode = $this->composer->install( - Filesystem\Path::join($this->targetDirectory, 'composer.json'), + Helper\FilesystemHelper::path($this->targetDirectory, 'composer.json'), true, $this->output, ); diff --git a/src/DependencyInjection/ContainerFactory.php b/src/DependencyInjection/ContainerFactory.php index fe918e51..5c400451 100644 --- a/src/DependencyInjection/ContainerFactory.php +++ b/src/DependencyInjection/ContainerFactory.php @@ -71,7 +71,7 @@ public static function create(array $resourcePaths = []): self public static function createFromConfig(Builder\Config\Config $config): self { $resourcePaths = [ - Filesystem\Path::join( + Helper\FilesystemHelper::path( Helper\FilesystemHelper::getProjectRootPath(), Paths::PROJECT_TEMPLATES, basename(dirname($config->getDeclaringFile())), @@ -85,18 +85,18 @@ public static function createFromConfig(Builder\Config\Config $config): self public static function createForTesting(string $testsRootPath = 'tests'): self { if (!Filesystem\Path::isAbsolute($testsRootPath)) { - $testsRootPath = Filesystem\Path::join( + $testsRootPath = Helper\FilesystemHelper::path( Helper\FilesystemHelper::getProjectRootPath(), $testsRootPath, ); } $resources = self::locateResources([ - Filesystem\Path::join( + Helper\FilesystemHelper::path( $testsRootPath, 'config', ), ]); - $containerPath = Filesystem\Path::join( + $containerPath = Helper\FilesystemHelper::path( Helper\FilesystemHelper::getProjectRootPath(), 'var', 'cache', @@ -115,7 +115,7 @@ public function get(): DependencyInjection\ContainerInterface if ($this->debug && null !== $this->containerPath) { $containerXmlFilename = Filesystem\Path::getFilenameWithoutExtension($this->containerPath); - $containerXmlPath = Filesystem\Path::join(dirname($this->containerPath), $containerXmlFilename.'.xml'); + $containerXmlPath = Helper\FilesystemHelper::path(dirname($this->containerPath), $containerXmlFilename.'.xml'); $container->addCompilerPass(new CompilerPass\ContainerBuilderDebugDumpPass($containerXmlPath)); } @@ -185,6 +185,6 @@ private static function locateResources(array $resourcePaths = []): array private static function getDefaultResourcePath(): string { - return Filesystem\Path::join(Helper\FilesystemHelper::getProjectRootPath(), Paths::PROJECT_SERVICE_CONFIG); + return Helper\FilesystemHelper::path(Helper\FilesystemHelper::getProjectRootPath(), Paths::PROJECT_SERVICE_CONFIG); } } diff --git a/src/Helper/FilesystemHelper.php b/src/Helper/FilesystemHelper.php index c3faca52..79e058d1 100644 --- a/src/Helper/FilesystemHelper.php +++ b/src/Helper/FilesystemHelper.php @@ -28,7 +28,9 @@ use Symfony\Component\Finder; use function dirname; +use function explode; use function getenv; +use function implode; /** * FilesystemHelper. @@ -41,7 +43,7 @@ final class FilesystemHelper public static function createFileObject(string $baseDir, string $relativePathname): Finder\SplFileInfo { return new Finder\SplFileInfo( - Filesystem\Path::join($baseDir, $relativePathname), + self::path($baseDir, $relativePathname), dirname($relativePathname), $relativePathname, ); @@ -50,7 +52,7 @@ public static function createFileObject(string $baseDir, string $relativePathnam public static function getNewTemporaryDirectory(): string { do { - $dir = Filesystem\Path::join(sys_get_temp_dir(), uniqid('cpsit_project_builder_')); + $dir = self::path(sys_get_temp_dir(), uniqid('cpsit_project_builder_')); } while (is_dir($dir)); return $dir; @@ -63,9 +65,16 @@ public static function getProjectRootPath(): string } if (null !== $rootPath) { - $rootPath = Filesystem\Path::canonicalize($rootPath); + $rootPath = self::path($rootPath); } return $rootPath ?? dirname(__DIR__, 2); } + + public static function path(string ...$segments): string + { + $normalizedSegments = explode('/', Filesystem\Path::join(...$segments)); + + return implode(DIRECTORY_SEPARATOR, $normalizedSegments); + } } diff --git a/src/Paths.php b/src/Paths.php index e3bc3235..658c346b 100644 --- a/src/Paths.php +++ b/src/Paths.php @@ -48,6 +48,11 @@ enum Paths */ final public const PROJECT_SCHEMA_CONFIG = 'resources/config.schema.json'; + /** + * Internal reference to the JSON schema for template config files. + */ + final public const PROJECT_SCHEMA_REFERENCE = 'https://project-builder.cps-it.de/schema.json'; + /** * Path to service configurations. */ diff --git a/src/Resource/Local/Composer.php b/src/Resource/Local/Composer.php index 79790b7c..40f508fd 100644 --- a/src/Resource/Local/Composer.php +++ b/src/Resource/Local/Composer.php @@ -136,7 +136,7 @@ public static function createComposer(string $rootPath): \Composer\Composer return $factory->createComposer( new IO\NullIO(), - Filesystem\Path::join($rootPath, 'composer.json'), + Helper\FilesystemHelper::path($rootPath, 'composer.json'), ); } } diff --git a/src/Template/Provider/BaseProvider.php b/src/Template/Provider/BaseProvider.php index 57464917..0d27b211 100644 --- a/src/Template/Provider/BaseProvider.php +++ b/src/Template/Provider/BaseProvider.php @@ -66,7 +66,7 @@ public function __construct( $this->composer = new Resource\Local\Composer($this->filesystem); $this->renderer = new Environment( new Loader\FilesystemLoader([ - Filesystem\Path::join( + Helper\FilesystemHelper::path( Helper\FilesystemHelper::getProjectRootPath(), Paths::PROJECT_INSTALLER, ), @@ -272,7 +272,7 @@ protected function createComposerJson(array $templateSources, array $repositorie ]; $targetDirectory = Helper\FilesystemHelper::getNewTemporaryDirectory(); - $targetFile = Filesystem\Path::join($targetDirectory, 'composer.json'); + $targetFile = Helper\FilesystemHelper::path($targetDirectory, 'composer.json'); $composerJson = $this->renderer->render('composer.json.twig', [ 'templateSources' => $templateSources, 'rootDir' => Helper\FilesystemHelper::getProjectRootPath(), diff --git a/tests/src/Builder/Generator/Step/GenerateBuildArtifactStepTest.php b/tests/src/Builder/Generator/Step/GenerateBuildArtifactStepTest.php index 8edb41b8..20cfd141 100644 --- a/tests/src/Builder/Generator/Step/GenerateBuildArtifactStepTest.php +++ b/tests/src/Builder/Generator/Step/GenerateBuildArtifactStepTest.php @@ -49,7 +49,7 @@ protected function setUp(): void $this->buildResult = new Src\Builder\BuildResult( new Src\Builder\BuildInstructions(self::$config, 'foo'), ); - $this->artifactPath = Filesystem\Path::join( + $this->artifactPath = Src\Helper\FilesystemHelper::path( $this->buildResult->getWrittenDirectory(), '.build/build-artifact.json', );