diff --git a/job_creator.php b/job_creator.php index db8d83e..6b9a611 100644 --- a/job_creator.php +++ b/job_creator.php @@ -26,10 +26,14 @@ public function getInstallerVersion(): string if (in_array($repo, NO_INSTALLER_LOCKSTEPPED_REPOS) || in_array($repo, NO_INSTALLER_UNLOCKSTEPPED_REPOS)) { return ''; } - $branch = $this->getCleanedBranch(); + $branch = $this->getCleanedBranch(true); + $isReleaseBranch = preg_match('#^[0-9\.]+-release$#', $branch); $cmsMajor = $this->getCmsMajor(); // repo is a lockstepped repo - if (in_array($repo, LOCKSTEPPED_REPOS) && is_numeric($branch)) { + if (in_array($repo, LOCKSTEPPED_REPOS) && (is_numeric($branch) || $isReleaseBranch)) { + if ($isReleaseBranch) { + return 'dev-' . preg_replace('#^([0-9])#', $cmsMajor, $branch); + } // e.g. ['4', '11'] $portions = explode('.', $branch); if (count($portions) == 1) { @@ -43,7 +47,10 @@ public function getInstallerVersion(): string foreach (INSTALLER_TO_REPO_MINOR_VERSIONS[$installerVersion] as $_repo => $_repoVersions) { $repoVersions = is_array($_repoVersions) ? $_repoVersions : [$_repoVersions]; foreach ($repoVersions as $repoVersion) { - if ($repo === $_repo && $repoVersion === $branch) { + if ($repo === $_repo && $repoVersion === preg_replace('#-release$#', '', $branch)) { + if ($isReleaseBranch) { + return 'dev-' . $installerVersion . '-release'; + } return $installerVersion . '.x-dev'; } } @@ -63,7 +70,11 @@ public function getInstallerVersion(): string $minorPortions = array_map(fn($portions) => (int) explode('.', $portions)[1], $installerVersions); sort($minorPortions); $minorPortion = $minorPortions[count($minorPortions) - 1]; - return $cmsMajor . '.' . $minorPortion . '.x-dev'; + $installerVersion = $cmsMajor . '.' . $minorPortion; + if ($isReleaseBranch) { + return 'dev-' . $installerVersion . '-release'; + } + return $installerVersion . '.x-dev'; } } @@ -275,12 +286,12 @@ private function getCmsMajorFromComposerJson(): string return ''; } - private function getCleanedBranch(): string + private function getCleanedBranch(bool $allowReleaseSuffix = false): string { $branch = $this->branch; // e.g. pulls/4.10/some-bugfix or pulls/4/some-feature // for push events to the creative-commoners account - if (preg_match('#^pulls/([0-9\.]+)/#', $branch, $matches)) { + if (preg_match('#^pulls/([0-9\.]+(-release)?)/#', $branch, $matches)) { $branch = $matches[1]; } // fallback to parent branch if available @@ -292,7 +303,9 @@ private function getCleanedBranch(): string $branch = $this->parentBranch; } // e.g. 4.10-release - $branch = preg_replace('#^([0-9\.]+)-release$#', '$1', $branch); + if (!$allowReleaseSuffix) { + $branch = preg_replace('#^([0-9\.]+)-release$#', '$1', $branch); + } return $branch; } diff --git a/tests/JobCreatorTest.php b/tests/JobCreatorTest.php index f03a8e4..cbcc7c1 100644 --- a/tests/JobCreatorTest.php +++ b/tests/JobCreatorTest.php @@ -90,6 +90,7 @@ private function getCurrentMinorInstallerVersion(string $cmsMajor): string public function provideGetInstallerVersion(): array { $nextMinor = '4.x-dev'; + $nextMinorRelease = 'dev-' . $this->getCurrentMinorInstallerVersion('4') . '-release'; $currentMinor = $this->getCurrentMinorInstallerVersion('4') . '.x-dev'; return [ // no-installer repo @@ -108,8 +109,9 @@ public function provideGetInstallerVersion(): array ['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', $currentMinor], - ['myaccount/silverstripe-framework', '4-release', '4.x-dev'], - ['myaccount/silverstripe-framework', '4.10-release', '4.10.x-dev'], + ['myaccount/silverstripe-framework', '4-release', 'dev-4-release'], + ['myaccount/silverstripe-framework', '4.10-release', 'dev-4.10-release'], + ['myaccount/silverstripe-framework', 'pulls/4.10-release/some-change', 'dev-4.10-release'], // lockstepped repo with 1.* naming ['myaccount/silverstripe-admin', '1', '4.x-dev'], ['myaccount/silverstripe-admin', '1.10', '4.10.x-dev'], @@ -117,8 +119,9 @@ public function provideGetInstallerVersion(): array ['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', $currentMinor], - ['myaccount/silverstripe-admin', '1-release', '4.x-dev'], - ['myaccount/silverstripe-admin', '1.10-release', '4.10.x-dev'], + ['myaccount/silverstripe-admin', '1-release', 'dev-4-release'], + ['myaccount/silverstripe-admin', '1.10-release', 'dev-4.10-release'], + ['myaccount/silverstripe-admin', 'pulls/1.10-release/some-change', 'dev-4.10-release'], // non-lockedstepped repo ['myaccount/silverstripe-tagfield', '2', $nextMinor], ['myaccount/silverstripe-tagfield', '2.9', $currentMinor], @@ -126,12 +129,14 @@ public function provideGetInstallerVersion(): array ['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], + ['myaccount/silverstripe-tagfield', '2-release', 'dev-' . $this->getCurrentMinorInstallerVersion('4') . '-release'], + ['myaccount/silverstripe-tagfield', '2.9-release', $nextMinorRelease], + ['myaccount/silverstripe-tagfield', 'pulls/2.9-release/some-change', $nextMinorRelease], // hardcoded repo version ['myaccount/silverstripe-session-manager', '1', $nextMinor], ['myaccount/silverstripe-session-manager', '1.2', '4.10.x-dev'], ['myaccount/silverstripe-session-manager', 'burger', $currentMinor], + ['myaccount/silverstripe-session-manager', '1.2-release', 'dev-4.10-release'], // hardcoded repo version using array ['myaccount/silverstripe-html5', '2', $nextMinor], ['myaccount/silverstripe-html5', '2.2', '4.10.x-dev'], @@ -329,7 +334,7 @@ public function provideParentBranch(): array parent_branch: '4.10-release' EOT ]), - '4.10.x-dev' + 'dev-4.10-release' ], [ implode("\n", [