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
15 changes: 11 additions & 4 deletions scripts/ci-bun-crash-census.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)) {
Expand Down
17 changes: 17 additions & 0 deletions tests/ci-bun-crash-census.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Loading