diff --git a/consts.php b/consts.php index 63d3a1c..5ac8585 100644 --- a/consts.php +++ b/consts.php @@ -23,6 +23,37 @@ 'recipe-blog', ]; +// list of modules that are required in either: +// - silverstripe/installer +// - silverstripe/recipe-cms +// - silverstripe/recipe-core +const INSTALLER_MODULES = [ + // installer + 'recipe-plugin', + 'vendor-plugin', + 'recipe-cms', + 'silverstripe-simple', + 'silverstripe-login-forms', + // recipe-cms + 'recipe-core', + 'silverstripe-admin', + 'silverstripe-asset-admin', + 'silverstripe-campaign-admin', + 'silverstripe-versioned-admin', + 'silverstripe-cms', + 'silverstripe-errorpage', + 'silverstripe-reports', + 'silverstripe-siteconfig', + 'silverstripe-versioned', + 'silverstripe-graphql', + 'silverstripe-session-manager', + // recipe-core + 'silverstripe-assets', + 'silverstripe-config', + 'silverstripe-framework', + 'silverstripe-mimevalidator', +]; + // use hardcoded.php to bulk update update this after creating a .cow.pat.json // for multiple versions, use an array e.g. silverstripe-mymodule => ['2.3', '2.4'] const INSTALLER_TO_REPO_MINOR_VERSIONS = [ diff --git a/job_creator.php b/job_creator.php index 686c550..77154ab 100644 --- a/job_creator.php +++ b/job_creator.php @@ -132,10 +132,24 @@ public function getInstallerVersion( public function createJob(int $phpIndex, array $opts): array { + $isInstallerModule = in_array($this->repoName, INSTALLER_MODULES); + $isPreferLoweset = strpos($opts['composer_args'] ?? '', '--prefer-lowest') !== false; + $installerVersion = $this->installerVersion; + $cmsMajor = BranchLogic::getCmsMajor($this->repoData, $this->branch, $this->getComposerJsonContent()); + if ($cmsMajor >= 5 && !$isInstallerModule && $isPreferLoweset && $installerVersion) { + // --prefer-lowest jobs should use the lowest installer version for non-installer modules + // gha-ci will increment the installer version higher if composer is unable to install + // and try installing again + // + // Was going to use something like 5.2.x-dev, install 5.0.x-dev instead + $installerVersion = preg_replace('#^([0-9])\.[0-9]\.x-dev$#', '$1.0.x-dev', $installerVersion); + // Was going to use something like 5.x-dev, install 5.0.x-dev instaed + $installerVersion = preg_replace('#^([0-9])\.x-dev$#', '$1.0.x-dev', $installerVersion); + } $default = [ # ensure there's a default value for all possible return keys # this allows us to use `if [[ "${{ matrix.key }}" == "true" ]]; then` in gha-ci/ci.yml - 'installer_version' => $this->installerVersion, + 'installer_version' => $installerVersion, 'php' => $this->getPhpVersion($phpIndex), 'parent_branch' => $this->parentBranch, 'db' => DB_MYSQL_57, diff --git a/tests/JobCreatorTest.php b/tests/JobCreatorTest.php index 844e054..9d1de4c 100644 --- a/tests/JobCreatorTest.php +++ b/tests/JobCreatorTest.php @@ -5,6 +5,49 @@ class JobCreatorTest extends TestCase { + public function provideCreateJobPreferLowest(): array + { + return [ + 'installer-module cms 4' => [ + 'branch' => '4', + 'ghrepo' => 'silverstripe/silverstripe-framework', + 'expected' => '4.x-dev', + ], + 'non-installer-module cms 4' => [ + 'branch' => '4', + 'ghrepo' => 'dnadesign/silverstripe-elemental', + 'expected' => '4.x-dev', + ], + 'installer-module cms 5' => [ + 'branch' => '5', + 'ghrepo' => 'silverstripe/silverstripe-framework', + 'expected' => '5.x-dev', + ], + 'non-installer-module cms 5' => [ + 'branch' => '5', + 'ghrepo' => 'dnadesign/silverstripe-elemental', + 'expected' => '5.0.x-dev', + ], + ]; + } + + /** + * @dataProvider provideCreateJobPreferLowest + */ + public function testCreateJobPreferLowest(string $branch, string $ghrepo, string $expected): void + { + $installerVersionProperty = new ReflectionProperty(JobCreator::class, 'installerVersion'); + $installerVersionProperty->setAccessible(true); + $creator = new JobCreator(); + $installerVersionProperty->setValue($creator, "$branch.x-dev"); + $creator->githubRepository = $ghrepo; + $creator->repoName = explode('/', $ghrepo)[1]; + $creator->branch = $branch; + $creator->parseRepositoryMetadata(); + $actual = $creator->createJob(0, ['composer_args' => '--prefer-lowest'])['installer_version']; + $this->assertSame($expected, $actual); + } + /** * @dataProvider provideCreateJob */ @@ -962,7 +1005,7 @@ public function testGetInstallerVersionFromComposer( $creator = new JobCreator(); $creator->composerJsonPath = '__composer.json'; $json = json_decode($creator->createJson($yml)); - $this->assertSame($expected, $json->include[0]->installer_version); + $this->assertSame($expected, $json->include[1]->installer_version); } finally { unlink('__composer.json'); unlink('__installer_branches.json'); diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 6832380..b946eb9 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,4 +1,10 @@