From 48cc7981d0c8fb669542038a2023db8fceb86a46 Mon Sep 17 00:00:00 2001 From: Guy Sartorelli Date: Wed, 8 May 2024 14:31:52 +1200 Subject: [PATCH] ENH Update reference to supported modules data --- README.md | 2 +- composer.json | 1 + composer.lock | 126 +++++++++++++++++++++++++++++++- src/Console/CheckoutCommand.php | 60 ++++++++++++--- 4 files changed, 175 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 9c5850d..82f91de 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ generated through [Doctum](https://github.com/code-lts/doctum#readme). ### Add a new major ersion * Add a new version in the `'versions'` key in `conf/doctum.json` - * Make sure https://github.com/silverstripe/supported-modules has been updated with a new branch for the new major version with correct branch mapping + * Make sure https://github.com/silverstripe/supported-modules has been updated with correct branch mapping * Run `makedoc.sh` and confirm the generation runs through properly * Make a commit of the updated `conf/doctum.json` * Update the redirections in `.htaccess` to the stable version number (if releasing a new stable major version) diff --git a/composer.json b/composer.json index 59f08ac..3535ab5 100644 --- a/composer.json +++ b/composer.json @@ -11,6 +11,7 @@ "require": { "php": "^8.1", "gitonomy/gitlib": "^1.2", + "silverstripe/supported-modules": "dev-main", "symfony/console": "^6.2", "code-lts/doctum": "^5.5.3", "psr/log": "^3.0" diff --git a/composer.lock b/composer.lock index e5016bb..907ea03 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "1acd24aa6f37e026e363914584f105fb", + "content-hash": "6bfa2a42e9b2502dc71055873af9daa2", "packages": [ { "name": "code-lts/cli-tools", @@ -156,6 +156,87 @@ ], "time": "2023-10-10T23:36:13+00:00" }, + { + "name": "composer/semver", + "version": "3.4.0", + "source": { + "type": "git", + "url": "https://github.com/composer/semver.git", + "reference": "35e8d0af4486141bc745f23a29cc2091eb624a32" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/composer/semver/zipball/35e8d0af4486141bc745f23a29cc2091eb624a32", + "reference": "35e8d0af4486141bc745f23a29cc2091eb624a32", + "shasum": "" + }, + "require": { + "php": "^5.3.2 || ^7.0 || ^8.0" + }, + "require-dev": { + "phpstan/phpstan": "^1.4", + "symfony/phpunit-bridge": "^4.2 || ^5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "3.x-dev" + } + }, + "autoload": { + "psr-4": { + "Composer\\Semver\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nils Adermann", + "email": "naderman@naderman.de", + "homepage": "http://www.naderman.de" + }, + { + "name": "Jordi Boggiano", + "email": "j.boggiano@seld.be", + "homepage": "http://seld.be" + }, + { + "name": "Rob Bast", + "email": "rob.bast@gmail.com", + "homepage": "http://robbast.nl" + } + ], + "description": "Semver library that offers utilities, version constraint parsing and validation.", + "keywords": [ + "semantic", + "semver", + "validation", + "versioning" + ], + "support": { + "irc": "ircs://irc.libera.chat:6697/composer", + "issues": "https://github.com/composer/semver/issues", + "source": "https://github.com/composer/semver/tree/3.4.0" + }, + "funding": [ + { + "url": "https://packagist.com", + "type": "custom" + }, + { + "url": "https://github.com/composer", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/composer/composer", + "type": "tidelift" + } + ], + "time": "2023-08-31T09:50:34+00:00" + }, { "name": "erusev/parsedown", "version": "1.7.4", @@ -739,6 +820,43 @@ }, "time": "2021-07-14T16:46:02+00:00" }, + { + "name": "silverstripe/supported-modules", + "version": "dev-main", + "source": { + "type": "git", + "url": "https://github.com/silverstripe/supported-modules.git", + "reference": "cde6b5514080138bcfbf0331b17c870c5a9cfa77" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/silverstripe/supported-modules/zipball/cde6b5514080138bcfbf0331b17c870c5a9cfa77", + "reference": "cde6b5514080138bcfbf0331b17c870c5a9cfa77", + "shasum": "" + }, + "require": { + "composer/semver": "^3.4", + "php": "^8.1" + }, + "require-dev": { + "phpunit/phpunit": "^9.6" + }, + "default-branch": true, + "type": "library", + "autoload": { + "psr-4": { + "SilverStripe\\SupportedModules\\": "src/", + "SilverStripe\\SupportedModules\\Tests\\": "tests/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "description": "Metadata about Silverstripe CMS supported modules and other repositories maintained by Silverstripe", + "support": { + "issues": "https://github.com/silverstripe/supported-modules/issues", + "source": "https://github.com/silverstripe/supported-modules/tree/main" + }, + "time": "2024-05-06T06:10:45+00:00" + }, { "name": "symfony/console", "version": "v6.3.4", @@ -3580,12 +3698,14 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": { + "silverstripe/supported-modules": 20 + }, "prefer-stable": false, "prefer-lowest": false, "platform": { "php": "^8.1" }, "platform-dev": [], - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.6.0" } diff --git a/src/Console/CheckoutCommand.php b/src/Console/CheckoutCommand.php index 3304168..1331cde 100644 --- a/src/Console/CheckoutCommand.php +++ b/src/Console/CheckoutCommand.php @@ -8,6 +8,7 @@ use RuntimeException; use SilverStripe\ApiDocs\Data\Config; use SilverStripe\ApiDocs\Data\RepoFactory; +use SilverStripe\SupportedModules\MetaData; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -17,6 +18,7 @@ class CheckoutCommand extends Command /** * Regex patterns for github repositories that should be ignored. * These are repositories that don't have relevant API. + * The patterns are matched against the packagist name for the module. */ private array $ignoreModulePatterns = [ '/^silverstripe\/developer-docs$/', @@ -162,21 +164,43 @@ private function buildVersionMap(array $config, OutputInterface $output) $map = []; $versions = array_keys($config['versions']); - foreach ($versions as $version) { - $modulesUrl = "https://raw.githubusercontent.com/silverstripe/supported-modules/$version/modules.json"; + $repos = MetaData::getAllRepositoryMetaData()[MetaData::CATEGORY_SUPPORTED]; + foreach ($repos as $repo) { + if ($this->shouldIgnoreModule($repo)) { + continue; + } + $githubName = $repo['github']; + $moduleName = $repo['packagist']; + $versionMap = $repo['majorVersionMapping']; + // Remove mapping from any versions we don't care about, and make sure we only have one branch for each cms major + foreach ($versionMap as $cmsMajor => $branches) { + if (!in_array($cmsMajor, $versions)) { + unset($versionMap[$cmsMajor]); + continue; + } + $versionMap[$cmsMajor] = end($branches); + } + $map[$moduleName] = [ + 'repository' => "https://github.com/$githubName.git", + 'versionmap' => $versionMap, + ]; + } + + // CMS 3 isn't in the main branch of silverstripe/supported-modules - we have to use a legacy branch for that data. + if (in_array(3, $versions)) { + $modulesUrl = "https://raw.githubusercontent.com/silverstripe/supported-modules/3/modules.json"; $modulesJson = json_decode(file_get_contents($modulesUrl) ?: 'null', true); if ($modulesJson === null) { - throw new RuntimeException('Modules data could not be retrieved for version ' . $version); + throw new RuntimeException('Modules data could not be retrieved for version 3'); } foreach ($modulesJson as $module) { - $moduleName = $module['composer']; - - if ($this->shouldIgnoreModule($module)) { + if ($this->shouldIgnoreModuleLegacy($module, true)) { continue; } + $moduleName = $module['composer']; if (!array_key_exists($moduleName, $map)) { $githubName = $module['github']; $map[$moduleName] = [ @@ -187,14 +211,15 @@ private function buildVersionMap(array $config, OutputInterface $output) $branches = $module['branches']; sort($branches); - $map[$moduleName]['versionmap'][$version] = end($branches); + $map[$moduleName]['versionmap'][3] = end($branches); } } - foreach ($map as &$data) { + // Add a null entry for anything that's not supported for a given version + foreach ($map as $index => $data) { foreach ($versions as $version) { if (!isset($data['versionmap'][$version])) { - $data['versionmap'][$version] = null; + $map[$index]['versionmap'][$version] = null; } } } @@ -202,7 +227,7 @@ private function buildVersionMap(array $config, OutputInterface $output) return $map; } - private function shouldIgnoreModule(array $module) + private function shouldIgnoreModuleLegacy(array $module) { if ($module['type'] !== 'supported-module' || empty($module['branches'])) { return true; @@ -216,4 +241,19 @@ private function shouldIgnoreModule(array $module) return false; } + + private function shouldIgnoreModule(array $module) + { + if ($module['type'] === 'other' || empty($module['majorVersionMapping'])) { + return true; + } + + foreach ($this->ignoreModulePatterns as $regex) { + if (preg_match($regex, $module['packagist'])) { + return true; + } + } + + return false; + } }