Skip to content

Commit 368c107

Browse files
taladraneCopilot
andcommitted
Report skips that could not be recorded as failures
record_skip appends to the file the job summary is built from, but every caller runs under "if ! process_pr", which disables set -e for the function and everything it calls. The "return 0" that followed each call overwrote the append's exit status, so a failed write left the run green while silently dropping the branch from the summary. Two of the four call sites are added by this branch, and the summary is the only record of which branches were left in place, so a skip that cannot be recorded is now surfaced as a failure instead of being lost. Nothing has been deleted at any of these points, so failing there cannot leave a branch half-processed. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: daca0885-6779-4adb-bb02-ff6920d73ab3
1 parent e5ef3db commit 368c107

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

‎.github/workflows/delete_staging_and_head_branches_writer.yaml‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,15 @@ jobs:
319319
# Records a branch that was deliberately left in place, along with the open pull
320320
# request that is using it, so the job summary can report it without the run
321321
# having to fail.
322+
# Callers run under "if ! process_pr", which disables set -e for everything they
323+
# call, so a failed write here has to be returned and propagated by hand. A skip
324+
# that cannot be recorded is reported as a failure rather than dropped, because
325+
# the job summary is the only record of which branches were left in place.
322326
record_skip() {
323-
printf '%s\t%s\t%s\n' "$1" "$2" "$3" >> "${SKIPPED_FILE}"
327+
if ! printf '%s\t%s\t%s\n' "$1" "$2" "$3" >> "${SKIPPED_FILE}"; then
328+
echo "::error::Could not record that branch $2 was left in place for pull request $1."
329+
return 1
330+
fi
324331
}
325332
326333
# Removes the staging branch a closed pull request targeted. The branch always
@@ -349,7 +356,7 @@ jobs:
349356
blocking_pr="$(open_pr_using_ref "${branch}")" || lookup_status=$?
350357
if (( lookup_status == 0 )); then
351358
echo "::warning::Staging branch ${branch} is still in use by open pull request #${blocking_pr}; leaving it in place."
352-
record_skip "${pr_number}" "${branch}" "${blocking_pr}"
359+
record_skip "${pr_number}" "${branch}" "${blocking_pr}" || return 1
353360
return 0
354361
fi
355362
if (( lookup_status != 1 )); then
@@ -362,7 +369,7 @@ jobs:
362369
# in use by an open pull request" skip into a run failure.
363370
delete_branch "${branch}" || delete_status=$?
364371
if (( delete_status == 3 )); then
365-
record_skip "${pr_number}" "${branch}" "${BLOCKING_PR}"
372+
record_skip "${pr_number}" "${branch}" "${BLOCKING_PR}" || return 1
366373
return 0
367374
fi
368375
(( delete_status == 0 )) || return 1
@@ -462,7 +469,7 @@ jobs:
462469
if [[ "${head_ref}" == "${base_ref}" ]]; then
463470
delete_branch "${base_ref}" "${head_sha}" || delete_status=$?
464471
if (( delete_status == 3 )); then
465-
record_skip "${pr_number}" "${base_ref}" "${BLOCKING_PR}"
472+
record_skip "${pr_number}" "${base_ref}" "${BLOCKING_PR}" || return 1
466473
return 0
467474
fi
468475
(( delete_status == 0 )) || return 1
@@ -477,7 +484,7 @@ jobs:
477484
# Never delete the staging branch when the head branch could not be removed.
478485
delete_branch "${head_ref}" "${head_sha}" || delete_status=$?
479486
if (( delete_status == 3 )); then
480-
record_skip "${pr_number}" "${head_ref}" "${BLOCKING_PR}"
487+
record_skip "${pr_number}" "${head_ref}" "${BLOCKING_PR}" || return 1
481488
return 0
482489
fi
483490
if (( delete_status != 0 )); then

0 commit comments

Comments
 (0)