Skip to content

Commit

Permalink
ENH Don't include installer if it's not needed
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed Jan 26, 2024
1 parent 0e30080 commit 03f3142
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 17 deletions.
5 changes: 0 additions & 5 deletions consts.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,7 @@
];

const NO_INSTALLER_UNLOCKSTEPPED_REPOS = [
'vendor-plugin',
'recipe-plugin',
'api.silverstripe.org',
'cow',
'silverstripe-config',
'markdown-php-codesniffer',
];

const CMS_TO_REPO_MAJOR_VERSIONS = [
Expand Down
13 changes: 12 additions & 1 deletion job_creator.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,20 @@ 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));
// We shouldn't try to infer the installer version for regular repositories
// that weren't already detected via the const-based logic above
$silverstripeRepoTypes = [
'silverstripe-vendormodule',
'silverstripe-module',
'silverstripe-recipe',
'silverstripe-theme',
];
if (!isset($json->type) || !in_array($json->type, $silverstripeRepoTypes)) {
return '';
}
// has a lockstepped .x-dev requirement in composer.json
foreach (LOCKSTEPPED_REPOS as $lockedSteppedRepo) {
$composerRepo = 'silverstripe/' . str_replace('silverstripe-', '', $lockedSteppedRepo);
if (isset($json->require->{$composerRepo})) {
Expand Down
69 changes: 58 additions & 11 deletions tests/JobCreatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,7 @@ public function testGetInstallerVersionCMS5FromComposer(
string $githubRepository,
string $branch,
array $composerDeps,
string $repoType,
string $expected
): void {
if (!function_exists('yaml_parse')) {
Expand All @@ -778,6 +779,9 @@ public function testGetInstallerVersionCMS5FromComposer(
$creator = new JobCreator();
$creator->composerJsonPath = '__composer.json';
$composer = new stdClass();
if ($repoType) {
$composer->type = $repoType;
}
$composer->require = new stdClass();
foreach ($composerDeps as $dep => $version) {
$composer->require->{$dep} = $version;
Expand All @@ -795,18 +799,21 @@ public function provideGetInstallerVersionCMS5FromComposer(): array
$currentMinor = $this->getCurrentMinorInstallerVersion('4') . '.x-dev';
return [
// priority given to branch name
['myaccount/silverstripe-framework', '4', [], '4.x-dev'],
['myaccount/silverstripe-framework', '4.10', [], '4.10.x-dev'],
['myaccount/silverstripe-framework', 'burger', [], $currentMinor],
['myaccount/silverstripe-framework', '5', [], '5.x-dev'],
['myaccount/silverstripe-framework', '5.10', [], '5.10.x-dev'],
['myaccount/silverstripe-framework', '4', [], 'silverstripe-module', '4.x-dev'],
['myaccount/silverstripe-framework', '4.10', [], 'silverstripe-vendormodule', '4.10.x-dev'],
['myaccount/silverstripe-framework', 'burger', [], 'silverstripe-theme', $currentMinor],
['myaccount/silverstripe-framework', '5', [], 'silverstripe-recipe', '5.x-dev'],
['myaccount/silverstripe-framework', '5.10', [], 'silverstripe-vendormodule', '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.x-dev'],
['myaccount/silverstripe-admin', 'mybranch', ['silverstripe/framework' => '5.0.x-dev'], '5.0.x-dev'],
['myaccount/silverstripe-admin', 'mybranch', ['silverstripe/framework' => '^5'], '5.2.x-dev'],
['myaccount/silverstripe-somemodule', 'mybranch', ['silverstripe/cms' => '^5'], '5.2.x-dev'],
['myaccount/silverstripe-somemodule', 'mybranch', ['silverstripe/admin' => '^2'], '5.2.x-dev'],
['myaccount/silverstripe-somemodule', '3', ['silverstripe/framework' => '^5'], '5.x-dev'],
['myaccount/silverstripe-admin', 'mybranch', ['silverstripe/framework' => '5.x-dev'], 'silverstripe-module', '5.x-dev'],
['myaccount/silverstripe-admin', 'mybranch', ['silverstripe/framework' => '5.0.x-dev'], 'silverstripe-vendormodule', '5.0.x-dev'],
['myaccount/silverstripe-admin', 'mybranch', ['silverstripe/framework' => '^5'], 'silverstripe-theme', '5.2.x-dev'],
['myaccount/silverstripe-somemodule', 'mybranch', ['silverstripe/cms' => '^5'], 'silverstripe-recipe', '5.2.x-dev'],
['myaccount/silverstripe-somemodule', 'mybranch', ['silverstripe/admin' => '^2'], 'silverstripe-vendormodule', '5.2.x-dev'],
['myaccount/silverstripe-somemodule', '3', ['silverstripe/framework' => '^5'], 'silverstripe-vendormodule', '5.x-dev'],
['myaccount/silverstripe-somemodule', '3', ['silverstripe/framework' => '^5'], 'package', ''],
['myaccount/silverstripe-somemodule', '3', ['silverstripe/framework' => '^5'], '', ''],
['myaccount/silverstripe-somemodule', '3', [], '', ''],
];
}

Expand All @@ -817,6 +824,7 @@ public function testComposerInstall(
string $composerInstall,
string $configPlatformPhp,
string $frameworkVersion,
string $repoType,
array $expected
): void {
$yml = implode("\n", [
Expand All @@ -830,6 +838,9 @@ public function testComposerInstall(
$creator = new JobCreator();
$creator->composerJsonPath = '__composer.json';
$composer = new stdClass();
if ($repoType) {
$composer->type = $repoType;
}
$composer->require = new stdClass();
$composer->require->{'silverstripe/framework'} = $frameworkVersion;
if ($configPlatformPhp) {
Expand All @@ -855,6 +866,7 @@ public function provideComposerInstall(): array
'true',
'',
'4.x-dev',
'silverstripe-module',
[
'7.4 mysql57 phpunit all'
]
Expand All @@ -863,6 +875,7 @@ public function provideComposerInstall(): array
'true',
'',
'5.x-dev',
'silverstripe-vendormodule',
[
'8.1 mysql57 phpunit all'
]
Expand All @@ -871,6 +884,7 @@ public function provideComposerInstall(): array
'true',
'21.99',
'5.x-dev',
'silverstripe-recipe',
[
'21.99 mysql57 phpunit all'
]
Expand All @@ -879,6 +893,7 @@ public function provideComposerInstall(): array
'true',
'fish',
'5.x-dev',
'silverstripe-theme',
[
'8.1 mysql57 phpunit all'
]
Expand All @@ -887,6 +902,7 @@ public function provideComposerInstall(): array
'false',
'',
'4.x-dev',
'silverstripe-module',
[
'7.4 prf-low mysql57 phpunit all',
'8.0 mysql57pdo phpunit all',
Expand All @@ -897,6 +913,7 @@ public function provideComposerInstall(): array
'false',
'',
'5.x-dev',
'silverstripe-vendormodule',
[
'8.1 prf-low mysql57 phpunit all',
'8.2 mariadb phpunit all',
Expand All @@ -907,6 +924,7 @@ public function provideComposerInstall(): array
'false',
'21.99',
'5.x-dev',
'silverstripe-recipe',
[
'8.1 prf-low mysql57 phpunit all',
'8.2 mariadb phpunit all',
Expand All @@ -917,6 +935,7 @@ public function provideComposerInstall(): array
'false',
'fish',
'5.x-dev',
'silverstripe-theme',
[
'8.1 prf-low mysql57 phpunit all',
'8.2 mariadb phpunit all',
Expand All @@ -927,6 +946,7 @@ public function provideComposerInstall(): array
'false',
'',
'5.1.x-dev',
'silverstripe-module',
[
'8.1 prf-low mysql57 phpunit all',
'8.1 mariadb phpunit all',
Expand All @@ -937,6 +957,7 @@ public function provideComposerInstall(): array
'false',
'21.99',
'5.1.x-dev',
'silverstripe-vendormodule',
[
'8.1 prf-low mysql57 phpunit all',
'8.1 mariadb phpunit all',
Expand All @@ -947,6 +968,7 @@ public function provideComposerInstall(): array
'false',
'fish',
'5.1.x-dev',
'silverstripe-recipe',
[
'8.1 prf-low mysql57 phpunit all',
'8.1 mariadb phpunit all',
Expand All @@ -957,6 +979,7 @@ public function provideComposerInstall(): array
'false',
'',
'5.2.x-dev',
'silverstripe-theme',
[
'8.1 prf-low mysql57 phpunit all',
'8.2 mariadb phpunit all',
Expand All @@ -967,6 +990,7 @@ public function provideComposerInstall(): array
'false',
'21.99',
'5.2.x-dev',
'silverstripe-module',
[
'8.1 prf-low mysql57 phpunit all',
'8.2 mariadb phpunit all',
Expand All @@ -977,12 +1001,35 @@ public function provideComposerInstall(): array
'false',
'fish',
'5.2.x-dev',
'silverstripe-vendormodule',
[
'8.1 prf-low mysql57 phpunit all',
'8.2 mariadb phpunit all',
'8.3 mysql80 phpunit all',
]
],
'composerupgrade_invalidphpversion_notmodule1' => [
'false',
'fish',
'*',
'package',
[
'7.4 prf-low mysql57 phpunit all',
'8.0 mysql57pdo phpunit all',
'8.1 mysql80 phpunit all',
]
],
'composerupgrade_invalidphpversion_notmodule2' => [
'false',
'fish',
'*',
'',
[
'7.4 prf-low mysql57 phpunit all',
'8.0 mysql57pdo phpunit all',
'8.1 mysql80 phpunit all',
]
],
];
}
}

0 comments on commit 03f3142

Please sign in to comment.