@@ -204,15 +204,57 @@ jobs:
204204 - name : Checkout code
205205 uses : actions/checkout@v5
206206 with :
207- ref : ${{ github.event.workflow_run.head_branch }}
207+ ref : ${{ github.event.workflow_run.head_sha }}
208208 fetch-depth : 0
209209
210210 - name : Fetch failed logs
211211 id : failed_logs
212212 env :
213213 GH_TOKEN : ${{ secrets.GH_PAT || github.token }}
214+ GH_REPO : ${{ github.repository }}
214215 run : |
215- gh run view ${{ github.event.workflow_run.id }} --log-failed > failed.log 2>/dev/null || echo "Failed to fetch logs" > failed.log
216+ set -euo pipefail
217+
218+ run_id="${{ github.event.workflow_run.id }}"
219+ run_url="${{ github.event.workflow_run.html_url }}"
220+
221+ if [ -z "$run_id" ]; then
222+ echo "::error::Missing workflow_run.id; this job only supports workflow_run triggers."
223+ exit 1
224+ fi
225+
226+ echo "Fetching failed logs for run $run_id ($run_url)"
227+
228+ tmp_err="$(mktemp)"
229+ if gh run view "$run_id" --repo "$GH_REPO" --log-failed > failed.log 2>"$tmp_err"; then
230+ if [ ! -s failed.log ]; then
231+ echo "::error::Fetched logs are empty (run $run_id)."
232+ {
233+ echo "ERROR: fetched logs are empty."
234+ echo "Run URL: $run_url"
235+ } > failed.log
236+ exit 1
237+ fi
238+ else
239+ echo "::error::Failed to fetch logs for run $run_id."
240+ {
241+ echo "ERROR: failed to fetch logs for run $run_id."
242+ echo "Run URL: $run_url"
243+ echo ""
244+ echo "--- gh stderr ---"
245+ cat "$tmp_err"
246+ } > failed.log
247+ {
248+ echo "### Claude CI Auto-Fix"
249+ echo ""
250+ echo "Failed to fetch logs for run $run_id."
251+ echo ""
252+ echo "- Run: $run_url"
253+ echo "- Details captured in \`failed.log\` (runner workspace)"
254+ } >> "$GITHUB_STEP_SUMMARY"
255+ exit 1
256+ fi
257+
216258 echo "log_path=failed.log" >> "$GITHUB_OUTPUT"
217259
218260 - name : Get CI failure details
@@ -243,7 +285,8 @@ jobs:
243285 failedJobs: failedJobs.map(j => j.name),
244286 hasPR: hasPR,
245287 prNumber: hasPR ? pullRequests[0].number : null,
246- headBranch: '${{ github.event.workflow_run.head_branch }}'
288+ headBranch: '${{ github.event.workflow_run.head_branch }}',
289+ headSha: '${{ github.event.workflow_run.head_sha }}'
247290 };
248291
249292 - name : Run Claude Code for Auto-Fix
@@ -266,6 +309,7 @@ jobs:
266309 - **Workflow**: ${{ fromJSON(steps.failure_details.outputs.result).workflowName }}
267310 - **Failed Run**: ${{ fromJSON(steps.failure_details.outputs.result).runUrl }}
268311 - **Branch**: ${{ fromJSON(steps.failure_details.outputs.result).headBranch }}
312+ - **SHA (pinned)**: ${{ fromJSON(steps.failure_details.outputs.result).headSha }}
269313 - **Has PR**: ${{ fromJSON(steps.failure_details.outputs.result).hasPR }}
270314 - **PR Number**: ${{ fromJSON(steps.failure_details.outputs.result).prNumber }}
271315 - **Failed Jobs**: ${{ join(fromJSON(steps.failure_details.outputs.result).failedJobs, ', ') }}
0 commit comments