From 0559e7143c1ca60661fa02577d358c069c9e9d0f Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Tue, 2 Apr 2024 11:32:14 +1300 Subject: [PATCH] ENH Prevent merge-up from linkfield v3 --- README.md | 10 +++++++ funcs.php | 15 +++++++++++ tests/BranchesTest.php | 61 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+) diff --git a/README.md b/README.md index a3734fd..d341f60 100644 --- a/README.md +++ b/README.md @@ -12,3 +12,13 @@ steps: ``` This action has no inputs + +## Preventing merge-ups from specific major versions of a repository + +update `DO_NOT_MERGE_UP_FROM_MAJOR` in `funcs.php`. For example to prevent merging up from the `3` major version of `silverstripe/silverstripe-linkfield`: + +```php +const DO_NOT_MERGE_UP_FROM_MAJOR = [ + 'silverstripe/silverstripe-linkfield' => '3', +]; +``` diff --git a/funcs.php b/funcs.php index 428379b..5cc1d9d 100644 --- a/funcs.php +++ b/funcs.php @@ -3,6 +3,13 @@ // This should always match default branch of silverstripe/framework const CURRENT_CMS_MAJOR = 5; +// List of major branches to not merge up from +// Add repos in here where the repo was previously unsupported +// Note these are actual major branches, not CMS major versions +const DO_NOT_MERGE_UP_FROM_MAJOR = [ + 'silverstripe/silverstripe-linkfield' => '3', +]; + function branches( string $defaultBranch, string $minimumCmsMajor, @@ -152,6 +159,14 @@ function branches( } $foundMinorInMajor[$major] = true; } + + // remove any branches less than or equal to DO_NOT_MERGE_UP_FROM_MAJOR + if (isset(DO_NOT_MERGE_UP_FROM_MAJOR[$githubRepository])) { + $doNotMergeUpFromMajor = DO_NOT_MERGE_UP_FROM_MAJOR[$githubRepository]; + $branches = array_filter($branches, function($branch) use ($doNotMergeUpFromMajor) { + return version_compare($branch, $doNotMergeUpFromMajor, '>'); + }); + } // reverse the array so that oldest is first $branches = array_reverse($branches); diff --git a/tests/BranchesTest.php b/tests/BranchesTest.php index eb1a878..2559ab0 100644 --- a/tests/BranchesTest.php +++ b/tests/BranchesTest.php @@ -405,6 +405,67 @@ public function provideBranches() ] EOT, ], + 'silverstripe-linkfield beta' => [ + 'expected' => ['4.0', '4', '5'], + 'defaultBranch' => '4', + 'minimumCmsMajor' => '4', + 'githubRepository' => 'silverstripe/silverstripe-linkfield', + 'composerJson' => << << << [ + 'expected' => ['4.0', '4', '5'], + 'defaultBranch' => '4', + 'minimumCmsMajor' => '4', + 'githubRepository' => 'silverstripe/silverstripe-linkfield', + 'composerJson' => << << <<