Skip to content

Commit 3cbf6c7

Browse files
committed
Prevent review failures from failing the calling workflow
Signed-off-by: Derek Misler <derek.misler@docker.com>
1 parent 509e721 commit 3cbf6c7

File tree

2 files changed

+6
-81
lines changed

2 files changed

+6
-81
lines changed

.github/workflows/review-pr.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ jobs:
176176
- name: Run PR Review
177177
if: steps.membership.outputs.is_member == 'true'
178178
id: run-review
179+
continue-on-error: true # Don't fail the calling workflow if the review errors
179180
uses: docker/cagent-action/review-pr@latest
180181
with:
181182
pr-number: ${{ inputs.pr-number || github.event.pull_request.number }}
@@ -225,6 +226,7 @@ jobs:
225226

226227
- name: Run PR Review
227228
id: run-review
229+
continue-on-error: true # Don't fail the calling workflow if the review errors
228230
uses: docker/cagent-action/review-pr@latest
229231
with:
230232
pr-number: ${{ inputs.pr-number || github.event.issue.number }}

review-pr/action.yml

Lines changed: 4 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,6 @@ outputs:
6262
exit-code:
6363
description: "Exit code from the review"
6464
value: ${{ steps.run-review.outputs.exit-code }}
65-
review-posted:
66-
description: "Whether a review was posted"
67-
value: ${{ steps.verify-review.outputs.review-verified }}
6865
review-url:
6966
description: "URL to the posted review"
7067
value: ${{ steps.post-summary.outputs.review-url }}
@@ -325,11 +322,6 @@ runs:
325322
# ========================================
326323
# RUN REVIEW using root cagent-action
327324
# ========================================
328-
- name: Record pre-review timestamp
329-
id: pre-review
330-
shell: bash
331-
run: echo "timestamp=$(date -u -d '5 seconds ago' +%Y-%m-%dT%H:%M:%SZ 2>/dev/null || date -u -v-5S +%Y-%m-%dT%H:%M:%SZ)" >> $GITHUB_OUTPUT
332-
333325
- name: Run PR Review
334326
id: run-review
335327
uses: docker/cagent-action@latest
@@ -349,39 +341,6 @@ runs:
349341
extra-args: ${{ inputs.model && format('--model={0}', inputs.model) || '' }}
350342
add-prompt-files: ${{ inputs.add-prompt-files }}
351343

352-
- name: Verify review was posted
353-
id: verify-review
354-
shell: bash
355-
env:
356-
GH_TOKEN: ${{ github.token }}
357-
PR_NUMBER: ${{ steps.resolve-context.outputs.pr-number }}
358-
PRE_REVIEW_TS: ${{ steps.pre-review.outputs.timestamp }}
359-
EXIT_CODE: ${{ steps.run-review.outputs.exit-code }}
360-
run: |
361-
# If the agent failed, no review was posted
362-
if [ "$EXIT_CODE" != "0" ]; then
363-
echo "review-verified=false" >> $GITHUB_OUTPUT
364-
exit 0
365-
fi
366-
367-
# Check for a bot review submitted AFTER this run started
368-
API_ERR=$(mktemp)
369-
REVIEW_COUNT=$(gh api "repos/${{ github.repository }}/pulls/$PR_NUMBER/reviews" \
370-
--jq --arg ts "$PRE_REVIEW_TS" \
371-
'[.[] | select(.user.type == "Bot" and .submitted_at >= $ts)] | length' \
372-
2>"$API_ERR" || echo "0")
373-
if [ -s "$API_ERR" ]; then
374-
echo "::warning::Review verification API error: $(cat "$API_ERR")"
375-
fi
376-
rm -f "$API_ERR"
377-
378-
if [ "$REVIEW_COUNT" -eq 0 ]; then
379-
echo "::warning::Review agent exited successfully but no review was found on the PR. The GitHub token may have expired during execution."
380-
echo "review-verified=false" >> $GITHUB_OUTPUT
381-
else
382-
echo "review-verified=true" >> $GITHUB_OUTPUT
383-
fi
384-
385344
- name: Save reviewer memory
386345
if: always()
387346
continue-on-error: true # Don't fail if memory file doesn't exist (first run)
@@ -398,33 +357,24 @@ runs:
398357
if: always()
399358
shell: bash
400359
env:
401-
GH_TOKEN: ${{ github.token }}
360+
GH_TOKEN: ${{ steps.resolve-token.outputs.token }}
402361
PR_NUMBER: ${{ steps.resolve-context.outputs.pr-number }}
403362
REPOSITORY: ${{ github.repository }}
404363
EXIT_CODE: ${{ steps.run-review.outputs.exit-code }}
405-
REVIEW_VERIFIED: ${{ steps.verify-review.outputs.review-verified }}
406364
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
407365
run: |
408366
REVIEW_URL="https://github.com/$REPOSITORY/pull/$PR_NUMBER"
409367
echo "review-url=$REVIEW_URL" >> $GITHUB_OUTPUT
410368
411-
# Determine status and post fallback comment if review wasn't posted
412369
if [ "$EXIT_CODE" != "0" ]; then
413370
STATUS="❌ **Review failed** (exit code: $EXIT_CODE)"
414371
if ! gh api "repos/$REPOSITORY/issues/$PR_NUMBER/comments" \
415372
-f body="❌ **PR Review Failed** — The review agent encountered an error and could not complete the review. [View logs]($RUN_URL)." \
416373
2>&1; then
417374
echo "::warning::Failed to post fallback comment to PR"
418375
fi
419-
elif [ "$REVIEW_VERIFIED" == "false" ]; then
420-
STATUS="⚠️ **Review not posted** — agent completed but review was not found on the PR (possible token expiry)"
421-
if ! gh api "repos/$REPOSITORY/issues/$PR_NUMBER/comments" \
422-
-f body="⚠️ **PR Review Incomplete** — The review agent completed analysis but was unable to post the review due to an authentication timeout. [View logs]($RUN_URL)." \
423-
2>&1; then
424-
echo "::warning::Failed to post fallback comment to PR"
425-
fi
426376
else
427-
STATUS="✅ **Review posted successfully**"
377+
STATUS="✅ **Review completed**"
428378
fi
429379
430380
# Override the default summary with a cleaner one for PR reviews
@@ -443,40 +393,13 @@ runs:
443393
if: steps.resolve-context.outputs.comment-id != '' && always()
444394
shell: bash
445395
env:
446-
GH_TOKEN: ${{ github.token }} # Use github.token (6h lifetime) — App token may have expired
396+
GH_TOKEN: ${{ steps.resolve-token.outputs.token }}
447397
EXIT_CODE: ${{ steps.run-review.outputs.exit-code }}
448-
REVIEW_VERIFIED: ${{ steps.verify-review.outputs.review-verified }}
449-
PR_NUMBER: ${{ steps.resolve-context.outputs.pr-number }}
450-
PRE_REVIEW_TS: ${{ steps.pre-review.outputs.timestamp }}
451398
run: |
452399
if [ "$EXIT_CODE" != "0" ]; then
453-
# Error: add confused reaction
454400
gh api "repos/${{ github.repository }}/issues/comments/${{ steps.resolve-context.outputs.comment-id }}/reactions" \
455401
-X POST -f content='confused' || true
456-
exit 0
457-
fi
458-
459-
if [ "$REVIEW_VERIFIED" == "false" ]; then
460-
# Agent succeeded but review wasn't posted (likely token expiry)
461-
gh api "repos/${{ github.repository }}/issues/comments/${{ steps.resolve-context.outputs.comment-id }}/reactions" \
462-
-X POST -f content='confused' || true
463-
exit 0
464-
fi
465-
466-
# Get the state of the review posted during THIS run
467-
API_ERR=$(mktemp)
468-
REVIEW_STATE=$(gh api "repos/${{ github.repository }}/pulls/$PR_NUMBER/reviews" \
469-
--jq --arg ts "$PRE_REVIEW_TS" \
470-
'[.[] | select(.user.type == "Bot" and .submitted_at >= $ts)] | last | .state // empty' \
471-
2>"$API_ERR" || echo "")
472-
if [ -s "$API_ERR" ]; then
473-
echo "::warning::Review state API error: $(cat "$API_ERR")"
474-
fi
475-
rm -f "$API_ERR"
476-
477-
if [ "$REVIEW_STATE" == "APPROVED" ]; then
478-
# Approved: thumbs up
402+
else
479403
gh api "repos/${{ github.repository }}/issues/comments/${{ steps.resolve-context.outputs.comment-id }}/reactions" \
480404
-X POST -f content='+1' || true
481405
fi
482-
# Changes requested: no reaction (the review itself is the feedback)

0 commit comments

Comments
 (0)