Skip to content

Commit

Permalink
Merge branch '1.2' into 1
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Mar 5, 2025
2 parents d99c139 + d357a2b commit 82d3c7a
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 8 deletions.
41 changes: 38 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ runs:
fi
# Gets 100 most recently created tags from GitHub API
# https://docs.github.com/en/rest/git/tags?apiVersion=2022-11-28
# https://docs.github.com/en/rest/repos/repos?apiVersion=2022-11-28#list-repository-tags
RESP_CODE=$(curl -w %{http_code} -s -o __tags.json \
-X GET "https://api.github.com/repos/$GITHUB_REPOSITORY/tags?per_page=100" \
-H "Accept: application/vnd.github+json" \
Expand All @@ -84,6 +84,27 @@ runs:
echo "Unable to read list of tags - HTTP response code was $RESP_CODE"
exit 1
fi
# Parse the "link" header to see if there's a next page of tags
NEXT_LINK=$(curl -I -s \
-X HEAD "https://api.github.com/repos/$GITHUB_REPOSITORY/tags?per_page=100" \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ github.token }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
| sed -n -E 's/link:.*<(.*?)>; rel="next".*/\1/p'
)
if [[ $NEXT_LINK != "" ]]; then
# Get the next 100 tags just in case (sometimes needed at the end of a major release line cycle)
RESP_CODE=$(curl -w %{http_code} -s -o __tags2.json \
-X GET "${NEXT_LINK}" \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ github.token }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
)
if [[ $RESP_CODE != "200" ]]; then
echo "Unable to read second page of tags - HTTP response code was $RESP_CODE"
exit 1
fi
fi
# Download composer.json for use in branches.php
RESP_CODE=$(curl -w %{http_code} -s -o __composer.json https://raw.githubusercontent.com/$GITHUB_REPOSITORY/$DEFAULT_BRANCH/composer.json)
Expand All @@ -104,6 +125,9 @@ runs:
fi
echo "branches=$BRANCHES" >> $GITHUB_OUTPUT
rm __tags.json
if [[ -f __tags2.json ]]; then
rm __tags2.json
fi
rm __branches.json
if [[ -f __composer.json ]]; then
rm __composer.json
Expand Down Expand Up @@ -207,16 +231,17 @@ runs:
git config --local user.name "github-actions"
# List of branches to trigger-ci for later
# Normally we'll only ever trigger 3 branches, though providing up to 6 for scenarios
# Normally we'll only ever trigger 3 branches, though providing up to 7 for scenarios
# where there is are things like betas in the mix
# branches.php will throw an Exception early if there is more than 6 branches which will cause
# branches.php will throw an Exception early if there is more than 7 branches which will cause
# this job to fail without any merge-ups being performed
TRIGGER_CI_BRANCH_01=""
TRIGGER_CI_BRANCH_02=""
TRIGGER_CI_BRANCH_03=""
TRIGGER_CI_BRANCH_04=""
TRIGGER_CI_BRANCH_05=""
TRIGGER_CI_BRANCH_06=""
TRIGGER_CI_BRANCH_07=""
TRIGGER_CI_EXCEEDED=""
FROM_BRANCH=""
Expand Down Expand Up @@ -414,6 +439,8 @@ runs:
TRIGGER_CI_BRANCH_05=$INTO_BRANCH
elif [[$TRIGGER_CI_BRANCH_06 == "" ]]; then
TRIGGER_CI_BRANCH_06=$INTO_BRANCH
elif [[$TRIGGER_CI_BRANCH_07 == "" ]]; then
TRIGGER_CI_BRANCH_07=$INTO_BRANCH
else
if [[ $TRIGGER_CI_EXCEEDED == "" ]]; then
TRIGGER_CI_EXCEEDED=$INTO_BRANCH
Expand All @@ -428,13 +455,15 @@ runs:
echo "TRIGGER_CI_BRANCH_04 is $TRIGGER_CI_BRANCH_04"
echo "TRIGGER_CI_BRANCH_05 is $TRIGGER_CI_BRANCH_05"
echo "TRIGGER_CI_BRANCH_06 is $TRIGGER_CI_BRANCH_06"
echo "TRIGGER_CI_BRANCH_07 is $TRIGGER_CI_BRANCH_07"
echo "TRIGGER_CI_EXCEEDED is $TRIGGER_CI_EXCEEDED"
echo "trigger_ci_branch_01=$TRIGGER_CI_BRANCH_01" >> $GITHUB_OUTPUT
echo "trigger_ci_branch_02=$TRIGGER_CI_BRANCH_02" >> $GITHUB_OUTPUT
echo "trigger_ci_branch_03=$TRIGGER_CI_BRANCH_03" >> $GITHUB_OUTPUT
echo "trigger_ci_branch_04=$TRIGGER_CI_BRANCH_04" >> $GITHUB_OUTPUT
echo "trigger_ci_branch_05=$TRIGGER_CI_BRANCH_05" >> $GITHUB_OUTPUT
echo "trigger_ci_branch_06=$TRIGGER_CI_BRANCH_06" >> $GITHUB_OUTPUT
echo "trigger_ci_branch_07=$TRIGGER_CI_BRANCH_07" >> $GITHUB_OUTPUT
echo "trigger_ci_exceeded=$TRIGGER_CI_EXCEEDED" >> $GITHUB_OUTPUT
- name: Trigger CI 01
Expand Down Expand Up @@ -473,6 +502,12 @@ runs:
with:
branch: ${{ steps.git-merge-up.outputs.trigger_ci_branch_06 }}

- name: Trigger CI 07
if: ${{ steps.git-merge-up.outputs.trigger_ci_branch_07 != '' }}
uses: silverstripe/gha-trigger-ci@v1
with:
branch: ${{ steps.git-merge-up.outputs.trigger_ci_branch_07 }}

- name: Trigger CI Exceeded
if: ${{ steps.git-merge-up.outputs.trigger_ci_exceeded != '' }}
shell: bash
Expand Down
9 changes: 6 additions & 3 deletions funcs.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,16 @@ function branches(

$repoMetaData = MetaData::getMetaDataForRepository($githubRepository);
$allRepoTags = array_map(fn($x) => $x->name, json_decode(file_get_contents('__tags.json')));
if (file_exists('__tags2.json')) {
$allRepoTags = array_merge($allRepoTags, array_map(fn($x) => $x->name, json_decode(file_get_contents('__tags2.json'))));
}
$allRepoBranches = array_map(fn($x) => $x->name, json_decode(file_get_contents('__branches.json')));

$branches = BranchLogic::getBranchesForMergeUp($githubRepository, $repoMetaData, $defaultBranch, $allRepoTags, $allRepoBranches, $composerJson);
// max of 6 branches - also update action.yml if you need to increase this limit
if (count($branches) > 6) {
// max of 7 branches - also update action.yml if you need to increase this limit
if (count($branches) > 7) {
$branchesString = implode(', ', $branches);
throw new Exception("More than 6 branches to merge up: $branchesString. Aborting.");
throw new Exception("More than 7 branches to merge up: $branchesString. Aborting.");
}
return $branches;
}
53 changes: 51 additions & 2 deletions tests/BranchesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,54 @@ public function provideBranches()
]
EOT,
],
'More than 6 branches exception' => [
'6.0.0-alpha1 with all final CMS 4/5 branches on silverstripe/framework' => [
'expected' => ['4.13', '4', '5.3', '5.4', '5', '6.0', '6'],
'defaultBranch' => '5',
'githubRepository' => 'lorem/ipsum',
'composerJson' => <<<EOT
{
"require": {
"silverstripe/framework": "^5.4"
}
}
EOT,
'branchesJson' => <<<EOT
[
{"name": "3"},
{"name": "3.6"},
{"name": "3.7"},
{"name": "4"},
{"name": "4.10"},
{"name": "4.11"},
{"name": "4.12"},
{"name": "4.13"},
{"name": "5"},
{"name": "5.0"},
{"name": "5.1"},
{"name": "5.2"},
{"name": "5.3"},
{"name": "5.4"},
{"name": "6"},
{"name": "6.0"}
]
EOT,
'tagsJson' => <<<EOT
[
{"name": "6.0.0-alpha1"},
{"name": "5.4.0-beta1"},
{"name": "5.3.0"},
{"name": "5.2.0"},
{"name": "5.1.0"},
{"name": "5.0.9"},
{"name": "4.13.11"},
{"name": "4.12.11"},
{"name": "4.11.11"},
{"name": "4.10.11"},
{"name": "3.7.4"}
]
EOT,
],
'More than 7 branches exception' => [
'expected' => ['__exception__'],
'defaultBranch' => '5',
'githubRepository' => 'lorem/ipsum',
Expand All @@ -113,11 +160,13 @@ public function provideBranches()
{"name": "5.0"},
{"name": "5.1"},
{"name": "5.2"},
{"name": "6"}
{"name": "6"},
{"name": "6.0"}
]
EOT,
'tagsJson' => <<<EOT
[
{"name": "6.0.0-alpha1"},
{"name": "5.2.0-beta1"},
{"name": "5.1.0-beta1"},
{"name": "5.0.9"},
Expand Down

0 comments on commit 82d3c7a

Please # to comment.