Skip to content

Commit

Permalink
NEW Remove supported badge from unsupported modules
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Jun 12, 2024
1 parent da766e5 commit 6e19fac
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ 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`. |
| --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.
Expand Down
14 changes: 14 additions & 0 deletions funcs_scripts.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,20 @@ function module_is_recipe()
return ($json->type ?? '') === 'silverstripe-recipe';
}

/**
* Determine if the module being processed is supported for the current $CMS_MAJOR
*
* Example usage:
* module_is_supported()
*/
function module_is_supported()
{
global $GITHUB_REF, $CMS_MAJOR;
$repoMetaData = MetaData::getMetaDataForRepository($GITHUB_REF);
$metaData = MetaData::removeReposNotInCmsMajor([$repoMetaData], $CMS_MAJOR);
return count($metaData) > 0;
}

/**
* Determine if the repository being processed is an actual silverstripe module e.g. silverstripe-admin, not gha-*
*
Expand Down
18 changes: 18 additions & 0 deletions funcs_utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand Down
8 changes: 8 additions & 0 deletions run.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
const TAG_RULESET_NAME = 'Silverstripe CMS tag ruleset';

// global variables
$CMS_MAJOR = '';
$MODULE_DIR = '';
$GITHUB_REF = '';
$PRS_CREATED = [];
Expand Down Expand Up @@ -80,6 +81,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.'
];
$optionUpdatePrs = [
'update-prs',
null,
Expand All @@ -98,6 +105,7 @@
->addOption(...$optionDryRun)
->addOption(...$optionAccount)
->addOption(...$optionNoDelete)
->addOption(...$optionUnsupported)
->addOption(...$optionUpdatePrs)
->setCode($updateCommand);

Expand Down
8 changes: 8 additions & 0 deletions scripts/default-branch/readme.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

if (!module_is_supported() && file_exists('README.md')) {
$contents = read_file('README.md');
$rx = "#\n\[!\[Silverstripe supported module\].+?\n#s";
$contents = preg_replace($rx, "\n", $contents);
write_file_even_if_exists('README.md', $contents);
}
24 changes: 17 additions & 7 deletions update_command.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// This is the code that is executed when running the 'update' command

// variables
global $MODULE_DIR, $GITHUB_REF, $OUT, $PRS_CREATED, $REPOS_WITH_PRS_CREATED;
global $MODULE_DIR, $GITHUB_REF, $OUT, $PRS_CREATED, $REPOS_WITH_PRS_CREATED, $CMS_MAJOR;
$OUT = $output;

// validate system is ready
Expand All @@ -18,25 +18,35 @@
// setup directories
setup_directories($input);

// unsupported option must be used with github-default option
if ($input->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)) {
error(sprintf('Invalid branch option - must be one of: %s', implode('|', BRANCH_OPTIONS)));
}

// CMS major version to use
$cmsMajor = $input->getOption('cms-major') ?: MetaData::HIGHEST_STABLE_CMS_MAJOR;
$CMS_MAJOR = $input->getOption('cms-major') ?: MetaData::HIGHEST_STABLE_CMS_MAJOR;

// modules
$modules = filtered_modules($cmsMajor, $input);
$modules = filtered_modules($CMS_MAJOR, $input);

// script files
if ($branchOption === 'github-default') {
$scriptFiles = script_files('default-branch');
} else {
$scriptFiles = array_merge(
script_files('any'),
script_files($cmsMajor),
script_files($CMS_MAJOR),
);
}

Expand Down Expand Up @@ -131,7 +141,7 @@
$defaultBranch,
$currentBranch,
$currentBranchCmsMajor,
$cmsMajor,
$CMS_MAJOR,
$branchOption
);
}
Expand All @@ -142,8 +152,8 @@
cmd("git checkout $branchToCheckout", $MODULE_DIR);

// ensure that this branch actually supports the cmsMajor we're targetting
if (!$useDefaultBranch && $branchOption !== 'github-default' && current_branch_cms_major() !== $cmsMajor) {
error("Branch $branchToCheckout does not support CMS major version $cmsMajor");
if (!$useDefaultBranch && $branchOption !== 'github-default' && current_branch_cms_major() !== $CMS_MAJOR) {
error("Branch $branchToCheckout does not support CMS major version $CMS_MAJOR");
}

// create a new branch used for the pull-request
Expand Down

0 comments on commit 6e19fac

Please sign in to comment.