From e35094d4737e13fd14ef4d8e9a197cd0feb87a86 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Mon, 9 Dec 2024 17:32:51 +1300 Subject: [PATCH 1/2] MNT Update unit test for installer 6.0 support --- tests/JobCreatorTest.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/JobCreatorTest.php b/tests/JobCreatorTest.php index 2a51cd7..cd5bdbf 100644 --- a/tests/JobCreatorTest.php +++ b/tests/JobCreatorTest.php @@ -1988,16 +1988,16 @@ public function provideGetInstallerVersionFromComposer(): array // the `6.0` branches are created - currently only `6` branches exist ['myaccount/silverstripe-admin', 'mybranch', ['silverstripe/framework' => '6.x-dev'], 'silverstripe-module', '6.x-dev'], ['myaccount/silverstripe-admin', 'mybranch', ['silverstripe/framework' => '6.0.x-dev'], 'silverstripe-vendormodule', '6.0.x-dev'], - ['myaccount/silverstripe-admin', 'mybranch', ['silverstripe/framework' => '^6'], 'silverstripe-theme', '6.x-dev'], - ['myaccount/silverstripe-somemodule', 'mybranch', ['silverstripe/cms' => '^6'], 'silverstripe-recipe', '6.x-dev'], - ['myaccount/silverstripe-somemodule', 'mybranch', ['silverstripe/admin' => '^3'], 'silverstripe-vendormodule', '6.x-dev'], + ['myaccount/silverstripe-admin', 'mybranch', ['silverstripe/framework' => '^6'], 'silverstripe-theme', '6.0.x-dev'], + ['myaccount/silverstripe-somemodule', 'mybranch', ['silverstripe/cms' => '^6'], 'silverstripe-recipe', '6.0.x-dev'], + ['myaccount/silverstripe-somemodule', 'mybranch', ['silverstripe/admin' => '^3'], 'silverstripe-vendormodule', '6.0.x-dev'], ['myaccount/silverstripe-somemodule', '4', ['silverstripe/framework' => '^6'], 'silverstripe-vendormodule', '6.x-dev'], ['myaccount/silverstripe-somemodule', '4', ['silverstripe/framework' => '^6'], 'package', ''], ['myaccount/silverstripe-somemodule', '4', ['silverstripe/framework' => '^6'], '', ''], ['myaccount/silverstripe-somemodule', '4', [], '', ''], // // recipe-plugin and vendor-plugin do not override framework - ['myaccount/silverstripe-admin', 'mybranch', ['silverstripe/recipe-plugin' => '^2', 'silverstripe/framework' => '^6'], 'silverstripe-vendormodule', '6.x-dev'], - ['myaccount/silverstripe-admin', 'mybranch', ['silverstripe/vendor-plugin' => '^2', 'silverstripe/framework' => '^6'], 'silverstripe-vendormodule', '6.x-dev'], + ['myaccount/silverstripe-admin', 'mybranch', ['silverstripe/recipe-plugin' => '^2', 'silverstripe/framework' => '^6'], 'silverstripe-vendormodule', '6.0.x-dev'], + ['myaccount/silverstripe-admin', 'mybranch', ['silverstripe/vendor-plugin' => '^2', 'silverstripe/framework' => '^6'], 'silverstripe-vendormodule', '6.0.x-dev'], ]; } From 8754dbbaadb8f8189415cafaf9f340265bb023a1 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Tue, 10 Dec 2024 09:52:44 +1300 Subject: [PATCH 2/2] ENH Fallback to reading PHP version from composer.json --- job_creator.php | 21 ++++++++++- tests/JobCreatorTest.php | 76 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+), 1 deletion(-) diff --git a/job_creator.php b/job_creator.php index c78e067..c49dc81 100644 --- a/job_creator.php +++ b/job_creator.php @@ -368,7 +368,26 @@ private function createPhpunitJobs( private function getListOfPhpVersionsByBranchName(): array { $branch = $this->getInstallerBranch(); - return MetaData::PHP_VERSIONS_FOR_CMS_RELEASES[$branch] ?? MetaData::PHP_VERSIONS_FOR_CMS_RELEASES['4']; + if (isset(MetaData::PHP_VERSIONS_FOR_CMS_RELEASES[$branch])) { + return MetaData::PHP_VERSIONS_FOR_CMS_RELEASES[$branch]; + } + // Fallback to using a CMS major based on the version of PHP in composer.json + $json = $this->getComposerJsonContent(); + if ($json) { + $php = $json->require->php ?? null; + $php = str_replace('^', '', $php); + $cmsMajors = array_keys(MetaData::PHP_VERSIONS_FOR_CMS_RELEASES); + $cmsMajors = array_filter($cmsMajors, fn($v) => !str_contains($v, '.')); + $cmsMajors = array_reverse($cmsMajors); + foreach ($cmsMajors as $cmsMajor) { + $phpVersions = MetaData::PHP_VERSIONS_FOR_CMS_RELEASES[$cmsMajor]; + if (in_array($php, $phpVersions)) { + return $phpVersions; + } + } + } + // Fallback to the PHP versions allowed for the lowest supported major release line + return MetaData::PHP_VERSIONS_FOR_CMS_RELEASES[MetaData::LOWEST_SUPPORTED_CMS_MAJOR]; } /** diff --git a/tests/JobCreatorTest.php b/tests/JobCreatorTest.php index cd5bdbf..570db2b 100644 --- a/tests/JobCreatorTest.php +++ b/tests/JobCreatorTest.php @@ -2299,4 +2299,80 @@ public function testDuplicateJobsRemoved(): void ]; $this->assertSame($expected, $actual); } + + public function providePhpFallbackDoorman(): array + { + return [ + 'php81' => [ + 'php' => '^8.1', + 'exception' => false, + 'expected' => [ + '8.1 prf-low mariadb phpunit all', + '8.2 mysql80 phpunit all', + '8.3 mysql84 phpunit all', + ], + ], + 'php83' => [ + 'php' => '^8.3', + 'exception' => false, + 'expected' => [ + '8.3 prf-low mariadb phpunit all', + '8.3 mysql80 phpunit all', + '8.4 mysql84 phpunit all', + ], + ], + 'none' => [ + 'php' => 'none', + 'exception' => true, + 'expected' => null, + ], + ]; + } + + /** + * @dataProvider providePhpFallbackDoorman + */ + public function testPhpFallbackDoorman(string $php, bool $exception, ?array $expected): void + { + if (!function_exists('yaml_parse')) { + $this->markTestSkipped('yaml extension is not installed'); + } + if ($exception) { + $this->expectException(Exception::class); + } + try { + $yml = implode("\n", [ + <<composerJsonPath = '__composer.json'; + $this->writeComposerJson(['php' => $php]); + $creator->githubRepository = 'silverstripe/doorman'; + $creator->repoName = 'doorman'; + $creator->branch = '5'; + $creator->parseRepositoryMetadata(); + $json = json_decode($creator->createJson($yml)); + $actual = array_map(fn($job) => $job->name, $json->include); + $this->assertSame($expected, $actual); + } finally { + if (file_exists('__composer.json')) { + unlink('__composer.json'); + } + } + } }