From bfff9edf0a3e6751154eed5b7361ff13fbc463f3 Mon Sep 17 00:00:00 2001 From: Luke Abby Date: Sun, 22 Dec 2024 16:53:52 -0800 Subject: [PATCH] Use better message in merge to maintenance --- .github/workflows/checks.yml | 60 +++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 9255f3ce0..fa8efbc94 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -166,9 +166,6 @@ jobs: git remote add upstream https://github.com/${{ github.repository }} git fetch --no-tags upstream main maintenance - # This is its own command so that if the current branch is `maintenance` it'll be overridden. - git checkout -B maintenance upstream/maintenance - baseRef="${{github.head_ref}}" before="" @@ -180,17 +177,23 @@ jobs: range="$before..${{ github.event.pull_request.head.sha || github.event.after }}" - echo "Checking if $range can be cherry-picked onto the maintenance branch." + echo "Checking if $range can be applied onto the maintenance branch." + + git fetch --no-tags origin maintenance main + + branchName=$(git branch --show-current) + branchBase=$(git merge-base upstream/main "$branchName") + branchTip=$(git rev-parse "$branchName") + + # Commit using the GitHub Actions bot user. + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + + echo "Checking if can merge $branchName into maintenance" - # Using cherry-pick preserves the history of the commits so it's normally ideal. - git cherry-pick --allow-empty --no-commit -m 1 "$range" || ( - git cherry-pick --abort - echo "Cannot cherry-pick onto the maintenance branch! Will try git apply." - ) + git checkout -B maintenance upstream/maintenance - # But if an intermediary commit fails to merge cleanly then cherry-pick fails. - # So use a 3-way merge to apply the changes. - git diff c33b7c566118dfc9179a66d312f5ef36bb8a5167..526a3c747d76c1b2f61221ec56ed1e132b5e416e | git apply --3wa + git diff "$branchBase..$branchTip" | git apply --3way <<< "$diff" - name: Install Node if: steps.should_skip.outputs.should_skip != 'true' @@ -230,33 +233,34 @@ jobs: fetch-depth: 0 fetch-tags: false - - name: Cherry pick commits onto maintenance + - name: Pick commits onto maintenance run: | - git fetch origin maintenance:maintenance + git fetch --no-tags origin maintenance main + + branchName=$(git branch --show-current) - git switch maintenance + branchName=$(git branch --show-current) + branchBase=$(git merge-base upstream/main "$branchName") + branchTip=$(git rev-parse "$branchName") # Commit using the GitHub Actions bot user. git config user.name "github-actions[bot]" git config user.email "41898282+github-actions[bot]@users.noreply.github.com" - range="${{ github.event.before }}..${{ github.event.after }}" + git checkout -B maintenance upstream/maintenance - echo "Cherry picking $range onto the maintenance branch." + echo "Merging $branchName into maintenance" - # Pick the freshly added commits onto the maintenance branch. - if git cherry-pick --allow-empty -m 1 "$range"; then - exit 1 - else - git cherry-pick --abort - echo "Falling back to 3way apply!" - fi + # Commit using the GitHub Actions bot user. + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + + git diff "$branchBase..$branchTip" | git apply --3way <<< "$diff" - git diff c33b7c566118dfc9179a66d312f5ef36bb8a5167..526a3c747d76c1b2f61221ec56ed1e132b5e416e | git apply --3wa || ( - echo "Both cherry-pick and 3way apply failed! This can only happen if there is a bug in checkCanMergeToMaintenance or mergeToMaintenance or someone pushed in between!" && exit 1 - ) + message=$(git log --format='* %s' "$range") + message="Merge $branchName into maintenance\n\n$message" - git commit -m "Applied c33b7c566118dfc9179a66d312f5ef36bb8a5167..526a3c747d76c1b2f61221ec56ed1e132b5e416e" + git commit -m "$message" - name: Push changes uses: ad-m/github-push-action@master