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

MNT New PHP 8.3 support #74

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
6 changes: 6 additions & 0 deletions consts.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,15 @@
'8.1',
'8.2',
],
'5.2' => [
'8.1',
'8.2',
'8.3',
],
'5' => [
'8.1',
'8.2',
GuySartorelli marked this conversation as resolved.
Show resolved Hide resolved
'8.3',
],
];

Expand Down
83 changes: 65 additions & 18 deletions job_creator.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,23 +197,33 @@ private function isAllowedPhpVersion(string $phpVersion)
return false;
}

private function getPhpVersion(int $phpIndex): string
/**
* Get the branch name from the installer version and left only the minor version
* e.g. 4.10.x-dev -> 4.10
*/
private function getBranchName(): string
{
if ($this->phpVersionOverride) {
return $this->phpVersionOverride;
}
$key = str_replace('.x-dev', '', $this->installerVersion);
$version = str_replace('.x-dev', '', $this->installerVersion);
$repo = explode('/', $this->githubRepository)[1];
if (in_array($repo, NO_INSTALLER_LOCKSTEPPED_REPOS)) {
$cmsMajor = $this->getCmsMajor();
$branch = $this->getCleanedBranch();
if (preg_match('#^[1-9]$#', $branch)) {
$key = $cmsMajor;
$version = $cmsMajor;
} elseif (preg_match('#^[1-9]\.([0-9]+)$#', $branch, $matches)) {
$key = sprintf('%d.%d', $cmsMajor, $matches[1]);
$version = sprintf('%d.%d', $cmsMajor, $matches[1]);
}
}
$phpVersions = INSTALLER_TO_PHP_VERSIONS[$key] ?? INSTALLER_TO_PHP_VERSIONS['4'];

return $version;
}

private function getPhpVersion(int $phpIndex): string
{
if ($this->phpVersionOverride) {
return $this->phpVersionOverride;
}
$phpVersions = $this->getListOfPhpVersionsByBranchName();
// Use the max allowed php version
if (!array_key_exists($phpIndex, $phpVersions)) {
for ($i = count($phpVersions) - 1; $i >= 0; $i--) {
Expand All @@ -235,6 +245,7 @@ private function getPhpVersion(int $phpIndex): string
return $phpVersion;
}
}

throw new Exception("No valid PHP version allowed");
}

Expand Down Expand Up @@ -369,21 +380,57 @@ private function createPhpunitJobs(
'phpunit_suite' => $suite,
]);
} elseif ($this->getCmsMajor() === '5') {
$matrix['include'][] = $this->createJob(0, [
'db' => DB_MARIADB,
'phpunit' => true,
'phpunit_suite' => $suite,
]);
$matrix['include'][] = $this->createJob(1, [
'db' => DB_MYSQL_80,
'phpunit' => true,
'phpunit_suite' => $suite,
]);
// phpunit tests for cms 5 are run on php 8.1, 8.2 or 8.3 and mysql 8.0 or mariadb
$phpToDB = $this->generatePhpToDBMap();
foreach ($phpToDB as $php => $db) {
$matrix['include'][] = $this->createJob($this->getIndexByPHPVersion($php), [
'db' => $db,
'phpunit' => true,
'phpunit_suite' => $suite,
]);
}
}
}
return $matrix;
}

/**
* Return the list of php versions for the branch
*/
private function getListOfPhpVersionsByBranchName(): array
{
return INSTALLER_TO_PHP_VERSIONS[$this->getBranchName()] ?? INSTALLER_TO_PHP_VERSIONS['4'];
}

/**
* Return the index of the php version in the list of php versions for the branch
*/
private function getIndexByPHPVersion(string $version): int
{
return array_search($version, $this->getListOfPhpVersionsByBranchName()) ?? 0;
}

/**
* Generate a map of php versions to db versions
* e.g. [ '8.1' => 'mariadb', '8.2' => 'mysql80' ]
*/
private function generatePhpToDBMap(): array
{
$map = [];
$phpVersions = $this->getListOfPhpVersionsByBranchName();
$dbs = [DB_MARIADB, DB_MYSQL_80];
foreach ($phpVersions as $key => $phpVersion) {
if (count($phpVersions) < 3) {
$map[$phpVersion] = $dbs[$key];
} else {
if ($key === 0) continue;
$map[$phpVersion] = array_key_exists($key, $dbs) ? $dbs[$key - 1] : DB_MYSQL_80;
}
}

return $map;
}

private function doRunPhpCoverage(array $run): bool
{
// (currently disabled) always run on silverstripe account, unless phpcoverage_force_off is set to true
Expand Down
206 changes: 197 additions & 9 deletions tests/JobCreatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,70 @@ public function provideCreateJson(): array
],
[
'installer_version' => '5.x-dev',
'php' => '8.2',
'db' => DB_MARIADB,
'composer_require_extra' => '',
'composer_args' => '',
'name_suffix' => '',
'phpunit' => 'true',
'phpunit_suite' => 'all',
'phplinting' => 'false',
'phpcoverage' => 'false',
'endtoend' => 'false',
'endtoend_suite' => 'root',
'endtoend_config' => '',
'js' => 'false',
'name' => '8.2 mariadb phpunit all',
],
[
'installer_version' => '5.x-dev',
'php' => '8.3',
'db' => DB_MYSQL_80,
'composer_require_extra' => '',
'composer_args' => '',
'name_suffix' => '',
'phpunit' => 'true',
'phpunit_suite' => 'all',
'phplinting' => 'false',
'phpcoverage' => 'false',
'endtoend' => 'false',
'endtoend_suite' => 'root',
'endtoend_config' => '',
'js' => 'false',
'name' => '8.3 mysql80 phpunit all',
],
]
],
// general test for v5.1
[
implode("\n", [
$this->getGenericYml(),
<<<EOT
github_repository: 'myaccount/silverstripe-framework'
github_my_ref: '5.1'
parent_branch: ''
EOT
]),
[
[
'installer_version' => '5.1.x-dev',
'php' => '8.1',
'db' => DB_MYSQL_57,
'composer_require_extra' => '',
'composer_args' => '--prefer-lowest',
'name_suffix' => '',
'phpunit' => 'true',
'phpunit_suite' => 'all',
'phplinting' => 'false',
'phpcoverage' => 'false',
'endtoend' => 'false',
'endtoend_suite' => 'root',
'endtoend_config' => '',
'js' => 'false',
'name' => '8.1 prf-low mysql57 phpunit all',
],
[
'installer_version' => '5.1.x-dev',
'php' => '8.1',
'db' => DB_MARIADB,
'composer_require_extra' => '',
Expand All @@ -279,7 +343,7 @@ public function provideCreateJson(): array
'name' => '8.1 mariadb phpunit all',
],
[
'installer_version' => '5.x-dev',
'installer_version' => '5.1.x-dev',
'php' => '8.2',
'db' => DB_MYSQL_80,
'composer_require_extra' => '',
Expand All @@ -297,6 +361,70 @@ public function provideCreateJson(): array
],
]
],
// general test for v5.2
[
implode("\n", [
$this->getGenericYml(),
<<<EOT
github_repository: 'myaccount/silverstripe-framework'
github_my_ref: '5.2'
parent_branch: ''
EOT
]),
[
[
'installer_version' => '5.2.x-dev',
'php' => '8.1',
'db' => DB_MYSQL_57,
'composer_require_extra' => '',
'composer_args' => '--prefer-lowest',
'name_suffix' => '',
'phpunit' => 'true',
'phpunit_suite' => 'all',
'phplinting' => 'false',
'phpcoverage' => 'false',
'endtoend' => 'false',
'endtoend_suite' => 'root',
'endtoend_config' => '',
'js' => 'false',
'name' => '8.1 prf-low mysql57 phpunit all',
],
[
'installer_version' => '5.2.x-dev',
'php' => '8.2',
'db' => DB_MARIADB,
'composer_require_extra' => '',
'composer_args' => '',
'name_suffix' => '',
'phpunit' => 'true',
'phpunit_suite' => 'all',
'phplinting' => 'false',
'phpcoverage' => 'false',
'endtoend' => 'false',
'endtoend_suite' => 'root',
'endtoend_config' => '',
'js' => 'false',
'name' => '8.2 mariadb phpunit all',
],
[
'installer_version' => '5.2.x-dev',
'php' => '8.3',
'db' => DB_MYSQL_80,
'composer_require_extra' => '',
'composer_args' => '',
'name_suffix' => '',
'phpunit' => 'true',
'phpunit_suite' => 'all',
'phplinting' => 'false',
'phpcoverage' => 'false',
'endtoend' => 'false',
'endtoend_suite' => 'root',
'endtoend_config' => '',
'js' => 'false',
'name' => '8.3 mysql80 phpunit all',
],
]
],
];
}

Expand Down Expand Up @@ -675,9 +803,9 @@ public function provideGetInstallerVersionCMS5FromComposer(): array
// fallback to looking at deps in composer.json, use current minor of installer .x-dev
['myaccount/silverstripe-admin', 'mybranch', ['silverstripe/framework' => '5.x-dev'], '5.x-dev'],
['myaccount/silverstripe-admin', 'mybranch', ['silverstripe/framework' => '5.0.x-dev'], '5.0.x-dev'],
['myaccount/silverstripe-admin', 'mybranch', ['silverstripe/framework' => '^5'], '5.1.x-dev'],
['myaccount/silverstripe-somemodule', 'mybranch', ['silverstripe/cms' => '^5'], '5.1.x-dev'],
['myaccount/silverstripe-somemodule', 'mybranch', ['silverstripe/admin' => '^2'], '5.1.x-dev'],
['myaccount/silverstripe-admin', 'mybranch', ['silverstripe/framework' => '^5'], '5.2.x-dev'],
['myaccount/silverstripe-somemodule', 'mybranch', ['silverstripe/cms' => '^5'], '5.2.x-dev'],
['myaccount/silverstripe-somemodule', 'mybranch', ['silverstripe/admin' => '^2'], '5.2.x-dev'],
['myaccount/silverstripe-somemodule', '3', ['silverstripe/framework' => '^5'], '5.x-dev'],
];
}
Expand Down Expand Up @@ -771,8 +899,8 @@ public function provideComposerInstall(): array
'5.x-dev',
[
'8.1 prf-low mysql57 phpunit all',
'8.1 mariadb phpunit all',
'8.2 mysql80 phpunit all'
'8.2 mariadb phpunit all',
'8.3 mysql80 phpunit all',
]
],
'composerupgrade_definedphpversion_framework5' => [
Expand All @@ -781,18 +909,78 @@ public function provideComposerInstall(): array
'5.x-dev',
[
'8.1 prf-low mysql57 phpunit all',
'8.1 mariadb phpunit all',
'8.2 mysql80 phpunit all'
'8.2 mariadb phpunit all',
'8.3 mysql80 phpunit all',
]
],
'composerupgrade_invalidphpversion_framework5' => [
'false',
'fish',
'5.x-dev',
[
'8.1 prf-low mysql57 phpunit all',
'8.2 mariadb phpunit all',
'8.3 mysql80 phpunit all',
]
],
'composerupgrade_nophpversion_framework51' => [
'false',
'',
'5.1.x-dev',
[
'8.1 prf-low mysql57 phpunit all',
'8.1 mariadb phpunit all',
'8.2 mysql80 phpunit all',
]
],
'composerupgrade_definedphpversion_framework51' => [
'false',
'21.99',
'5.1.x-dev',
[
'8.1 prf-low mysql57 phpunit all',
'8.1 mariadb phpunit all',
'8.2 mysql80 phpunit all',
]
],
'composerupgrade_invalidphpversion_framework51' => [
'false',
'fish',
'5.1.x-dev',
[
'8.1 prf-low mysql57 phpunit all',
'8.1 mariadb phpunit all',
'8.2 mysql80 phpunit all'
'8.2 mysql80 phpunit all',
]
],
'composerupgrade_nophpversion_framework52' => [
'false',
'',
'5.2.x-dev',
[
'8.1 prf-low mysql57 phpunit all',
'8.2 mariadb phpunit all',
'8.3 mysql80 phpunit all',
]
],
'composerupgrade_definedphpversion_framework52' => [
'false',
'21.99',
'5.2.x-dev',
[
'8.1 prf-low mysql57 phpunit all',
'8.2 mariadb phpunit all',
'8.3 mysql80 phpunit all',
]
],
'composerupgrade_invalidphpversion_framework52' => [
'false',
'fish',
'5.2.x-dev',
[
'8.1 prf-low mysql57 phpunit all',
'8.2 mariadb phpunit all',
'8.3 mysql80 phpunit all',
]
],
];
Expand Down