From ae9f97bade2e212818622329754bfded9f7073b5 Mon Sep 17 00:00:00 2001 From: Mario Campos Date: Wed, 28 Oct 2026 15:30:49 -0500 Subject: [PATCH] Make post-comment marker configurable Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .github/actions/post-comment/action.yml | 10 ++++---- .github/workflows/pr-checks.yml | 1 + pr-checks/post-comment.test.ts | 34 +++++++++++++++++++++++++ pr-checks/post-comment.ts | 6 ++--- 4 files changed, 43 insertions(+), 8 deletions(-) diff --git a/.github/actions/post-comment/action.yml b/.github/actions/post-comment/action.yml index f2233bc97..8b3d56ee9 100644 --- a/.github/actions/post-comment/action.yml +++ b/.github/actions/post-comment/action.yml @@ -1,6 +1,9 @@ name: "Post comment" -description: "Create, update, or delete a sticky PR comment identified by an automatically-derived HTML-comment marker. If this action is used more than once within the same job, give each step an explicit 'id:' so the derived marker stays unique." +description: "Create, update, or delete a sticky PR comment identified by a caller-provided marker." inputs: + marker: + description: "Non-empty marker identifying the comment. Use a unique, stable HTML comment for each distinct comment." + required: true body: description: "Full comment markdown." required: true @@ -26,10 +29,7 @@ runs: shell: bash env: BODY: ${{ inputs.body }} - # Derived from the workflow name, job id, and step id/sequence-number so that repeated - # runs of the same step find the same comment (for upsert/delete), while distinct steps - # (even within the same job) get distinct markers. - MARKER: + MARKER: ${{ inputs.marker }} GH_TOKEN: ${{ inputs.token }} ISSUE_ID: ${{ inputs.issue-id || github.event.pull_request.number }} ACTION_CONDITION: ${{ inputs.action-condition }} diff --git a/.github/workflows/pr-checks.yml b/.github/workflows/pr-checks.yml index 1fbab5612..d8450dc4b 100644 --- a/.github/workflows/pr-checks.yml +++ b/.github/workflows/pr-checks.yml @@ -298,6 +298,7 @@ jobs: !startsWith(github.event.pull_request.head.ref, 'update-bundle/') uses: ./.github/actions/post-comment with: + marker: "" body: | ⚠️ `CHANGELOG.md` has been modified in this PR. Please do not modify `CHANGELOG.md` directly. Instead, create a change-note file in `unreleased-change-notes/`. The `CHANGELOG.md` diff --git a/pr-checks/post-comment.test.ts b/pr-checks/post-comment.test.ts index db6d45539..ca7f7f1dd 100644 --- a/pr-checks/post-comment.test.ts +++ b/pr-checks/post-comment.test.ts @@ -90,6 +90,13 @@ describe("parseOptions", async () => { ); }); + await it("rejects a whitespace-only --marker", () => { + assert.throws( + () => parseOptions(withFlag("--marker", " \t\n")), + /Missing required flag --marker/, + ); + }); + await it("rejects an invalid --action-condition value", () => { assert.throws( () => parseOptions(withFlag("--action-condition", "yes")), @@ -226,6 +233,33 @@ const baseOptions: Options = { }; describe("performAction", async () => { + for (const action of ["upsert", "delete"] as const) { + await it(`uses the supplied marker for '${action}' without affecting other comments`, async () => { + const marker = ""; + const { client, calls } = fakeClient([ + { id: 1, body: "\nunrelated warning" }, + { id: 2, body: `${marker}\nold warning` }, + ]); + const options = parseOptions(withFlag("--marker", marker)); + await performAction(client, action, options); + assert.deepEqual(calls, { + createComment: [], + updateComment: + action === "upsert" + ? [ + { + ...options.repository, + comment_id: 2, + body: `${marker}\nhello`, + }, + ] + : [], + deleteComment: + action === "delete" ? [{ ...options.repository, comment_id: 2 }] : [], + }); + }); + } + await it("does nothing for 'none'", async () => { const { client, calls } = fakeClient([]); await performAction(client, "none", baseOptions); diff --git a/pr-checks/post-comment.ts b/pr-checks/post-comment.ts index 6c1a1e5e5..13e6f2238 100644 --- a/pr-checks/post-comment.ts +++ b/pr-checks/post-comment.ts @@ -10,9 +10,9 @@ The marker is passed explicitly via `--marker` and can be any non-empty string, HTML comment (e.g. ``) is recommended so it doesn't render visibly. It is used both to find a pre-existing comment on the pull request so that `upsert`/`delete` actions know which comment to operate on, and is automatically prepended to -`--body` when posting or updating a comment so that future invocations can find it again. Callers -typically derive this value automatically (see `.github/actions/post-comment`) rather than -hand-authoring it. +`--body` when posting or updating a comment so that future invocations can find it again. +The `.github/actions/post-comment` action requires callers to supply this value via its +`marker` input. */ import { parseArgs } from "node:util";