From 628434fddd899cfad3aae6cafc74ae0b60d95e2d Mon Sep 17 00:00:00 2001 From: Sabina Talipova Date: Tue, 21 Nov 2023 16:48:06 +1300 Subject: [PATCH] MNT New PHP 8.3 support --- consts.php | 6 ++ job_creator.php | 83 ++++++++++++---- tests/JobCreatorTest.php | 206 +++++++++++++++++++++++++++++++++++++-- 3 files changed, 268 insertions(+), 27 deletions(-) diff --git a/consts.php b/consts.php index 3e69073..c8f79c7 100644 --- a/consts.php +++ b/consts.php @@ -31,9 +31,15 @@ '8.1', '8.2', ], + '5.2' => [ + '8.1', + '8.2', + '8.3', + ], '5' => [ '8.1', '8.2', + '8.3', ], ]; diff --git a/job_creator.php b/job_creator.php index 96b56f9..899c95d 100644 --- a/job_creator.php +++ b/job_creator.php @@ -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--) { @@ -235,6 +245,7 @@ private function getPhpVersion(int $phpIndex): string return $phpVersion; } } + throw new Exception("No valid PHP version allowed"); } @@ -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 diff --git a/tests/JobCreatorTest.php b/tests/JobCreatorTest.php index 927c4fe..425c403 100644 --- a/tests/JobCreatorTest.php +++ b/tests/JobCreatorTest.php @@ -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(), + << '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' => '', @@ -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' => '', @@ -297,6 +361,70 @@ public function provideCreateJson(): array ], ] ], + // general test for v5.2 + [ + implode("\n", [ + $this->getGenericYml(), + << '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', + ], + ] + ], ]; } @@ -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'], ]; } @@ -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' => [ @@ -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', ] ], ];