Skip to content

Commit 4dd6631

Browse files
committed
fix: wain for the checks to be started
1 parent bc334ba commit 4dd6631

1 file changed

Lines changed: 79 additions & 2 deletions

File tree

.github/workflows/trunk-upgrade.yaml

Lines changed: 79 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
pull-requests: write
1818
steps:
1919
- name: Checkout
20-
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 #v4.2.2
20+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
2121

2222
- name: Create Token for MasterpointBot App
2323
uses: tibdex/github-app-token@3beb63f4bd073e61482598c45c71c1019b59b73a #v2.1.0
@@ -27,8 +27,85 @@ jobs:
2727
private_key: ${{ secrets.MP_BOT_APP_PRIVATE_KEY }}
2828

2929
- name: Upgrade
30-
uses: trunk-io/trunk-action/upgrade@4d5ecc89b2691705fd08c747c78652d2fc806a94 #v1.1.19
30+
id: trunk-upgrade
31+
uses: trunk-io/trunk-action/upgrade@4d5ecc89b2691705fd08c747c78652d2fc806a94 # v1.1.19
3132
with:
3233
github-token: ${{ steps.generate-token.outputs.token }}
3334
reviewers: "@masterpointio/masterpoint-internal"
3435
prefix: "chore: "
36+
37+
- name: Wait for checks to pass + Merge PR
38+
if: steps.trunk-upgrade.outputs.pull-request-number != ''
39+
env:
40+
GH_TOKEN: ${{ secrets.MASTERPOINT_TEAM_PAT }}
41+
PR_NUMBER: ${{ steps.trunk-upgrade.outputs.pull-request-number }}
42+
run: |
43+
echo "Waiting for status checks to pass on PR #$PR_NUMBER..."
44+
45+
# Wait a bit for checks to start
46+
echo "Waiting 30 seconds for checks to initialize..."
47+
sleep 30
48+
49+
# Try to get all checks first to see if any exist
50+
ALL_CHECKS_JSON=$(gh pr checks "$PR_NUMBER" --json state,bucket || echo "[]")
51+
echo "All checks: $ALL_CHECKS_JSON"
52+
53+
# Get required checks
54+
REQUIRED_CHECKS_JSON=$(gh pr checks "$PR_NUMBER" --required --json state,bucket || echo "[]")
55+
echo "Required checks: $REQUIRED_CHECKS_JSON"
56+
57+
# Check if we have any required checks
58+
REQUIRED_CHECKS_COUNT=$(echo "$REQUIRED_CHECKS_JSON" | jq '. | length')
59+
ALL_CHECKS_COUNT=$(echo "$ALL_CHECKS_JSON" | jq '. | length')
60+
61+
if [ "$REQUIRED_CHECKS_COUNT" -eq 0 ] && [ "$ALL_CHECKS_COUNT" -eq 0 ]; then
62+
echo "No status checks found. This might be expected if no checks are configured."
63+
echo "Proceeding with auto-approval and merge..."
64+
65+
# Auto-approve the PR
66+
gh pr review "$PR_NUMBER" --approve --body "Auto-approved by trunk upgrade workflow (no status checks configured)"
67+
68+
# Merge the PR
69+
gh pr merge "$PR_NUMBER" --squash --delete-branch --admin
70+
exit 0
71+
fi
72+
73+
# If we have required checks, wait for them. Otherwise, wait for all checks.
74+
if [ "$REQUIRED_CHECKS_COUNT" -gt 0 ]; then
75+
echo "Waiting for $REQUIRED_CHECKS_COUNT required status checks..."
76+
CHECKS_TO_MONITOR="required"
77+
else
78+
echo "No required checks configured. Waiting for all $ALL_CHECKS_COUNT status checks..."
79+
CHECKS_TO_MONITOR="all"
80+
fi
81+
82+
# Wait for checks to complete
83+
while true; do
84+
if [ "$CHECKS_TO_MONITOR" = "required" ]; then
85+
CHECKS_JSON=$(gh pr checks "$PR_NUMBER" --required --json state,bucket)
86+
else
87+
CHECKS_JSON=$(gh pr checks "$PR_NUMBER" --json state,bucket)
88+
fi
89+
90+
echo "Current checks status: $CHECKS_JSON"
91+
92+
if echo "$CHECKS_JSON" | jq -e '.[] | select(.bucket=="fail")' > /dev/null; then
93+
echo "One or more checks have failed. Exiting..."
94+
exit 1
95+
fi
96+
97+
FAILED_OR_PENDING_CHECKS=$(echo "$CHECKS_JSON" | jq '[.[] | select(.state!="SUCCESS" or .bucket!="pass")] | length')
98+
if [ "$FAILED_OR_PENDING_CHECKS" -eq 0 ]; then
99+
echo "All checks passed. Auto-approving and merging PR https://github.com/${{ github.repository }}/pull/$PR_NUMBER..."
100+
101+
# Auto-approve the PR
102+
gh pr review "$PR_NUMBER" --approve --body "Auto-approved by trunk upgrade workflow"
103+
104+
# Merge the PR
105+
gh pr merge "$PR_NUMBER" --squash --delete-branch --admin
106+
break
107+
else
108+
echo "Some checks are still running or pending. Retrying in 30s..."
109+
sleep 30
110+
fi
111+
done

0 commit comments

Comments
 (0)