Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX Move parent branch logic #13

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 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,7 @@ 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';
}
// 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 @@ -117,6 +114,14 @@ private function getCleanedBranch(): string
if (preg_match('#^pulls/([0-9\.]+)/#', $branch, $matches)) {
$branch = $matches[1];
}
// fallback to parent branch if available
if (
!is_numeric($branch) &&
$this->parentBranch &&
(is_numeric($this->parentBranch) || preg_match('#^[0-9\.]+-release$#', $this->parentBranch))
) {
$branch = $this->parentBranch;
}
// e.g. 4.10-release
$branch = preg_replace('#^([0-9\.]+)-release$#', '$1', $branch);
return $branch;
Expand Down
11 changes: 11 additions & 0 deletions tests/JobCreatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,17 @@ public function provideParentBranch(): array
]),
'4.10.x-dev'
],
[
implode("\n", [
$this->getGenericYml(),
<<<EOT
github_repository: 'myaccount/silverstripe-versioned'
github_my_ref: 'myaccount-patch-1'
parent_branch: '4.10-release'
EOT
]),
'4.10.x-dev'
],
[
implode("\n", [
$this->getGenericYml(),
Expand Down