Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH Prevent merge-up from linkfield v3 #32

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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',
];
```
15 changes: 15 additions & 0 deletions funcs.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment on lines +6 to +8
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should technically use a PHPdoc comment (i.e. /** the comment */) but since this is only an internal tool and this is the only change I'd request, I'll just leave it as is.

const DO_NOT_MERGE_UP_FROM_MAJOR = [
'silverstripe/silverstripe-linkfield' => '3',
];

function branches(
string $defaultBranch,
string $minimumCmsMajor,
Expand Down Expand Up @@ -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);
Expand Down
61 changes: 61 additions & 0 deletions tests/BranchesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => <<<EOT
{
"require": {
"silverstripe/framework": "^5"
}
}
EOT,
'branchesJson' => <<<EOT
[
{"name": "1"},
{"name": "2"},
{"name": "3"},
{"name": "4"},
{"name": "4.0"},
{"name": "5"}
]
EOT,
'tagsJson' => <<<EOT
[
{"name": "3.0.0-beta1"},
{"name": "2.0.0"},
{"name": "1.0.0"}
]
EOT,
],
'silverstripe-linkfield stable' => [
'expected' => ['4.0', '4', '5'],
'defaultBranch' => '4',
'minimumCmsMajor' => '4',
'githubRepository' => 'silverstripe/silverstripe-linkfield',
'composerJson' => <<<EOT
{
"require": {
"silverstripe/framework": "^5"
}
}
EOT,
'branchesJson' => <<<EOT
[
{"name": "1"},
{"name": "2"},
{"name": "3"},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a 3.0 branch as well, to ensure this also doesn't try to merge up 3.0 into 3 - ultimately the point of this is to pretend that there is nothing before 4.0 for merge-ups.

Actually that doesn't really matter so I won't ask for it. Just leaving the comment so people in the future know it was considered.
Ultimately whether 3.0 would be merged up to 3 doesn't affect anything. If someone's separately maintaining that it may even be useful to them, but the important part is we don't get anything from 3.x into 4.x.

{"name": "4"},
{"name": "4.0"},
{"name": "5"}
]
EOT,
'tagsJson' => <<<EOT
[
{"name": "4.0.0"},
{"name": "3.0.0"},
{"name": "2.0.0"},
{"name": "1.0.0"}
]
EOT,
],
];
}
}
Loading