Skip to content

Commit

Permalink
Merge pull request #115 from creative-commoners/pulls/1.17/doorman
Browse files Browse the repository at this point in the history
ENH Fallback to reading PHP version from composer.json
  • Loading branch information
GuySartorelli authored Dec 9, 2024
2 parents 1908713 + 8754dbb commit 00933af
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 6 deletions.
21 changes: 20 additions & 1 deletion job_creator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}

/**
Expand Down
86 changes: 81 additions & 5 deletions tests/JobCreatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
];
}

Expand Down Expand Up @@ -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", [
<<<EOT
composer_install: false
endtoend: true
js: true
phpcoverage: false
phpcoverage_force_off: false
phplinting: true
phpunit: true
doclinting: true
phpunit_skip_suites: ''
dynamic_matrix: true
simple_matrix: false
github_repository: 'silverstripe/doorman'
github_my_ref: '5'
parent_branch: ''
EOT
]);
$creator = new JobCreator();
$creator->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');
}
}
}
}

0 comments on commit 00933af

Please sign in to comment.