From 1e23091136d1abab2e50c5f1c74d9c9e4c68c40b Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Wed, 16 Aug 2023 12:49:40 +1200 Subject: [PATCH] FIX Find cms major for developer-docs --- action.yml | 2 +- branches.php | 3 ++- funcs.php | 12 ++++++++++-- tests/BranchesTest.php | 39 ++++++++++++++++++++++++++++++++++++++- 4 files changed, 51 insertions(+), 5 deletions(-) diff --git a/action.yml b/action.yml index 51aff47..61a0205 100644 --- a/action.yml +++ b/action.yml @@ -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]} diff --git a/branches.php b/branches.php index 25b5844..7306d62 100644 --- a/branches.php +++ b/branches.php @@ -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); diff --git a/funcs.php b/funcs.php index aa54717..52fa5dc 100644 --- a/funcs.php +++ b/funcs.php @@ -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 = '', @@ -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'} ?? ''); } @@ -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; diff --git a/tests/BranchesTest.php b/tests/BranchesTest.php index 8e79a52..6aacd1e 100644 --- a/tests/BranchesTest.php +++ b/tests/BranchesTest.php @@ -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); } @@ -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' => << ['4.13', '4', '5.1', '5'], 'defaultBranch' => '5', 'minimumCmsMajor' => '4', + 'githubRepository' => 'lorem/ipsum', 'composerJson' => << ['4.13', '4', '5.1', '5'], 'defaultBranch' => '5', 'minimumCmsMajor' => '4', + 'githubRepository' => 'lorem/ipsum', 'composerJson' => << ['4.13', '4', '5.1', '5'], 'defaultBranch' => '5', 'minimumCmsMajor' => '4', + 'githubRepository' => 'lorem/ipsum', 'composerJson' => << ['1.13', '2.0', '2.1', '2'], 'defaultBranch' => '2', 'minimumCmsMajor' => '4', + 'githubRepository' => 'lorem/ipsum', 'composerJson' => << ['1.13', '1', '2.1', '2.2', '2.3', '2'], 'defaultBranch' => '2', 'minimumCmsMajor' => '4', + 'githubRepository' => 'lorem/ipsum', 'composerJson' => << ['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' => << [ + 'expected' => ['4.13', '4', '5.0', '5'], + 'defaultBranch' => '5', + 'minimumCmsMajor' => '4', + 'githubRepository' => 'silverstripe/developer-docs', + 'composerJson' => << << '[]', + ], ]; } }