Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH Fallback to reading PHP version from composer.json #115

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'],
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes here are in a separate commit to fix unrelated broken unit test

['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');
}
}
}
}
Loading