From 5002a01ddebe27767301f12a0bb99d73683f80fc Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Wed, 27 Jul 2022 10:43:28 +1200 Subject: [PATCH] FIX Use next-minor installer for next-minor branches --- job_creator.php | 20 +++++++++++++------- tests/JobCreatorTest.php | 39 ++++++++++++++++++++------------------- 2 files changed, 33 insertions(+), 26 deletions(-) diff --git a/job_creator.php b/job_creator.php index 4db7ac6..8408f3b 100644 --- a/job_creator.php +++ b/job_creator.php @@ -47,15 +47,21 @@ public function getInstallerVersion(): string } } } - // fallback to use the latest minor version of installer + // fallback to use the next-minor or latest-minor version of installer $installerVersions = array_keys(INSTALLER_TO_PHP_VERSIONS); $installerVersions = array_filter($installerVersions, fn($version) => substr($version, 0, 1) === $cmsMajor); - // remove major versions - $installerVersions = array_diff($installerVersions, ['4', '5', '6']); - // get the minor portions of the verisons e.g. [9, 10, 11] - $minorPortions = array_map(fn($portions) => (int) explode('.', $portions)[1], $installerVersions); - sort($minorPortions); - return $cmsMajor . '.' . $minorPortions[count($minorPortions) - 1] . '.x-dev'; + if (preg_match('#^[1-9]+[0-9]*$#', $branch)) { + // next-minor e.g. 4 + return $cmsMajor . '.x-dev'; + } else { + // current-minor e.g. 4.11 + // remove major versions + $installerVersions = array_diff($installerVersions, ['4', '5', '6']); + // get the minor portions of the verisons e.g. [9, 10, 11] + $minorPortions = array_map(fn($portions) => (int) explode('.', $portions)[1], $installerVersions); + sort($minorPortions); + return $cmsMajor . '.' . $minorPortions[count($minorPortions) - 1] . '.x-dev'; + } } public function createJob(int $phpIndex, array $opts): array diff --git a/tests/JobCreatorTest.php b/tests/JobCreatorTest.php index c41ce94..e73900a 100644 --- a/tests/JobCreatorTest.php +++ b/tests/JobCreatorTest.php @@ -77,7 +77,7 @@ public function testGetInstallerVersion( $this->assertSame($expected, $actual); } - private function getLatestInstallerVersion(string $cmsMajor): string + private function getCurrentMinorInstallerVersion(string $cmsMajor): string { $versions = array_keys(INSTALLER_TO_PHP_VERSIONS); $versions = array_filter($versions, fn($version) => substr($version, 0, 1) === $cmsMajor); @@ -88,7 +88,8 @@ private function getLatestInstallerVersion(string $cmsMajor): string public function provideGetInstallerVersion(): array { - $latest = $this->getLatestInstallerVersion('4') . '.x-dev'; + $nextMinor = '4.x-dev'; + $currentMinor = $this->getCurrentMinorInstallerVersion('4') . '.x-dev'; return [ // no-installer repo ['myaccount/recipe-cms', '4', ''], @@ -102,40 +103,40 @@ public function provideGetInstallerVersion(): array // lockstepped repo with 4.* naming ['myaccount/silverstripe-framework', '4', '4.x-dev'], ['myaccount/silverstripe-framework', '4.10', '4.10.x-dev'], - ['myaccount/silverstripe-framework', 'burger', $latest], + ['myaccount/silverstripe-framework', 'burger', $currentMinor], ['myaccount/silverstripe-framework', 'pulls/4/mybugfix', '4.x-dev'], ['myaccount/silverstripe-framework', 'pulls/4.10/mybugfix', '4.10.x-dev'], - ['myaccount/silverstripe-framework', 'pulls/burger/myfeature', $latest], + ['myaccount/silverstripe-framework', 'pulls/burger/myfeature', $currentMinor], ['myaccount/silverstripe-framework', '4-release', '4.x-dev'], ['myaccount/silverstripe-framework', '4.10-release', '4.10.x-dev'], // lockstepped repo with 1.* naming ['myaccount/silverstripe-admin', '1', '4.x-dev'], ['myaccount/silverstripe-admin', '1.10', '4.10.x-dev'], - ['myaccount/silverstripe-admin', 'burger', $latest], + ['myaccount/silverstripe-admin', 'burger', $currentMinor], ['myaccount/silverstripe-admin', 'pulls/1/mybugfix', '4.x-dev'], ['myaccount/silverstripe-admin', 'pulls/1.10/mybugfix', '4.10.x-dev'], - ['myaccount/silverstripe-admin', 'pulls/burger/myfeature', $latest], + ['myaccount/silverstripe-admin', 'pulls/burger/myfeature', $currentMinor], ['myaccount/silverstripe-admin', '1-release', '4.x-dev'], ['myaccount/silverstripe-admin', '1.10-release', '4.10.x-dev'], // non-lockedstepped repo - ['myaccount/silverstripe-tagfield', '2', $latest], - ['myaccount/silverstripe-tagfield', '2.9', $latest], - ['myaccount/silverstripe-tagfield', 'burger', $latest], - ['myaccount/silverstripe-tagfield', 'pulls/2/mybugfix', $latest], - ['myaccount/silverstripe-tagfield', 'pulls/2.9/mybugfix', $latest], - ['myaccount/silverstripe-tagfield', 'pulls/burger/myfeature', $latest], - ['myaccount/silverstripe-tagfield', '2-release', $latest], - ['myaccount/silverstripe-tagfield', '2.9-release', $latest], + ['myaccount/silverstripe-tagfield', '2', $nextMinor], + ['myaccount/silverstripe-tagfield', '2.9', $currentMinor], + ['myaccount/silverstripe-tagfield', 'burger', $currentMinor], + ['myaccount/silverstripe-tagfield', 'pulls/2/mybugfix', $nextMinor], + ['myaccount/silverstripe-tagfield', 'pulls/2.9/mybugfix', $currentMinor], + ['myaccount/silverstripe-tagfield', 'pulls/burger/myfeature', $currentMinor], + ['myaccount/silverstripe-tagfield', '2-release', $nextMinor], + ['myaccount/silverstripe-tagfield', '2.9-release', $currentMinor], // hardcoded repo version - ['myaccount/silverstripe-session-manager', '1', $latest], + ['myaccount/silverstripe-session-manager', '1', $nextMinor], ['myaccount/silverstripe-session-manager', '1.2', '4.10.x-dev'], - ['myaccount/silverstripe-session-manager', 'burger', $latest], + ['myaccount/silverstripe-session-manager', 'burger', $currentMinor], // hardcoded repo version using array - ['myaccount/silverstripe-html5', '2', $latest], + ['myaccount/silverstripe-html5', '2', $nextMinor], ['myaccount/silverstripe-html5', '2.2', '4.10.x-dev'], ['myaccount/silverstripe-html5', '2.3', '4.10.x-dev'], ['myaccount/silverstripe-html5', '2.4', '4.11.x-dev'], - ['myaccount/silverstripe-html5', 'burger', $latest], + ['myaccount/silverstripe-html5', 'burger', $currentMinor], ]; } @@ -271,7 +272,7 @@ private function getGenericYml(): string public function provideParentBranch(): array { - $latest = $this->getLatestInstallerVersion('4') . '.x-dev'; + $latest = $this->getCurrentMinorInstallerVersion('4') . '.x-dev'; return [ [ implode("\n", [