Skip to content

Commit

Permalink
Merge pull request #27 from creative-commoners/pulls/1.1/next-minor
Browse files Browse the repository at this point in the history
FIX Use next-minor installer for next-minor branches
  • Loading branch information
GuySartorelli authored Jul 27, 2022
2 parents f1a0002 + 5002a01 commit a233cfe
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 26 deletions.
20 changes: 13 additions & 7 deletions job_creator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 20 additions & 19 deletions tests/JobCreatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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', ''],
Expand All @@ -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],
];
}

Expand Down Expand Up @@ -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", [
Expand Down

0 comments on commit a233cfe

Please sign in to comment.