Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 38 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1156,22 +1156,54 @@ jobs:
REPOSITORY: ${{ github.repository }}
RUN_ID: ${{ github.run_id }}
RUN_ATTEMPT: ${{ github.run_attempt }}
# What failed, one line per job, from this attempt's jobs (every page, slurped). A job that
# stopped its run at its first failure is recorded as cancelled, and so is every job it
# stopped, `changes` included, so the results above cannot say which job it was: it is
# the cancelled job with a failed step, and the first such is named as the one that
# stopped the run. Left out, as consequences of an earlier failure: a job that started
# after the stop (only always() jobs start on a cancelled run), and `tests` when a shard
# did not pass, since its check is that every shard passed. A job's full name is one line,
# never split at its commas ("format, lint, types"). A run cancelled with no failed job
# says so, so it is not mistaken for a stop (scripts/verify-failures.test.ts).
NAME_FAILURES: |
def line: "\(.name) failed at \"\(.failed_at.name)\"";
[.[].jobs[]] as $jobs
| ([$jobs[] | select(any(.steps[]?; .conclusion == "failure"))
| . + {failed_at: first(.steps[] | select(.conclusion == "failure"))}]
| sort_by(.failed_at.completed_at)) as $failed
| any($jobs[]; (.name | startswith("tests (shard ")) and .conclusion != "success" and .conclusion != "skipped") as $shard_down
| [$failed[] | select(.name != "tests" or ($shard_down | not))] as $failed
| [$failed[] | select(.conclusion == "cancelled")] as $stoppers
| if ($stoppers | length) > 0 then
$stoppers[0] as $stop
| "Stopped the run: \($stop | line). Its log shows why; the jobs it stopped are marked cancelled.",
($failed[] | select(.name != $stop.name and .started_at <= $stop.failed_at.completed_at) | "Also failed: \(line).")
elif ($failed | length) > 0 then
$failed[] | "Failed: \(line)."
elif any($jobs[]; .conclusion == "cancelled") then
"No job failed: the run was cancelled from outside it, by a newer push, the merge queue or a person."
else empty end
run: |
set -euo pipefail
echo "$RESULTS"
if [ -n "$QUEUE_RUN" ]; then
echo "::notice::Tested in the merge queue: $QUEUE_RUN"
echo "Tested in the merge queue: $QUEUE_RUN" >> "$GITHUB_STEP_SUMMARY"
fi
# The jobs with a failed step, named first: a job that stopped its run at its first failure
# is recorded as cancelled, and so is every job it stopped, `changes` included.
# What failed, named before every red exit (NAME_FAILURES above says how), on the job and
# at the top of the run's summary.
name_failures() {
if ! failed=$(gh api --paginate "repos/$REPOSITORY/actions/runs/$RUN_ID/attempts/$RUN_ATTEMPT/jobs?per_page=100" \
--jq '.jobs[] | select(any(.steps[]?; .conclusion == "failure")) | .name'); then
local named line
if ! named=$(gh api --paginate "repos/$REPOSITORY/actions/runs/$RUN_ID/attempts/$RUN_ATTEMPT/jobs?per_page=100" \
| jq -rs "$NAME_FAILURES"); then
echo "::warning::Could not read this run's jobs to name the ones that failed."
elif [ -n "$failed" ]; then
echo "::error::Failed: $(echo "$failed" | paste -sd ',' - | sed 's/,/, /g'). Their logs show the step that failed."
return 0
fi
while IFS= read -r line; do
[ -n "$line" ] || continue
echo "::error::$line"
echo "- $line" >> "$GITHUB_STEP_SUMMARY"
done <<< "$named"
}
if [ "$CHANGES" != success ]; then
name_failures
Expand Down
6 changes: 4 additions & 2 deletions scripts/stop-on-failure.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,12 @@ describe("the failing job cancels its own run", () => {
const verify = yaml<Workflow>(CI).jobs.verify;
expect(verify.if).toBe("always()");
expect(verify.permissions).toEqual({ contents: "read", actions: "read" });
const script = verify.steps?.find((step) => step.run)?.run ?? "";
const step = verify.steps?.find((candidate) => candidate.run);
const script = step?.run ?? "";
expect(script).toContain("success|skipped) ;;");
expect(script).toContain('echo "::error::A required check reported');
expect(script).toContain('.conclusion == "failure"');
// How it names them: scripts/verify-failures.test.ts.
expect(step?.env?.NAME_FAILURES).toContain('.conclusion == "failure"');
// Named before every red exit, `changes` reporting cancelled included: a run stopped at its
// first failure cancels `changes` too (seen live on the first proof run).
for (const red of [
Expand Down
Loading
Loading