Skip to content

Commit

Permalink
FIX Find cms major for developer-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Aug 16, 2023
1 parent 93229f9 commit 1e23091
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 5 deletions.
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ runs:
# Download composer.json for use in branches.php
curl -s -o __composer.json https://raw.githubusercontent.com/$GITHUB_REPOSITORY/$DEFAULT_BRANCH/composer.json
BRANCHES=$(MINIMUM_CMS_MAJOR=$MINIMUM_CMS_MAJOR DEFAULT_BRANCH=$DEFAULT_BRANCH php ${{ github.action_path }}/branches.php)
BRANCHES=$(MINIMUM_CMS_MAJOR=$MINIMUM_CMS_MAJOR DEFAULT_BRANCH=$DEFAULT_BRANCH GITHUB_REPOSITORY=$GITHUB_REPOSITORY php ${{ github.action_path }}/branches.php)
echo "BRANCHES is $BRANCHES"
if [[ $BRANCHES =~ "^FAILURE \- (.+)$" ]]; then
MESSAGE=${BASH_REMATCH[1]}
Expand Down
3 changes: 2 additions & 1 deletion branches.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

$defaultBranch = getenv('DEFAULT_BRANCH');
$minimumCmsMajor = getenv('MINIMUM_CMS_MAJOR');
$githubRepository = getenv('GITHUB_REPOSITORY');

$branches = branches($defaultBranch, $minimumCmsMajor);
$branches = branches($defaultBranch, $minimumCmsMajor, $githubRepository);
echo implode(' ', $branches);
12 changes: 10 additions & 2 deletions funcs.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
function branches(
string $defaultBranch,
string $minimumCmsMajor,
string $githubRepository,
// The following params are purely for unit testing, for the actual github action it will read json files instead
string $composerJson = '',
string $branchesJson = '',
Expand All @@ -28,7 +29,13 @@ function branches(
}
$defaultCmsMajor = '';
$matchedOnBranchThreeLess = false;
$version = preg_replace('#[^0-9\.]#', '', $json->require->{'silverstripe/framework'} ?? '');
$version = '';
if ($githubRepository === 'silverstripe/developer-docs') {
$version = $defaultBranch;
}
if (!$version) {
$version = preg_replace('#[^0-9\.]#', '', $json->require->{'silverstripe/framework'} ?? '');
}
if (!$version) {
$version = preg_replace('#[^0-9\.]#', '', $json->require->{'silverstripe/cms'} ?? '');
}
Expand Down Expand Up @@ -115,7 +122,8 @@ function branches(
unset($branches[$i]);
continue;
}
if (isset($minorsWithStableTags[$major][$branch])) {
// for developer-docs which has no tags, pretend that every branch has a tag
if (isset($minorsWithStableTags[$major][$branch]) || $githubRepository === 'silverstripe/developer-docs') {
$foundMinorBranchWithStableTag[$major] = true;
}
$foundMinorInMajor[$major] = true;
Expand Down
39 changes: 38 additions & 1 deletion tests/BranchesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,19 @@ public function testBranches(
array $expected,
string $defaultBranch,
string $minimumCmsMajor,
string $githubRepository,
string $composerJson = '',
string $branchesJson = '',
string $tagsJson = ''
) {
$actual = branches($defaultBranch, $minimumCmsMajor, $composerJson, $branchesJson, $tagsJson);
$actual = branches(
$defaultBranch,
$minimumCmsMajor,
$githubRepository,
$composerJson,
$branchesJson,
$tagsJson
);
$this->assertSame($expected, $actual);
}

Expand All @@ -26,6 +34,7 @@ public function provideBranches()
'expected' => ['4.13', '4', '5.0', '5.1', '5', '6'],
'defaultBranch' => '5',
'minimumCmsMajor' => '4',
'githubRepository' => 'lorem/ipsum',
'composerJson' => <<<EOT
{
"require": {
Expand Down Expand Up @@ -65,6 +74,7 @@ public function provideBranches()
'expected' => ['4.13', '4', '5.1', '5'],
'defaultBranch' => '5',
'minimumCmsMajor' => '4',
'githubRepository' => 'lorem/ipsum',
'composerJson' => <<<EOT
{
"require": {
Expand Down Expand Up @@ -103,6 +113,7 @@ public function provideBranches()
'expected' => ['4.13', '4', '5.1', '5'],
'defaultBranch' => '5',
'minimumCmsMajor' => '4',
'githubRepository' => 'lorem/ipsum',
'composerJson' => <<<EOT
{
"require": {
Expand Down Expand Up @@ -137,6 +148,7 @@ public function provideBranches()
'expected' => ['4.13', '4', '5.1', '5'],
'defaultBranch' => '5',
'minimumCmsMajor' => '4',
'githubRepository' => 'lorem/ipsum',
'composerJson' => <<<EOT
{
"require": {
Expand Down Expand Up @@ -166,6 +178,7 @@ public function provideBranches()
'expected' => ['1.13', '2.0', '2.1', '2'],
'defaultBranch' => '2',
'minimumCmsMajor' => '4',
'githubRepository' => 'lorem/ipsum',
'composerJson' => <<<EOT
{
"require": {
Expand Down Expand Up @@ -199,6 +212,7 @@ public function provideBranches()
'expected' => ['1.13', '1', '2.1', '2.2', '2.3', '2'],
'defaultBranch' => '2',
'minimumCmsMajor' => '4',
'githubRepository' => 'lorem/ipsum',
'composerJson' => <<<EOT
{
"require": {
Expand Down Expand Up @@ -231,6 +245,7 @@ public function provideBranches()
'expected' => ['5.9', '5', '6.0', '6', '7'],
'defaultBranch' => '5', // this repo has a `5` branch for CMS 4 and a '6' branch for CMS 5
'minimumCmsMajor' => '4',
'githubRepository' => 'lorem/ipsum',
'composerJson' => <<<EOT
{
"require": {
Expand Down Expand Up @@ -258,6 +273,28 @@ public function provideBranches()
]
EOT,
],
'developer-docs' => [
'expected' => ['4.13', '4', '5.0', '5'],
'defaultBranch' => '5',
'minimumCmsMajor' => '4',
'githubRepository' => 'silverstripe/developer-docs',
'composerJson' => <<<EOT
{
"no-require": {}
}
EOT,
'branchesJson' => <<<EOT
[
{"name": "5"},
{"name": "5.0"},
{"name": "4.13"},
{"name": "4.12"},
{"name": "4"},
{"name": "3"}
]
EOT,
'tagsJson' => '[]',
],
];
}
}

0 comments on commit 1e23091

Please sign in to comment.