Skip to content

Commit

Permalink
[TASK] Run tests on Windows and macOS as well
Browse files Browse the repository at this point in the history
  • Loading branch information
eliashaeussler committed Apr 2, 2024
1 parent 6027512 commit fafff6e
Show file tree
Hide file tree
Showing 14 changed files with 58 additions and 31 deletions.
19 changes: 16 additions & 3 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -28,6 +40,7 @@ jobs:
with:
php-version: ${{ matrix.php-version }}
tools: composer:v${{ matrix.composer-version }}
extensions: sockets
coverage: none

# Install dependencies
Expand All @@ -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
Expand Down
5 changes: 2 additions & 3 deletions src/Builder/BuildInstructions.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
use ArrayObject;
use CPSIT\ProjectBuilder\Helper;
use CPSIT\ProjectBuilder\Paths;
use Symfony\Component\Filesystem;

use function dirname;

Expand Down Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions src/Builder/Config/ConfigFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Builder/Config/ConfigReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/Builder/Generator/Step/ProcessSharedSourceFilesStep.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
'*',
Expand Down
5 changes: 3 additions & 2 deletions src/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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),
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Console/Simulation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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_')),
);
}

Expand All @@ -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,
);
Expand Down
12 changes: 6 additions & 6 deletions src/DependencyInjection/ContainerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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())),
Expand All @@ -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',
Expand All @@ -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));
}

Expand Down Expand Up @@ -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);
}
}
15 changes: 12 additions & 3 deletions src/Helper/FilesystemHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
use Symfony\Component\Finder;

use function dirname;
use function explode;
use function getenv;
use function implode;

/**
* FilesystemHelper.
Expand All @@ -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,
);
Expand All @@ -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;
Expand All @@ -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);
}
}
5 changes: 5 additions & 0 deletions src/Paths.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Resource/Local/Composer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
);
}
}
4 changes: 2 additions & 2 deletions src/Template/Provider/BaseProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
Expand Down Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
);
Expand Down

0 comments on commit fafff6e

Please sign in to comment.