diff --git a/consts.php b/consts.php index 4c226b2..cd252c1 100644 --- a/consts.php +++ b/consts.php @@ -27,6 +27,10 @@ '8.1', '8.2', ], + '5.1' => [ + '8.1', + '8.2', + ], '5' => [ '8.1', '8.2', @@ -59,6 +63,17 @@ 'recipe-blog', ]; +// lockstepped repos that are "three less" e.g. silverstripe/admin 1 is for CMS 4 +const LOCKSTEPPED_REPOS_VERSION_IS_THREE_LESS = [ + 'silverstripe-admin', + 'silverstripe-asset-admin', + 'silverstripe-assets', + 'silverstripe-campaign-admin', + 'silverstripe-errorpage', + 'silverstripe-versioned', + 'silverstripe-versioned-admin', +]; + // Repositories that do not require silverstripe/installer to be explicitly added as a dependency for testing const NO_INSTALLER_LOCKSTEPPED_REPOS = [ // these are/include recipe-cms or recipe-core, so we don't want to composer require installer diff --git a/job_creator.php b/job_creator.php index 2620e15..d1e5c6f 100644 --- a/job_creator.php +++ b/job_creator.php @@ -56,6 +56,25 @@ public function getInstallerVersion(): string } } } + // has a lockstepped .x-dev requirement in composer.json + if (file_exists($this->composerJsonPath)) { + $json = json_decode(file_get_contents($this->composerJsonPath)); + foreach (LOCKSTEPPED_REPOS as $lockedSteppedRepo) { + $composerRepo = 'silverstripe/' . str_replace('silverstripe-', '', $lockedSteppedRepo); + if (isset($json->require->{$composerRepo})) { + $version = $json->require->{$composerRepo}; + if (preg_match('#^([0-9\.]+)\.x\-dev$#', $version, $matches)) { + $versionNumber = $matches[1]; + // If the lockstepped dependency is "three less" (e.g. silverstripe/admin is 3 major + // versions behind silverstripe/installer), account for that here. + if (in_array($lockedSteppedRepo, LOCKSTEPPED_REPOS_VERSION_IS_THREE_LESS)) { + $versionNumber += 3; + } + return $versionNumber . '.x-dev'; + } + } + } + } // 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); diff --git a/tests/JobCreatorTest.php b/tests/JobCreatorTest.php index e4c4247..d26336d 100644 --- a/tests/JobCreatorTest.php +++ b/tests/JobCreatorTest.php @@ -673,11 +673,11 @@ public function provideGetInstallerVersionCMS5FromComposer(): array ['myaccount/silverstripe-framework', '5', [], '5.x-dev'], ['myaccount/silverstripe-framework', '5.10', [], '5.10.x-dev'], // fallback to looking at deps in composer.json, use current minor of installer .x-dev - ['myaccount/silverstripe-admin', 'mybranch', ['silverstripe/framework' => '5.x-dev'], '5.0.x-dev'], + ['myaccount/silverstripe-admin', 'mybranch', ['silverstripe/framework' => '5.x-dev'], '5.x-dev'], ['myaccount/silverstripe-admin', 'mybranch', ['silverstripe/framework' => '5.0.x-dev'], '5.0.x-dev'], - ['myaccount/silverstripe-admin', 'mybranch', ['silverstripe/framework' => '^5'], '5.0.x-dev'], - ['myaccount/silverstripe-somemodule', 'mybranch', ['silverstripe/cms' => '^5'], '5.0.x-dev'], - ['myaccount/silverstripe-somemodule', 'mybranch', ['silverstripe/admin' => '^2'], '5.0.x-dev'], + ['myaccount/silverstripe-admin', 'mybranch', ['silverstripe/framework' => '^5'], '5.1.x-dev'], + ['myaccount/silverstripe-somemodule', 'mybranch', ['silverstripe/cms' => '^5'], '5.1.x-dev'], + ['myaccount/silverstripe-somemodule', 'mybranch', ['silverstripe/admin' => '^2'], '5.1.x-dev'], ['myaccount/silverstripe-somemodule', '3', ['silverstripe/framework' => '^5'], '5.x-dev'], ]; }