Skip to content
Open
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
8 changes: 7 additions & 1 deletion scripts/publish-check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,10 @@
# Annotations and the PR summary describe the tree the review actually reached, which a CI autofix can move past this head.
summary: (if $here then ($review | summary_line($commit.conclusion)) else commit_summary($commit.conclusion) end),
annotations: (if $here then [$review.annotations[:50][] | {path, start_line: .line, end_line: .line, annotation_level: .level, message}] else [] end)
}}' | bash "$GITHUB_ACTION_PATH/scripts/retry.sh" gh api repos/$GITHUB_REPOSITORY/check-runs/$CHECK_ID -X PATCH --input -
}}' | bash "$GITHUB_ACTION_PATH/scripts/retry.sh" gh api repos/$GITHUB_REPOSITORY/check-runs/$CHECK_ID -X PATCH --input - || {

Check warning on line 59 in scripts/publish-check.sh

View check run for this annotation

Muspi Merol Review / code-review

scripts/publish-check.sh#L59

The retry wrapper resends an annotated PATCH on HTTP 502 before this fallback can read the check. Against an endpoint that applied each update and returned 502, one finding was appended eight times before the GET reported success. Reconcile the first ambiguous response before resending a PATCH that carries annotations.
# retry.sh never replays a write whose reply was lost, and it must not here: GitHub appends a
# patch's annotations to the ones already on the check run, so a resend would post every finding twice.
# The verdict is only unknown, not necessarily unapplied, so ask the check run itself.
landed=$(bash "$GITHUB_ACTION_PATH/scripts/retry.sh" gh api "repos/$GITHUB_REPOSITORY/check-runs/$CHECK_ID" --jq '.status == "completed"' </dev/null) || landed=false

Check failure on line 63 in scripts/publish-check.sh

View check run for this annotation

Muspi Merol Review / code-review

scripts/publish-check.sh#L63

Another attempt can close a reused check. I tested a failed-verdict PATCH that returned EOF without applying. The GET returned `completed` with conclusion `neutral` and zero annotations, and the publisher exited 0. Before checkpointing the review, verify that the stored conclusion, output, and annotations match the submitted verdict.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another attempt can close a reused check. I tested a failed-verdict PATCH that returned EOF without applying. The GET returned completed with conclusion neutral and zero annotations, and the publisher exited 0. Before checkpointing the review, verify that the stored conclusion, output, and annotations match the submitted verdict.

[ "$landed" = true ] || exit 1
}
23 changes: 23 additions & 0 deletions scripts/recovery.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,29 @@ esac
}
});

test("a check run that took the verdict keeps it when its reply is lost", () => {
for (const landed of [true, false]) {
const setup = fixture();
executable(setup.dir, "git", "#!/bin/sh\nprintf 'head\\n'\n");
executable(setup.dir, "sleep", "#!/bin/sh\nexit 0\n");
executable(setup.dir, "gh", `#!/bin/sh
case "$*" in
*'/pulls/7 --jq .head.sha'*) printf 'head\\n' ;;
*'/check-runs/10 -X PATCH'*) jq -c . >> "$RUNNER_TEMP/patches.jsonl"; printf 'Patch "https://api.github.com/repos/owner/repo/check-runs/10": EOF\\n' >&2; exit 1 ;;
*'/check-runs/10 --jq'*) printf '%s\\n' '{"status":"${landed ? "completed" : "in_progress"}"}' | jq -r "$4" ;;
*) exit 1 ;;
esac
`);
writeFileSync(join(setup.dir, "review.json"), JSON.stringify({ summary: "Reviewed", commits: [{ sha: "head", conclusion: "success" }], annotations: [{ path: "a.ts", line: 1, level: "warning", message: "Check this" }] }));
const result = run("Publish check run", setup, { GH_TOKEN: "" });
// A lost reply never resends: GitHub appends the annotations a second patch carries.
expect(result.exitCode).toBe(landed ? 0 : 1);
const patches = readFileSync(join(setup.dir, "patches.jsonl"), "utf8").trim().split("\n").map(line => JSON.parse(line));
expect(patches).toHaveLength(1);
expect(patches[0].output.annotations).toEqual([{ path: "a.ts", start_line: 1, end_line: 1, annotation_level: "warning", message: "Check this" }]);
}
});

test("a hosted review closes its own check without publishing a verdict", () => {
const setup = fixture();
executable(setup.dir, "git", "#!/bin/sh\nprintf 'head\\n'\n");
Expand Down
Loading