Skip to content

Commit

Permalink
ENH Automatically create hardcoded list
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Jul 19, 2022
1 parent 6ece91b commit 1a5b5b8
Show file tree
Hide file tree
Showing 5 changed files with 188 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.phpunit.result.cache
.cow.pat.json
125 changes: 123 additions & 2 deletions consts.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,133 @@
],
];

// 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 = [
'4.10' => [
'silverstripe-html5' => '2.3',
'comment-notifications' => '2.2',
'cwp' => '2.9',
'cwp-agencyextensions' => '2.6',
'cwp-core' => '2.9',
'cwp-pdfexport' => '1.3',
'cwp-search' => '1.6',
'cwp-starter-theme' => '3.2',
'cwp-watea-theme' => '3.1',
'silverstripe-advancedworkflow' => '5.6',
'silverstripe-akismet' => '4.2',
'silverstripe-auditor' => '2.4',
'silverstripe-blog' => '3.9',
'silverstripe-ckan-registry' => '1.4',
'silverstripe-comments' => '3.7',
'silverstripe-composer-update-checker' => '2.1',
'silverstripe-config' => '1.3',
'silverstripe-content-widget' => '2.3',
'silverstripe-contentreview' => '4.4',
'silverstripe-crontask' => '2.4',
'silverstripe-documentconverter' => '2.2',
'silverstripe-elemental' => '4.8',
'silverstripe-elemental-bannerblock' => '2.4',
'silverstripe-elemental-fileblock' => '2.3',
'silverstripe-elemental-userforms' => '3.1',
'silverstripe-environmentcheck' => '2.4',
'silverstripe-externallinks' => '2.2',
'silverstripe-fluent' => '4.6',
'silverstripe-fulltextsearch' => '3.9',
'silverstripe-graphql' => '3.7',
'silverstripe-gridfieldqueuedexport' => '2.6',
'silverstripe-html5' => ['2.2', '2.3'],
'silverstripe-hybridsessions' => '2.4',
'silverstripe-iframe' => '2.2',
'silverstripe-ldap' => '1.3',
'silverstripe-login-forms' => '4.6',
'silverstripe-maintenance' => '2.4',
'silverstripe-mfa' => '4.5',
'silverstripe-mimevalidator' => '2.3',
'silverstripe-multivaluefield' => '5.2',
'silverstripe-queuedjobs' => '4.9',
'silverstripe-realme' => '4.2',
'silverstripe-registry' => '2.4',
'silverstripe-restfulserver' => '2.4',
'silverstripe-security-extensions' => '4.2',
'silverstripe-securityreport' => '2.4',
'silverstripe-segment-field' => '2.5',
'silverstripe-session-manager' => '1.2',
'silverstripe-userforms' => '5.12',
'silverstripe-sharedraftcontent' => '2.6',
'silverstripe-sitewidecontent-report' => '3.2',
'silverstripe-spamprotection' => '3.2',
'silverstripe-spellcheck' => '2.3',
'silverstripe-subsites' => '2.5',
'silverstripe-tagfield' => '2.8',
'silverstripe-taxonomy' => '2.3',
'silverstripe-textextraction' => '3.3',
'silverstripe-totp-authenticator' => '4.3',
'silverstripe-userforms' => ['5.11', '5.12'],
'silverstripe-versionfeed' => '2.2',
'silverstripe-webauthn-authenticator' => '4.4',
'silverstripe-widgets' => '2.2',
'silverstripe-gridfieldextensions' => '3.3',
],
'4.11' => [
'comment-notifications' => '2.3',
'cwp' => '2.10',
'cwp-agencyextensions' => '2.7',
'cwp-core' => ['2.10', '2.11'],
'cwp-pdfexport' => '1.4',
'cwp-search' => '1.7',
'cwp-starter-theme' => '3.2',
'cwp-watea-theme' => '3.1',
'silverstripe-advancedworkflow' => '5.7',
'silverstripe-akismet' => '4.3',
'silverstripe-auditor' => '2.5',
'silverstripe-blog' => '3.10',
'silverstripe-ckan-registry' => '1.5',
'silverstripe-comments' => '3.8',
'silverstripe-composer-update-checker' => '3.0',
'silverstripe-config' => '1.4',
'silverstripe-content-widget' => '2.4',
'silverstripe-contentreview' => '4.5',
'silverstripe-crontask' => '2.5',
'silverstripe-documentconverter' => '2.3',
'silverstripe-elemental' => '4.9',
'silverstripe-elemental-bannerblock' => '2.5',
'silverstripe-elemental-fileblock' => '2.4',
'silverstripe-elemental-userforms' => '3.2',
'silverstripe-environmentcheck' => '2.5',
'silverstripe-externallinks' => '2.3',
'silverstripe-fluent' => '4.7',
'silverstripe-fulltextsearch' => '3.11',
'silverstripe-graphql' => '4.0',
'silverstripe-gridfieldqueuedexport' => '2.7',
'silverstripe-html5' => '2.4',
'silverstripe-hybridsessions' => '2.5',
'silverstripe-iframe' => '2.3',
'silverstripe-ldap' => '1.4',
'silverstripe-login-forms' => '4.7',
'silverstripe-maintenance' => '2.6',
'silverstripe-mfa' => '4.6',
'silverstripe-mimevalidator' => '2.4',
'silverstripe-multivaluefield' => '5.3',
'silverstripe-queuedjobs' => '4.10',
'silverstripe-realme' => '4.3',
'silverstripe-registry' => '2.5',
'silverstripe-restfulserver' => '2.5',
'silverstripe-security-extensions' => '4.3',
'silverstripe-securityreport' => '2.5',
'silverstripe-segment-field' => '2.6',
'silverstripe-session-manager' => '1.3',
'silverstripe-sharedraftcontent' => '2.7',
'silverstripe-sitewidecontent-report' => '3.3',
'silverstripe-spamprotection' => '3.3',
'silverstripe-spellcheck' => '2.4',
'silverstripe-subsites' => '2.6',
'silverstripe-tagfield' => '2.9',
'silverstripe-taxonomy' => '2.4',
'silverstripe-textextraction' => '3.4',
'silverstripe-totp-authenticator' => '4.4',
'silverstripe-userforms' => '5.13',
'silverstripe-versionfeed' => '2.3',
'silverstripe-webauthn-authenticator' => '4.5',
'silverstripe-widgets' => '2.3',
'silverstripe-gridfieldextensions' => '3.4',
]
];
52 changes: 52 additions & 0 deletions hardcoded.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

// Used to generate data for consts.php INSTALLER_TO_REPO_MINOR_VERSIONS
// Copy .cow.pat.json from the current release into the directory this script is being run from (file is .gitignored)

include 'consts.php';

$filename = '.cow.pat.json';
if (!file_exists($filename)) {
throw new \RuntimeException("Copy $filename into the directory this is being called from");
}

$versions = [];

function repoName(string $name)
{
$prefix = '';
if (!preg_match('#^(cwp/)#', $name) &&
!preg_match('#(/recipe-|/silverstripe-|/comment-notifications$)#', $name)
) {
$prefix = 'silverstripe-';
}
if (preg_match('#(/agency-extensions|/starter-theme|/watea-theme)$#', $name)) {
$prefix = 'cwp-';
}
$name = preg_replace('#/agency-extensions$#', '/agencyextensions', $name);
return $prefix . explode('/', $name)[1];
}

function parseNode(string $name, stdClass $node, array &$versions)
{
$repoName = repoName($name);
if (!in_array($repoName, LOCKSTEPPED_REPOS) &&
!in_array($repoName, NO_INSTALLER_LOCKSTEPPED_REPOS) &&
!in_array($repoName, NO_INSTALLER_UNLOCKSTEPPED_REPOS)
) {
preg_match('#^([0-9]+\.[0-9]+)#', $node->Version, $m);
$versions[$repoName] = $m[1];
}
foreach ((array) $node->Items as $itemName => $item) {
parseNode($itemName, $item, $versions);
}
}

foreach (json_decode(file_get_contents($filename)) as $itemName => $item) {
parseNode($itemName, $item, $versions);
}

ksort($versions);
foreach ($versions as $repoName => $version) {
echo " '$repoName' => '$version',\n";
}
9 changes: 6 additions & 3 deletions job_creator.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,12 @@ public function getInstallerVersion(): string
}
// hardcoded installer version for repo version
foreach (array_keys(INSTALLER_TO_REPO_MINOR_VERSIONS) as $installerVersion) {
foreach (INSTALLER_TO_REPO_MINOR_VERSIONS[$installerVersion] as $_repo => $repoVersion) {
if ($repo === $_repo && $repoVersion === $branch) {
return $installerVersion . '.x-dev';
foreach (INSTALLER_TO_REPO_MINOR_VERSIONS[$installerVersion] as $_repo => $_repoVersions) {
$repoVersions = is_array($_repoVersions) ? $_repoVersions : [$_repoVersions];
foreach ($repoVersions as $repoVersion) {
if ($repo === $_repo && $repoVersion === $branch) {
return $installerVersion . '.x-dev';
}
}
}
}
Expand Down
9 changes: 6 additions & 3 deletions tests/JobCreatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ public function provideGetInstallerVersion(): array
['myaccount/silverstripe-session-manager', '1', $latest],
['myaccount/silverstripe-session-manager', '1.2', '4.10.x-dev'],
['myaccount/silverstripe-session-manager', 'burger', $latest],
// hardcoded repo version using array
['myaccount/silverstripe-html5', '2', $latest],
['myaccount/silverstripe-html5', '2.2', '4.10.x-dev'],
['myaccount/silverstripe-html5', '2.3', '4.10.x-dev'],
['myaccount/silverstripe-html5', '2.4', '4.11.x-dev'],
['myaccount/silverstripe-html5', 'burger', $latest],
];
}

Expand Down Expand Up @@ -396,9 +402,6 @@ public function testGetPhpVersion($composerPhpConstraint, $expectedPhps): void
// framework 4.10.x-dev which creates php 7.3 jobs, this is so that this unit test
// keeps working as we increment the latest version of installer
$repo = 'silverstripe-elemental-bannerblock';
// use a hardcoded entry from INSTALLER_TO_REPO_MINOR_VERSIONS so that we get
// framework 4.10.x-dev which creates php 7.3 jobs, this is so that this unit test
// keeps working as we increment the latest version of installer
$minorVersion = '2.4';
if (INSTALLER_TO_REPO_MINOR_VERSIONS['4.10'][$repo] != $minorVersion) {
throw new Exception('Required const is missing for unit testing');
Expand Down

0 comments on commit 1a5b5b8

Please sign in to comment.