Skip to content

Commit

Permalink
FIX Use release branch of installer when appropriate (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli authored Nov 29, 2022
1 parent 728bef5 commit 28d62c6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 14 deletions.
27 changes: 20 additions & 7 deletions job_creator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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';
}
}
Expand All @@ -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';
}
}

Expand Down Expand Up @@ -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
Expand All @@ -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;
}

Expand Down
19 changes: 12 additions & 7 deletions tests/JobCreatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -108,30 +109,34 @@ 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'],
['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', $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],
['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],
['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'],
Expand Down Expand Up @@ -329,7 +334,7 @@ public function provideParentBranch(): array
parent_branch: '4.10-release'
EOT
]),
'4.10.x-dev'
'dev-4.10-release'
],
[
implode("\n", [
Expand Down

0 comments on commit 28d62c6

Please sign in to comment.