Skip to content

Commit 5bfbd3f

Browse files
fix: wait for build workflow to complete before pushing to main
- Modified workflow to wait for 'build-and-deploy.yml' to complete successfully on dev branch - Prevents 'Required status check build is in progress' error when pushing to main - Adds 30-minute timeout with 30-second polling interval - Fails gracefully if build fails, is cancelled, or times out This fixes the workflow execution failure where pushes to main were blocked because the required 'build' status check was still in progress.
1 parent 902ce49 commit 5bfbd3f

File tree

1 file changed

+47
-19
lines changed

1 file changed

+47
-19
lines changed

.github/workflows/sync-dev-to-main.yml

Lines changed: 47 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -57,27 +57,55 @@ jobs:
5757
echo "has_new_commits=true" >> $GITHUB_OUTPUT
5858
fi
5959
60-
- name: Check latest dev build status (non-blocking)
60+
- name: Wait for build workflow to complete
6161
if: steps.check-new-commits.outputs.has_new_commits == 'true'
62-
continue-on-error: true # Don't fail if this step fails
6362
run: |
64-
echo "ℹ️ Checking latest build status on ${{ env.SOURCE_BRANCH }} (informational only)..."
65-
66-
# Get latest build workflow run on dev
67-
BUILD_STATUS=$(gh run list --workflow="build-and-deploy.yml" \
68-
--branch ${{ env.SOURCE_BRANCH }} --limit 1 --json conclusion,status \
69-
--jq '.[0] | "\(.status):\(.conclusion)"' 2>/dev/null || echo "unknown:unknown")
70-
71-
echo "Latest build status: $BUILD_STATUS"
72-
73-
if [[ "$BUILD_STATUS" == *"failure"* ]]; then
74-
echo "⚠️ WARNING: Latest ${{ env.SOURCE_BRANCH }} build failed"
75-
echo "⚠️ Proceeding with merge anyway (bypass enabled)"
76-
elif [[ "$BUILD_STATUS" == *"in_progress"* ]]; then
77-
echo "ℹ️ Build is still running on ${{ env.SOURCE_BRANCH }}"
78-
echo "ℹ️ Proceeding with merge anyway (bypass enabled)"
79-
else
80-
echo "✅ Latest build status: $BUILD_STATUS"
63+
echo "⏳ Waiting for 'build-and-deploy.yml' workflow to complete on ${{ env.SOURCE_BRANCH }}..."
64+
65+
MAX_WAIT=1800 # 30 minutes max wait
66+
WAIT_INTERVAL=30 # Check every 30 seconds
67+
ELAPSED=0
68+
69+
while [ $ELAPSED -lt $MAX_WAIT ]; do
70+
# Get latest build workflow run on dev
71+
BUILD_RUN=$(gh run list --workflow="build-and-deploy.yml" \
72+
--branch ${{ env.SOURCE_BRANCH }} --limit 1 --json status,conclusion,databaseId \
73+
--jq '.[0]' 2>/dev/null || echo '{}')
74+
75+
STATUS=$(echo "$BUILD_RUN" | jq -r '.status // "unknown"')
76+
CONCLUSION=$(echo "$BUILD_RUN" | jq -r '.conclusion // "none"')
77+
RUN_ID=$(echo "$BUILD_RUN" | jq -r '.databaseId // "none"')
78+
79+
echo "Build status: $STATUS | Conclusion: $CONCLUSION | Run ID: $RUN_ID"
80+
81+
# Check if build completed
82+
if [ "$STATUS" = "completed" ]; then
83+
if [ "$CONCLUSION" = "success" ]; then
84+
echo "✅ Build workflow completed successfully!"
85+
break
86+
elif [ "$CONCLUSION" = "failure" ]; then
87+
echo "❌ Build workflow failed on ${{ env.SOURCE_BRANCH }}"
88+
echo "⚠️ Cannot sync to main - build must pass first"
89+
exit 1
90+
elif [ "$CONCLUSION" = "cancelled" ]; then
91+
echo "⚠️ Build workflow was cancelled"
92+
echo "⚠️ Cannot sync to main - build must complete successfully"
93+
exit 1
94+
else
95+
echo "⚠️ Build completed with conclusion: $CONCLUSION"
96+
exit 1
97+
fi
98+
fi
99+
100+
# Build still in progress
101+
echo "⏳ Build still running... waiting ${WAIT_INTERVAL}s (${ELAPSED}s elapsed)"
102+
sleep $WAIT_INTERVAL
103+
ELAPSED=$((ELAPSED + WAIT_INTERVAL))
104+
done
105+
106+
if [ $ELAPSED -ge $MAX_WAIT ]; then
107+
echo "❌ Timeout: Build did not complete within ${MAX_WAIT}s"
108+
exit 1
81109
fi
82110
env:
83111
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)