Skip to content
Merged
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
25 changes: 22 additions & 3 deletions .github/workflows/trunk-upgrade.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,29 @@ jobs:
reviewers: "@masterpointio/masterpoint-internal"
prefix: "chore: "

- name: Merge PR automatically
- name: Wait for checks to pass + Merge PR
if: steps.trunk-upgrade.outputs.pull-request-number != ''
env:
GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }}
GH_TOKEN: ${{ steps.generate-token.outputs.token }}
PR_NUMBER: ${{ steps.trunk-upgrade.outputs.pull-request-number }}
run: |
gh pr merge "$PR_NUMBER" --squash --auto --delete-branch
echo "Waiting for required status checks to pass on PR #$PR_NUMBER..."
while true; do
CHECKS_JSON=$(gh pr checks "$PR_NUMBER" --required --json state,bucket)
Copy link
Contributor

Choose a reason for hiding this comment

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

What's this state,bucket

Copy link
Member Author

Choose a reason for hiding this comment

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

@oycyc these are fields used when checking the status of pull request checks using the GitHub CLI - gh pr checks.

  1. state - the current status of a check. Possible values:
    SUCCESS - The check passed successfully
    FAILURE - The check failed
    PENDING - The check is still running
    ERROR - The check encountered an error
  2. bucket - a higher-level categorization of the check's status (yeah, the naming is a bit confusing).Possible values:
    pass - The check has passed
    fail - The check has failed
    pending - The check is still running or waiting to start

More about how it "makes a decision": the workflow uses both fields to ensure that all checks have not only passed (state="SUCCESS") but are also properly categorized in the bucket before proceeding with the merge.
With this, we ensure that the PR is truly ready to be merged, as it verifies both the immediate state of the checks and their proper categorization in the GH system.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah got it!

echo "Current checks status: $CHECKS_JSON"

if echo "$CHECKS_JSON" | jq -e '.[] | select(.bucket=="fail")' > /dev/null; then
echo "One or more required checks have failed. Exiting..."
exit 1
fi

FAILED_OR_PENDING_CHECKS=$(echo "$CHECKS_JSON" | jq '[.[] | select(.state!="SUCCESS" or .bucket!="pass")] | length')
if [ "$FAILED_OR_PENDING_CHECKS" -eq 0 ]; then
echo "All required checks passed. Merging PR https://github.com/${{ github.repository }}/pull/$PR_NUMBER..."
gh pr merge "$PR_NUMBER" --squash --delete-branch --admin
break
else
echo "Some required checks are still running or pending. Retrying in 30s..."
sleep 30
fi
done