diff --git a/scripts/ci-bun-crash-census.ts b/scripts/ci-bun-crash-census.ts index bfc6d465..c38a337c 100644 --- a/scripts/ci-bun-crash-census.ts +++ b/scripts/ci-bun-crash-census.ts @@ -116,6 +116,8 @@ const WORKFLOW_JOB_KEY = /^ {2}([A-Za-z0-9_-]+):\s*$/; const WORKFLOW_JOB_NAME = /^ {4}name:\s*(.+?)\s*$/; const WORKFLOW_EXPRESSION = /\$\{\{.*?\}\}/; const WORKFLOW_BUN_VERSION = /^\s+bun-version:\s*["']?([^"'\s]+)["']?\s*$/; +/** A YAML comment after a value: `#` preceded by whitespace, to end of line. */ +const YAML_TRAILING_COMMENT = /\s+#.*$/; const SHA = /^[0-9a-f]{40}$/; /** The runs endpoint returns at most 1000 results for one `created` query. */ const MAX_WINDOW_RUNS = 1000; @@ -173,21 +175,26 @@ function workflowJobNamed(opts: { * `jobs:` to the next one. Its display name is its `name:` template, or its * key when it has none, so `test shard 2/4` finds the `test-shard` matrix job. * A job with no `bun-version`, such as the `test` fan-in, returns null. - * Blank lines and column-0 `#` comments inside `jobs:` are skipped; any other - * column-0 line is the next top-level key and ends the jobs. + * The `jobs:` line may carry a trailing comment (`jobs: # all jobs`). + * Column-0 `#` comments inside `jobs:` are skipped; any other column-0 line is + * the next top-level key and ends the jobs. Blank lines need no skip: they + * start with no non-space character and match no key, `name:` or + * `bun-version`, so they neither end the jobs nor change a block. */ export function workflowJobBunVersion( workflow: string, job: string ): string | null { const lines = workflow.split(/\r?\n/); - const jobsAt = lines.findIndex((line) => line.trimEnd() === "jobs:"); + const jobsAt = lines.findIndex( + (line) => line.replace(YAML_TRAILING_COMMENT, "").trimEnd() === "jobs:" + ); if (jobsAt === -1) { return null; } const blocks: { readonly key: string; readonly lines: string[] }[] = []; for (const line of lines.slice(jobsAt + 1)) { - if (line.trim() === "" || line.startsWith("#")) { + if (line.startsWith("#")) { continue; } if (/^\S/.test(line)) { diff --git a/tests/ci-bun-crash-census.test.ts b/tests/ci-bun-crash-census.test.ts index 78ebca9a..d6fffdc1 100644 --- a/tests/ci-bun-crash-census.test.ts +++ b/tests/ci-bun-crash-census.test.ts @@ -729,6 +729,23 @@ describe("workflow reads (HACK-1441)", () => { expect(workflowJobBunVersion(WORKFLOW, "late")).toBeNull(); }); + test("a trailing comment on the jobs: line still opens the jobs (HACK-1462)", () => { + const commented = [ + "name: CI", + "jobs: # all jobs", + " test:", + " ", + " steps:", + " - with:", + ' bun-version: "1.4.2"', + ].join("\n"); + expect(workflowJobBunVersion(commented, "test")).toBe("1.4.2"); + // `#` without leading whitespace is part of the key, not a comment. + expect( + workflowJobBunVersion(commented.replace("jobs: #", "jobs:#"), "test") + ).toBeNull(); + }); + const SHA_SHARED = "d".repeat(40); const SHA_OTHER = "e".repeat(40);