From edab86138c6faf476f607ffdc95a05cd3710f827 Mon Sep 17 00:00:00 2001 From: Guy Sartorelli Date: Thu, 1 Aug 2024 16:39:53 +1200 Subject: [PATCH 1/5] NEW Add option to run a single script --- README.md | 1 + run.php | 8 ++++++++ update_command.php | 4 ++++ 3 files changed, 13 insertions(+) diff --git a/README.md b/README.md index 135a61a..60aeb1d 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,7 @@ MS_GITHUB_TOKEN=abc123 php run.php update --cms-major=5 --branch=next-minor --dr | ---- | ------------| | --cms-major=[version] | The major version of CMS to use (default: 5) which determines the list of supported modules to use | | --branch=[type] | The branch type to use - `next-minor`\|`next-patch`\|`github-default` (default: `next-patch`) | +| --script=[scriptname] | Only run a specific script. This is the name of the script file without the file extension e.g. `tag-patch-release` | | --only=[modules] | Only include the specified modules (without account prefix) separated by commas e.g. `silverstripe-config,silverstripe-assets` | | --exclude=[modules] | Exclude the specified modules (without account prefix) separated by commas e.g. `silverstripe-mfa,silverstripe-totp` | | --dry-run | Do not push to github or create pull-requests | diff --git a/run.php b/run.php index 66ea3db..cd207df 100644 --- a/run.php +++ b/run.php @@ -48,6 +48,13 @@ InputOption::VALUE_REQUIRED, 'The branch type to use - ' . implode('|', BRANCH_OPTIONS) . ' (default: ' . DEFAULT_BRANCH . ')' ]; +$optionScript = [ + 'script', + null, + InputOption::VALUE_REQUIRED, + 'Only run a specific script. This is the name of the script file without the file extension ' + . 'e.g. tag-patch-release' +]; $optionOnly = [ 'only', null, @@ -99,6 +106,7 @@ ->setDescription('The main script of module-standardiser') ->addOption(...$optionCmsMajor) ->addOption(...$optionBranch) + ->addOption(...$optionScript) ->addOption(...$optionOnly) ->addOption(...$optionExclude) ->addOption(...$optionDryRun) diff --git a/update_command.php b/update_command.php index fc96f49..9068ebe 100644 --- a/update_command.php +++ b/update_command.php @@ -169,7 +169,11 @@ } // run scripts + $onlyThisScript = $input->getOption('script'); foreach ($scriptFiles as $scriptFile) { + if ($onlyThisScript && basename($scriptFile, '.php') !== $onlyThisScript) { + continue; + } $contents = file_get_contents($scriptFile); $contents = str_replace(' Date: Thu, 1 Aug 2024 16:40:40 +1200 Subject: [PATCH 2/5] FIX When upating PRs, redo the run entirely --- funcs_utils.php | 16 ++++++++++++++++ run.php | 1 + update_command.php | 30 ++++++++++++++++-------------- 3 files changed, 33 insertions(+), 14 deletions(-) diff --git a/funcs_utils.php b/funcs_utils.php index 9ad8d93..2c335bb 100644 --- a/funcs_utils.php +++ b/funcs_utils.php @@ -19,6 +19,7 @@ function error($message) { output_prs_created(); + output_repos_with_prs_to_close(); output_repos_with_prs_created(); io()->error($message); if (!running_unit_tests()) { @@ -227,6 +228,21 @@ function output_repos_with_prs_created() $io->writeln(''); } +function output_repos_with_prs_to_close() +{ + if (running_unit_tests()) { + return; + } + global $REPOS_WITH_PRS_TO_CLOSE; + $io = io(); + $io->writeln(''); + $io->writeln('Repos with pull requests that should be closed:'); + foreach ($REPOS_WITH_PRS_TO_CLOSE as $pr) { + $io->writeln("- $pr"); + } + $io->writeln(''); +} + /** * Outputs a list of repos that that had labels updated * If there was an error with a run (probably a secondary rate limit), this can be diff --git a/run.php b/run.php index cd207df..2e6e7be 100644 --- a/run.php +++ b/run.php @@ -33,6 +33,7 @@ $REPOS_WITH_PRS_CREATED = []; $REPOS_WITH_LABELS_UPDATED = []; $REPOS_WITH_RULESETS_UPDATED = []; +$REPOS_WITH_PRS_TO_CLOSE = []; $OUT = null; // options diff --git a/update_command.php b/update_command.php index 9068ebe..9487ea9 100644 --- a/update_command.php +++ b/update_command.php @@ -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, $REPOS_WITH_PRS_TO_CLOSE; $OUT = $output; $reposMissingBranch = []; @@ -161,8 +161,15 @@ error("Branch $branchToCheckout does not support CMS major version $cmsMajor"); } - // create a new branch used for the pull-request - if (!$input->getOption('update-prs')) { + if ($input->getOption('update-prs')) { + // Delete the last commit so we're starting as through we didn't do the previous run + $lastCommitMessage = cmd('git log -1 --pretty=%B', $MODULE_DIR); + if ($lastCommitMessage !== PR_TITLE) { + error("Last commit message \"$lastCommitMessage\" does not match PR_TITLE \"" . PR_TITLE . "\""); + } + cmd("git reset HEAD~ --hard", $MODULE_DIR); + } else { + // create a new branch used for the pull-request $timestamp = time(); $prBranch = "pulls/$branchToCheckout/module-standardiser-$timestamp"; cmd("git checkout -b $prBranch", $MODULE_DIR); @@ -185,20 +192,14 @@ $status = cmd('git status', $MODULE_DIR); if (strpos($status, 'nothing to commit') !== false) { info("No changes to commit for $repo"); + if ($input->getOption('update-prs')) { + $REPOS_WITH_PRS_TO_CLOSE[] = $GITHUB_REF; + } continue; } + // create new commit cmd('git add .', $MODULE_DIR); - if ($input->getOption('update-prs')) { - // squash on to existing commit - $lastCommitMessage = cmd('git log -1 --pretty=%B', $MODULE_DIR); - if ($lastCommitMessage !== PR_TITLE) { - error("Last commit message \"$lastCommitMessage\" does not match PR_TITLE \"" . PR_TITLE . "\""); - } - cmd("git commit --amend --no-edit", $MODULE_DIR); - } else { - // create new commit - cmd("git commit -m '" . PR_TITLE . "'", $MODULE_DIR); - } + cmd("git commit -m '" . PR_TITLE . "'", $MODULE_DIR); if ($input->getOption('dry-run')) { info('Not pushing changes or creating pull-request because --dry-run option is set'); continue; @@ -227,6 +228,7 @@ } output_repos_with_prs_created(); output_prs_created(); + output_repos_with_prs_to_close(); // Report about any repos for which we couldn't find the right branch. if (count($reposMissingBranch)) { From 0863275d1cff4135ff32c320200b8465d3dd2cb0 Mon Sep 17 00:00:00 2001 From: Guy Sartorelli Date: Thu, 1 Aug 2024 16:41:20 +1200 Subject: [PATCH 3/5] FIX Add patch tagging workflow to gha-ci repos too --- scripts/cms-any/tag-patch-release.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/scripts/cms-any/tag-patch-release.php b/scripts/cms-any/tag-patch-release.php index 84d9bde..278dfc5 100644 --- a/scripts/cms-any/tag-patch-release.php +++ b/scripts/cms-any/tag-patch-release.php @@ -32,9 +32,16 @@ EOT; $workflowPath = '.github/workflows/tag-patch-release.yml'; -$ciPath = '.github/workflows/ci.yml'; +$ciPaths = [ '.github/workflows/ci.yml', '.github/workflows/action-ci.yml' ]; +$shouldHaveAction = false; -if (check_file_exists($ciPath)) { +foreach ($ciPaths as $ciPath) { + if (check_file_exists($ciPath)) { + $shouldHaveAction = true; + } +} + +if ($shouldHaveAction) { write_file_even_if_exists($workflowPath, $content); } else { delete_file_if_exists($workflowPath); From 335e0543574b6455d0f25bc69320d244b3c4c698 Mon Sep 17 00:00:00 2001 From: Guy Sartorelli Date: Fri, 2 Aug 2024 09:24:46 +1200 Subject: [PATCH 4/5] FIX Exclude some modules from getting tag-patch-release.yml --- scripts/cms-any/tag-patch-release.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/scripts/cms-any/tag-patch-release.php b/scripts/cms-any/tag-patch-release.php index 278dfc5..a69e7f6 100644 --- a/scripts/cms-any/tag-patch-release.php +++ b/scripts/cms-any/tag-patch-release.php @@ -41,6 +41,16 @@ } } +$notAllowedRepos = [ + 'cow', + 'rhino', + 'github-issue-search-client', + 'module-standardiser', + 'silverstripe-tx-translator', + 'supported-modules', +]; +$shouldHaveAction = $shouldHaveAction && !is_misc() && !module_is_one_of($notAllowedRepos); + if ($shouldHaveAction) { write_file_even_if_exists($workflowPath, $content); } else { From c167c4cfaf2de1046130210427f41654ebfcfffa Mon Sep 17 00:00:00 2001 From: Guy Sartorelli Date: Fri, 2 Aug 2024 10:09:48 +1200 Subject: [PATCH 5/5] FIX Resolve next-patch branch for wildcard repos --- update_command.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/update_command.php b/update_command.php index 9487ea9..1050c48 100644 --- a/update_command.php +++ b/update_command.php @@ -79,7 +79,7 @@ } cmd("git remote add pr-remote $prOrigin", $MODULE_DIR); - $useDefaultBranch = has_wildcard_major_version_mapping() || $branchOption === 'github-default'; + $useDefaultBranch = (has_wildcard_major_version_mapping() && !current_branch_name_is_numeric_style()) || $branchOption === 'github-default'; if ($input->getOption('update-prs')) { // checkout latest existing pr branch