From c94e4294df6d610c718023266f559c94ae788aae Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Wed, 12 Jun 2024 18:08:41 +1200 Subject: [PATCH] NEW Remove supported badge from unsupported modules --- README.md | 5 ++++- funcs_utils.php | 18 ++++++++++++++++++ run.php | 7 +++++++ scripts/cms-unsupported/readme.php | 8 ++++++++ update_command.php | 16 ++++++++++++++-- 5 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 scripts/cms-unsupported/readme.php diff --git a/README.md b/README.md index af2f1c3..5656c62 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,8 @@ relevant branch e.g. `5` will be used depending on the command-line `--branch` o It will run all scripts in the `scripts/any` folder and then run all scripts in the applicable `scripts/` folder depending on the command-line `--branch` option that's passed in. +If the `--unsupported` option is used then it will only run scripts in the `scripts/cms-unsupported` folder. + This tool can also be used to standardise GitHub labels on all supported repositories. ## GitHub Token @@ -54,9 +56,10 @@ MS_GITHUB_TOKEN=abc123 php run.php update --cms-major=5 --branch=next-minor --dr | --dry-run | Do not push to github or create pull-requests | | --account | GitHub account to use for creating pull-requests (default: creative-commoners) | | --no-delete | Do not delete `_data` and `_modules` directories before running | +| --unsupported | Only update unsupported modules that were supported in the previous CMS major. Must also use `--branch=default-branch`. Can not be used with `--cms-major` option. | | --update-prs | Update existing open PRs instead of creating new PRs | -**Note** that using `--branch=github-default` will only run scripts in the `scripts/default-branch` directory. +**Note** that using `--branch=github-default` will only run scripts in the `scripts/default-branch` directory, unless the `--unsupported` flag is also used in which case it will use `scripts/cms-unsupported`. ### GitHub API secondary rate limit diff --git a/funcs_utils.php b/funcs_utils.php index edccfa6..ce18529 100644 --- a/funcs_utils.php +++ b/funcs_utils.php @@ -380,6 +380,24 @@ function filtered_modules($cmsMajor, $input) $cmsMajor === MetaData::HIGHEST_STABLE_CMS_MAJOR ); + if ($input->getOption('unsupported')) { + $prevCmsMajor = $cmsMajor - 1; + $prevCmsRepos = MetaData::removeReposNotInCmsMajor( + MetaData::getAllRepositoryMetaData(false), + $prevCmsMajor, + false + ); + $repoGithubs = array_map(fn($repo) => $repo['github'], $repos); + $unsupportedRepos = []; + foreach ($prevCmsRepos as $prevCmsRepo) { + if (in_array($prevCmsRepo['github'], $repoGithubs)) { + continue; + } + $unsupportedRepos[] = $prevCmsRepo; + } + $repos = $unsupportedRepos; + } + $modules = convert_repos_data_to_modules($repos); if ($input->getOption('only')) { diff --git a/run.php b/run.php index 1222dc0..03f83c5 100644 --- a/run.php +++ b/run.php @@ -80,6 +80,12 @@ InputOption::VALUE_NONE, 'Do not delete _data and _modules directories before running' ]; +$optionUnsupported = [ + 'unsupported', + null, + InputOption::VALUE_NONE, + 'Only update unsupported modules that were supported in the previous CMS major. Must also use --branch=default-branch. Can not be used with --cms-major option.' +]; $optionUpdatePrs = [ 'update-prs', null, @@ -98,6 +104,7 @@ ->addOption(...$optionDryRun) ->addOption(...$optionAccount) ->addOption(...$optionNoDelete) + ->addOption(...$optionUnsupported) ->addOption(...$optionUpdatePrs) ->setCode($updateCommand); diff --git a/scripts/cms-unsupported/readme.php b/scripts/cms-unsupported/readme.php new file mode 100644 index 0000000..8775a85 --- /dev/null +++ b/scripts/cms-unsupported/readme.php @@ -0,0 +1,8 @@ +getOption('unsupported') && $input->getOption('branch') !== 'github-default') { + error('The --unsupported option must be used with --branch=github-default'); + } + + // unsupported option must not be used with cms-major option + if ($input->getOption('unsupported') && $input->getOption('cms-major')) { + error('The --unsupported option must not be used with the --cms-major option'); + } + // branch $branchOption = $input->getOption('branch') ?: DEFAULT_BRANCH; if (!in_array($branchOption, BRANCH_OPTIONS)) { @@ -31,7 +41,9 @@ $modules = filtered_modules($cmsMajor, $input); // script files - if ($branchOption === 'github-default') { + if ($input->getOption('unsupported')) { + $scriptFiles = script_files('unsupported'); + } elseif ($branchOption === 'github-default') { $scriptFiles = script_files('default-branch'); } else { $scriptFiles = array_merge( @@ -66,7 +78,7 @@ } cmd("git remote add pr-remote $prOrigin", $MODULE_DIR); - $useDefaultBranch = has_wildcard_major_version_mapping(); + $useDefaultBranch = has_wildcard_major_version_mapping() || $branchOption === 'github-default'; if ($input->getOption('update-prs')) { // checkout latest existing pr branch