Skip to content

Commit

Permalink
NEW Start with lowest installer version for --prefer-lowest
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Jul 2, 2024
1 parent 350589f commit bca9ab8
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 2 deletions.
31 changes: 31 additions & 0 deletions consts.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
16 changes: 15 additions & 1 deletion job_creator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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-core 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,
Expand Down
33 changes: 32 additions & 1 deletion tests/JobCreatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,37 @@

class JobCreatorTest extends TestCase
{
public function provideCreateJobPreferLowest(): array
{
return [
'installer-module' => [
'ghrepo' => 'silverstripe/silverstripe-framework',
'expected' => '5.x-dev',
],
'non-installer-module' => [
'ghrepo' => 'dnadesign/silverstripe-elemental',
'expected' => '5.0.x-dev',
],
];
}

/**
* @dataProvider provideCreateJobPreferLowest
*/
public function testCreateJobPreferLowest(string $ghrepo, string $expected): void
{
$installerVersionProperty = new ReflectionProperty(JobCreator::class, 'installerVersion');
$installerVersionProperty->setAccessible(true);
$creator = new JobCreator();
$installerVersionProperty->setValue($creator, '5.x-dev');
$creator->githubRepository = $ghrepo;
$creator->repoName = explode('/', $ghrepo)[1];
$creator->branch = '5';
$creator->parseRepositoryMetadata();
$actual = $creator->createJob(0, ['composer_args' => '--prefer-lowest'])['installer_version'];
$this->assertSame($expected, $actual);
}

/**
* @dataProvider provideCreateJob
*/
Expand Down Expand Up @@ -962,7 +993,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');
Expand Down
6 changes: 6 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
<?php
$autoloadPath = __DIR__ . '/../vendor/autoload.php';
if (!file_exists($autoloadPath)) {
throw new RuntimeException('Run composer install first');
}
require_once $autoloadPath;

// working directory will be root
include 'consts.php';
include 'job_creator.php';

0 comments on commit bca9ab8

Please sign in to comment.