Skip to content
Closed
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: 6 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ on:
jobs:
compile:
runs-on: ubuntu-latest
permissions:
contents: read
actions: read

strategy:
matrix:
Expand All @@ -30,8 +33,10 @@ jobs:
- name: configure
run: cmake -Stest -Bbuild
- name: build-${{ matrix.os.name }}
env:
GH_TOKEN: ${{ github.token }}
run: |
echo "CPPWARNINGNOTIFIER_LOG_MARKER"
echo "CPPWARNINGNOTIFIER_LOG_MARKER $(gh api "repos/$GITHUB_REPOSITORY/actions/jobs/${{ job.check_run_id }}" --jq '.steps[] | select(.status == "in_progress") | .number')"
cmake --build build

run-notifier:
Expand All @@ -48,7 +53,6 @@ jobs:
with:
RUN_ID: ${{ github.run_id }}
JOB_ID: ${{ job.check_run_id }}
STEP_REGEX: build-.*
JOB_REGEX: compile \((?<osName>.+?), (?<osVersion>.+?), (?<config>.+?), (?<cppVersion>.+?), (?<vendorName>.+?), (?<vendorVersion>.+?)\)
ROW_HEADERS: '["osName","osVersion","vendorName","vendorVersion","config"]'
COLUMN_HEADER: cppVersion
4 changes: 3 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ inputs:
required: true
JOB_REGEX:
required: true
# Picks the step to link to when the marker's output does not carry the
# step's number
STEP_REGEX:
required: true
required: false
ROW_HEADERS:
required: true
COLUMN_HEADER:
Expand Down
32 changes: 21 additions & 11 deletions action/dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion action/dist/index.js.map

Large diffs are not rendered by default.

13 changes: 4 additions & 9 deletions action/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { graphql } from "@octokit/graphql";

import { decideCommentAction } from "./comment.ts";
import { scanJobLog } from "./scan.ts";
import { locateStep } from "./step.ts";
import { headSha, renderTrailer } from "./trailer.ts";

if (!process.env.GITHUB_REF?.startsWith("refs/pull/")) {
Expand Down Expand Up @@ -32,7 +33,7 @@ const pullRequestNumber = parseInt(githubRef.split("/")[2]);
const ignoreNoMarker = requireEnv("INPUT_IGNORE_NO_MARKER") === "true";

const jobRegex = requireEnv("INPUT_JOB_REGEX");
const stepRegex = requireEnv("INPUT_STEP_REGEX");
const stepRegex = process.env.INPUT_STEP_REGEX || undefined;

const workerUrl = requireEnv("INPUT_WORKER_URL");

Expand Down Expand Up @@ -77,18 +78,12 @@ for (const job of jobList.jobs) {
}
const jobLog = await response.text();

const { hasMarker, status: compileResult, firstIssueLine, issue } = scanJobLog(jobLog);
const { hasMarker, status: compileResult, firstIssueLine, issue, markerStep } = scanJobLog(jobLog);
if (!hasMarker && ignoreNoMarker) continue;
console.log(`${compileResult} at line ${firstIssueLine}${issue === undefined ? "" : `: ${issue}`}`);

const steps = job.steps ?? [];
const stepIndex = steps.findIndex(
(step) =>
step.name.match(stepRegex) &&
step.status === "completed" &&
step.conclusion === "success",
);
const stepId = (stepIndex === -1 ? steps.length : stepIndex) + 1;
const stepId = locateStep(steps, markerStep, stepRegex) ?? steps.length + 1;

console.log(`stepId is ${stepId}`);
console.log(`job name is "${job.name}"`);
Expand Down
52 changes: 51 additions & 1 deletion action/src/scan.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ describe("scanJobLog", () => {
"[100%] Built target test",
),
);
assert.deepEqual(result, { hasMarker: true, status: statuses.success, firstIssueLine: 1, issue: undefined });
assert.deepEqual(result, {
hasMarker: true,
status: statuses.success,
firstIssueLine: 1,
issue: undefined,
markerStep: undefined,
});
});

it("reports an error after the marker by its line in the step", () => {
Expand All @@ -41,6 +47,7 @@ describe("scanJobLog", () => {
status: statuses.error,
firstIssueLine: 7,
issue: "2026-11-19T01:00:00.0000000Z foo.cpp(2,3): error C2131: expression did not evaluate to a constant",
markerStep: undefined,
});
});

Expand All @@ -51,6 +58,7 @@ describe("scanJobLog", () => {
status: statuses.warning,
firstIssueLine: 7,
issue: "2026-11-19T01:00:00.0000000Z b.cpp:2:2: warning: y",
markerStep: undefined,
});
});

Expand All @@ -61,6 +69,7 @@ describe("scanJobLog", () => {
status: statuses.warning,
firstIssueLine: 2,
issue: "2026-11-19T01:00:00.0000000Z a.cpp:1:1: warning: y",
markerStep: undefined,
});
});

Expand All @@ -71,6 +80,47 @@ describe("scanJobLog", () => {
status: statuses.error,
firstIssueLine: 5,
issue: "2026-11-19T01:00:00.0000000Z a.cpp:1:1: error: x",
markerStep: undefined,
});
});

it("reads the step number the marker's output carries", () => {
const result = scanJobLog(
log(
'##[group]Run echo "CPPWARNINGNOTIFIER_LOG_MARKER $(gh api ...)"',
'echo "CPPWARNINGNOTIFIER_LOG_MARKER $(gh api ...)"',
"##[endgroup]",
"CPPWARNINGNOTIFIER_LOG_MARKER 4",
"a.cpp:1:1: warning: y",
),
);
assert.deepEqual(result, {
hasMarker: true,
status: statuses.warning,
firstIssueLine: 5,
issue: "2026-11-19T01:00:00.0000000Z a.cpp:1:1: warning: y",
markerStep: 4,
});
});

it("has no step number when the marker's output carries none", () => {
// What the marker line prints when the command that looks up the step number fails.
const result = scanJobLog(
log(
'##[group]Run echo "CPPWARNINGNOTIFIER_LOG_MARKER $(gh api ...)"',
'echo "CPPWARNINGNOTIFIER_LOG_MARKER $(gh api ...)"',
'echo "warning: in the script"',
"##[endgroup]",
"CPPWARNINGNOTIFIER_LOG_MARKER ",
"a.cpp:1:1: error: x",
),
);
assert.deepEqual(result, {
hasMarker: true,
status: statuses.error,
firstIssueLine: 6,
issue: "2026-11-19T01:00:00.0000000Z a.cpp:1:1: error: x",
markerStep: undefined,
});
});
});
14 changes: 9 additions & 5 deletions action/src/scan.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { statuses } from "./comment.ts";

const marker = "CPPWARNINGNOTIFIER_LOG_MARKER";
// The marker printed by the step, as opposed to the runner's echo of the step's script that contains it.
const markerOutputRegex = new RegExp(`^(\\S+ )?${marker}\\r?$`);
// The marker printed by the step, as opposed to the runner's echo of the step's script that contains it. The step
// may append its own step number, which it looks up through the API while it runs.
const markerOutputRegex = new RegExp(`^(\\S+ )?${marker}(?: +(\\d+))? *\\r?$`);

const warningRegex = /warning( .\d+)?:/;
const errorRegex = /error( .\d+)?:/;
Expand All @@ -13,6 +14,7 @@ export interface LogScan {
// 1-based, counted from the first line that mentions the marker, which starts the step that prints it.
readonly firstIssueLine: number;
readonly issue: string | undefined;
readonly markerStep: number | undefined;
}

// Looks for compiler warnings and errors after the marker's output, so that earlier steps, including the runner's
Expand All @@ -25,6 +27,8 @@ export function scanJobLog(jobLog: string): LogScan {
const offset = hasMarker ? stepStart : 0;
const markerOutput = hasMarker ? lines.findIndex((line, i) => i > stepStart && markerOutputRegex.test(line)) : -1;
const searchStart = markerOutput !== -1 ? markerOutput + 1 : offset;
const markerStepText = markerOutput !== -1 ? markerOutputRegex.exec(lines[markerOutput])?.[2] : undefined;
const common = { hasMarker, markerStep: markerStepText === undefined ? undefined : parseInt(markerStepText) };

const find = (regex: RegExp) => {
const i = lines.slice(searchStart).findIndex((line) => regex.test(line));
Expand All @@ -33,11 +37,11 @@ export function scanJobLog(jobLog: string): LogScan {

const warningIdx = find(warningRegex);
if (warningIdx !== -1) {
return { hasMarker, status: statuses.warning, firstIssueLine: warningIdx - offset + 1, issue: lines[warningIdx] };
return { ...common, status: statuses.warning, firstIssueLine: warningIdx - offset + 1, issue: lines[warningIdx] };
}
const errorIdx = find(errorRegex);
if (errorIdx !== -1) {
return { hasMarker, status: statuses.error, firstIssueLine: errorIdx - offset + 1, issue: lines[errorIdx] };
return { ...common, status: statuses.error, firstIssueLine: errorIdx - offset + 1, issue: lines[errorIdx] };
}
return { hasMarker, status: statuses.success, firstIssueLine: 1, issue: undefined };
return { ...common, status: statuses.success, firstIssueLine: 1, issue: undefined };
}
43 changes: 43 additions & 0 deletions action/src/step.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import assert from "node:assert/strict";
import { describe, it } from "node:test";

import { locateStep, type Step } from "./step.ts";

const step = (number: number, name: string, conclusion = "success"): Step => ({
number,
name,
status: "completed",
conclusion,
});

const steps = [
step(1, "Set up job"),
step(2, "Run actions/checkout@v7"),
step(3, "Build Deps"),
step(4, "Build Tests"),
step(8, "Post Run actions/checkout@v7"),
step(9, "Complete job"),
];

describe("locateStep", () => {
it("takes the step number the marker carries over STEP_REGEX", () => {
assert.equal(locateStep(steps, 4, "Build .+"), 4);
assert.equal(locateStep(steps, 4, undefined), 4);
});

it("falls back to STEP_REGEX for a number that is not a step of the job", () => {
assert.equal(locateStep(steps, 5, "Build Tests"), 4);
});

it("falls back to the first successful step matching STEP_REGEX, by its number", () => {
assert.equal(locateStep(steps, undefined, "Build .+"), 3);
assert.equal(locateStep(steps, undefined, "Post .+"), 8);
const failed = [step(3, "Build Deps", "failure"), step(4, "Build Tests")];
assert.equal(locateStep(failed, undefined, "Build .+"), 4);
});

it("returns undefined when neither the marker nor STEP_REGEX decides", () => {
assert.equal(locateStep(steps, undefined, undefined), undefined);
assert.equal(locateStep(steps, undefined, "no-such-step"), undefined);
});
});
21 changes: 21 additions & 0 deletions action/src/step.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// The fields of a job's step, as the GitHub REST API returns them, that locateStep reads.
export interface Step {
readonly number: number;
readonly name: string;
readonly status: string;
readonly conclusion: string | null;
}

// Returns the number of the step to link to: the one the marker carries, or else the first successful step
// matching stepRegex.
export function locateStep(
steps: readonly Step[],
markerStep: number | undefined,
stepRegex: string | undefined,
): number | undefined {
if (markerStep !== undefined && steps.some((step) => step.number === markerStep)) return markerStep;
if (stepRegex === undefined) return undefined;
return steps.find(
(step) => step.name.match(stepRegex) !== null && step.status === "completed" && step.conclusion === "success",
)?.number;
}