Skip to content

Commit

Permalink
FIX Hardcode some module versions to installer version
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Jul 10, 2022
1 parent c6dca88 commit 08e6b3b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
10 changes: 10 additions & 0 deletions consts.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,13 @@
'silverstripe-installer' => '5',
],
];

const INSTALLER_TO_REPO_MINOR_VERSIONS = [
'4.10' => [
'html5' => '2.3',
'silverstripe-elemental-bannerblock' => '2.4',
'silverstripe-session-manager' => '1.2',
'silverstripe-userforms' => '5.12',
'silverstripe-totp-authenticator' => '4.3',
]
];
19 changes: 14 additions & 5 deletions job_creator.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ class JobCreator
public function getInstallerVersion(): string
{
$repo = explode('/', $this->githubRepository)[1];
// repo should not use installer
if (in_array($repo, NO_INSTALLER_LOCKSTEPPED_REPOS) || in_array($repo, NO_INSTALLER_UNLOCKSTEPPED_REPOS)) {
return '';
}
$branch = $this->getCleanedBranch();
$cmsMajor = $this->getCmsMajorFromBranch();
// module is a lockstepped repo
// repo is a lockstepped repo
if (in_array($repo, LOCKSTEPPED_REPOS) && is_numeric($branch)) {
// e.g. ['4', '11']
$portions = explode('.', $branch);
Expand All @@ -31,11 +32,15 @@ public function getInstallerVersion(): string
return $cmsMajor . '.' . $portions[1] . '.x-dev';
}
}
// use the parent branch
if ($this->parentBranch && is_numeric($this->parentBranch)) {
return $this->parentBranch . '.x-dev';
// hardcoded installer version for repo version
foreach (array_keys(INSTALLER_TO_REPO_MINOR_VERSIONS) as $installerVersion) {
foreach (INSTALLER_TO_REPO_MINOR_VERSIONS[$installerVersion] as $_repo => $repoVersion) {
if ($repo === $_repo && $repoVersion === $branch) {
return $installerVersion . '.x-dev';
}
}
}
// use the latest minor version of installer
// fallback to use the 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
Expand Down Expand Up @@ -119,6 +124,10 @@ private function getCleanedBranch(): string
}
// e.g. 4.10-release
$branch = preg_replace('#^([0-9\.]+)-release$#', '$1', $branch);
// fallback to parent branch if availableable
if (!is_numeric($branch) && $this->parentBranch && is_numeric($this->parentBranch)) {
$branch = $this->parentBranch;
}
return $branch;
}

Expand Down
4 changes: 4 additions & 0 deletions tests/JobCreatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ public function provideGetInstallerVersion(): array
['myaccount/silverstripe-tagfield', 'pulls/burger/myfeature', $latest],
['myaccount/silverstripe-tagfield', '2-release', $latest],
['myaccount/silverstripe-tagfield', '2.9-release', $latest],
// hardcoded repo version
['myaccount/silverstripe-session-manager', '1', $latest],
['myaccount/silverstripe-session-manager', '1.2', '4.10.x-dev'],
['myaccount/silverstripe-session-manager', 'burger', $latest],
];
}

Expand Down

0 comments on commit 08e6b3b

Please sign in to comment.