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
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ jobs:

report:
needs: [lint, run]
if: always() && github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
if: always() && (github.event_name == 'workflow_dispatch' || github.event.pull_request.head.repo.full_name == github.repository)
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
Expand Down Expand Up @@ -298,7 +298,7 @@ explicitly instead of discovering the baseline artifact by `baseline-report-id`
| Omitted / `all` | Validate inputs, lint, run after successful lint, publish evidence, and update the PR comment. |
| `lint` | Native whole-project lint. No selector or model credentials needed. Publishes a summary and artifact, without commenting. |
| `run` | Native `vally eval --require-pass --output=jsonl ...`. Requires a suite, eval paths or tags. Publishes a summary and artifact, without commenting. |
| `report` | Verify structured artifacts and update the sticky comment. Never installs Vally or runs a model. PR events only. |
| `report` | Verify structured artifacts and write the report to the job summary. On pull requests, also update the sticky comment; on push and manual dispatch, no PR APIs are called. Never installs Vally or runs a model. |
| `plan` | Reserved and unsupported; fails explicitly, never runs an eval. |

Native arguments are separate argv values, never interpolated shell commands.
Expand All @@ -317,7 +317,7 @@ explicit lint rejects execution overrides.
| `suite` | Native suite for all/run; mutually exclusive with paths/tags. |
| `eval-paths` | Newline-separated literal paths for all/run. Spaces are preserved. No shell expansion. |
| `tags` | Newline-separated native filters for all/run, e.g. `cost=free` or `flaky!=yes`. |
| `github-token` | Defaults to `${{ github.token }}`. Used for model auth and PR reporting in all; artifact discovery and commenting in report; not forwarded in explicit lint/run. Discovery requires `actions: read`. |
| `github-token` | Defaults to `${{ github.token }}`. Used for model auth and PR reporting in all; artifact discovery and PR commenting in report; not forwarded in explicit lint/run. Discovery requires `actions: read`. |
| `copilot-token` | Optional explicit model token. Overrides automatic model auth in all; supports workflow-token auth in explicit run. |
| `credential-env` | Advanced evaluator credential variable names, one per line, for BYOK/custom providers. Supplying these disables automatic model-token injection in all. Never put values here. Cannot list `COPILOT_GITHUB_TOKEN` with `copilot-token`. |
| `report-token` | Optional bot/App comment token override for all/report. Discovery uses `github-token`, falling back to this token if absent. Human/PAT reporters are refused. Not valid on explicit lint/run. |
Expand Down Expand Up @@ -443,7 +443,9 @@ and its SHA-256 digests, or uses explicit ID/digest pairs. It downloads the
selected artifacts itself, verifies digests and current
repository/revision/run/attempt identity, and accepts only a bounded
`report.json`. A companion must be successful lint from the same run/revision,
but it can originate in a separate lint job.
but it can originate in a separate lint job. On push and `workflow_dispatch`,
report mode writes the verified report to the job summary without looking up a
pull request or calling comment APIs.

## Example skill and eval

Expand Down
4 changes: 2 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ description: Acquire Vally and run native lint or evaluations with structured Gi
author: GitHub
inputs:
command:
description: Default all validates, lints, runs the selected evals, and updates one PR comment. Use lint, run, or report for separate jobs. Plan is unsupported.
description: Default all validates, lints, runs the selected evals, and updates one PR comment. Report verifies evidence and writes a job summary on pull_request, push, and workflow_dispatch; only pull_request updates a PR comment. Plan is unsupported.
default: all
github-token:
description: Automatic job token for Copilot and PR commenting in all mode, or artifact discovery and commenting in report mode. Discovery requires actions read. The all job token has combined permissions; use separate commands for isolation.
description: Automatic job token for Copilot and PR commenting in all mode, or artifact discovery and PR commenting in report mode. Discovery requires actions read. The all job token has combined permissions; use separate commands for isolation.
default: ${{ github.token }}
working-directory:
description: Project directory relative to checkout. Required for all/lint/run; omitted for report.
Expand Down
2 changes: 1 addition & 1 deletion dist/index.cjs

Large diffs are not rendered by default.

49 changes: 40 additions & 9 deletions src/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import { join } from 'node:path';
import { parseInputs, type Inputs } from './inputs.js';
import { assertRevision, containedFile, eventEligibility, inertEnvironment, object, projectDirectory } from './policy.js';
import { NativeError, nativeArguments, nativeEnvironment, runNative } from './native.js';
import { parseStructuredReport, renderSummary, structuredReport, type Report } from './reporting.js';
import { parseStructuredReport, renderReport, renderRunDiagnostics, structuredReport, type Report } from './reporting.js';
import { githubClient, ReportingError, takeReportToken, takeSecretInput } from './github.js';
import { postReport } from './reporter.js';
import { assertReportEvidence, postReport } from './reporter.js';
import { acquireEngine, resolveRelease, sha256 } from './tooling.js';
import { discoverReportArtifacts, reportArtifactName, type ReportArtifact } from './artifacts.js';

Expand Down Expand Up @@ -47,11 +47,16 @@ export async function runAction(): Promise<void> {
core.warning('Fork pull requests are excluded. No evaluator, installer, or commenter was started.');
Object.assign(report, { outcome: 'not-run', category: 'policy', code: 'fork-execution-excluded', executed: 0 });
publishOutputs(report);
await core.summary.addRaw(renderSummary(report)).write();
let artifactId: number | undefined;
if (!reportMode) {
try { publishArtifactOutputs(await uploadReport(report, 7)); }
try {
const artifact = await uploadReport(report, 7);
artifactId = artifact.id;
publishArtifactOutputs(artifact);
}
catch { core.setFailed('Required structured reporting failed: artifact upload did not complete.'); }
}
await writeSummary(report, artifactId);
return;
}
if (process.env.GITHUB_EVENT_NAME === 'pull_request') {
Expand All @@ -68,7 +73,6 @@ export async function runAction(): Promise<void> {
Object.keys(inputs.overrides).length || inputs.uploadTranscripts || inputs.workingDirectory) {
throw new NativeError('report-command-does-not-accept-execution-inputs', 'configuration');
}
if (pullNumber === undefined) throw new NativeError('report-command-requires-pull-request', 'policy');
let primary: { id: number; digest: string; reportId: string | readonly string[]; command?: 'lint' | 'run' };
let discoveredLint: ReportArtifact | undefined;
if (inputs.sourceArtifactId !== undefined && inputs.sourceArtifactDigest) {
Expand Down Expand Up @@ -124,9 +128,16 @@ export async function runAction(): Promise<void> {
};
}
}
await commentReport(imported, reportToken || githubToken, pullNumber, primary.id, companion, baseline);
assertReportEvidence(reportPrefix(inputs.reportId), imported, primary.id, companion, baseline);
publishOutputs(imported);
await core.summary.addRaw(renderSummary(imported, baseline?.report)).write();
if (pullNumber !== undefined) {
try {
await commentReport(imported, reportToken || githubToken, pullNumber, primary.id, companion, baseline);
} catch (error) {
core.setFailed(`Evals PR reporting failed: ${error instanceof NativeError ? error.code : 'comment-reporting-failed'}.`);
}
}
await writeSummary(imported, primary.id, companion, baseline);
return;
}

Expand Down Expand Up @@ -213,8 +224,10 @@ export async function runAction(): Promise<void> {
}
if (report.code === 'native-empty-selection') core.warning('Native evidence reports zero executed trials. This is not an evaluation pass.');
publishOutputs(report);
await core.summary.addRaw(renderSummary(report)).write();
if (reportMode) return;
if (reportMode) {
await writeSummary(report);
return;
}
if (nativeDirectory) core.setOutput('native-diagnostics-path', nativeDirectory);
let artifactId: number | undefined;
try {
Expand All @@ -224,6 +237,7 @@ export async function runAction(): Promise<void> {
} catch {
core.setFailed('Required structured reporting failed: artifact upload did not complete.');
}
await writeSummary(report, artifactId, report.command === 'run' ? companion : undefined);
if (allMode && pullNumber !== undefined) {
try {
await commentReport(report, reportToken || githubToken, pullNumber, artifactId, companion);
Expand Down Expand Up @@ -270,6 +284,23 @@ async function commentReport(
}
}

async function writeSummary(
report: Report, artifactId?: number, companion?: Evidence, baseline?: Evidence,
): Promise<void> {
const runUrl = `https://github.com/${report.repository}/actions/runs/${report.workflowRunId}`;
const body = renderReport(report, {
runUrl,
...(artifactId !== undefined ? { artifactId } : {}),
...(companion ? { companion } : {}),
...(baseline ? { baseline } : {}),
}) + renderRunDiagnostics(report);
try {
await core.summary.addRaw(body).write();
} catch {
core.warning('Job summary write failed. The report outcome is unchanged.');
}
}

async function verifyCheckout(cwd: string): Promise<void> {
const revision = await execute('git', ['-C', cwd, 'rev-parse', 'HEAD'], {
env: inertEnvironment(process.env), timeout: 10_000, maxBuffer: 4096,
Expand Down
130 changes: 43 additions & 87 deletions src/reporter.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { parseDocument } from 'yaml';
import { commentMarker, orderedBody, selectComment, type Comment, type CommentIdentity, type ReportOrder } from './comments.js';
import { object } from './policy.js';
import {
escapeMarkdown, hasQualityDetails, renderComparisonSection, renderQualitySection, renderVerdictSummaryTable,
type Report,
} from './reporting.js';
import { renderReport, type Report } from './reporting.js';
import { ReportingError, type GitHubClient } from './github.js';

export const commentConcurrencyGroup = 'evals-${{ github.workflow_ref }}';
Expand All @@ -25,6 +22,40 @@ function positive(value: unknown): number {
return value;
}

export function assertReportEvidence(
reportId: string, report: Report, artifactId?: number,
companion?: { report: Report; artifactId: number },
baseline?: { report: Report; artifactId: number },
): void {
if (report.reportId.replace(/-(?:lint|run)$/, '') !== reportId ||
(companion && (report.command !== 'run' || companion.report.command !== 'lint' ||
![report.reportId, reportId, `${reportId}-lint`].includes(companion.report.reportId) ||
companion.report.outcome !== 'validated' ||
companion.report.repository !== report.repository ||
companion.report.revision !== report.revision ||
companion.report.workflowRunId !== report.workflowRunId ||
companion.report.workflowRunAttempt !== report.workflowRunAttempt)) ||
(baseline && (report.command !== 'run' || baseline.report.command !== 'run' ||
baseline.report.reportId.replace(/-(?:lint|run)$/, '') === reportId ||
baseline.report.repository !== report.repository ||
baseline.report.revision !== report.revision ||
baseline.report.workflowRunId !== report.workflowRunId ||
baseline.report.workflowRunAttempt !== report.workflowRunAttempt))) {
throw new ReportingError('inconsistent-report-evidence');
}
if (artifactId !== undefined) positive(artifactId);
if (companion) {
positive(companion.artifactId);
if (companion.artifactId === artifactId) throw new ReportingError('inconsistent-report-evidence');
}
if (baseline) {
positive(baseline.artifactId);
if (baseline.artifactId === artifactId || baseline.artifactId === companion?.artifactId) {
throw new ReportingError('inconsistent-report-evidence');
}
}
}

function workflowPath(context: CommentContext): string {
if (!/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/.test(context.repository) || !/^[a-f0-9]{40}$/.test(context.workflowSha)) {
throw new ReportingError('invalid-workflow-identity');
Expand Down Expand Up @@ -86,33 +117,7 @@ export async function postReport(
): Promise<'created' | 'updated' | 'stale'> {
positive(context.pullNumber); positive(context.runId);
if (!/^[a-f0-9]{40}$/.test(report.revision)) throw new ReportingError('invalid-report-revision');
if (artifactId !== undefined) positive(artifactId);
if (report.reportId.replace(/-(?:lint|run)$/, '') !== context.reportId ||
(companion && (report.command !== 'run' || companion.report.command !== 'lint' ||
![report.reportId, context.reportId, `${context.reportId}-lint`].includes(companion.report.reportId) ||
companion.report.outcome !== 'validated' ||
companion.report.repository !== report.repository ||
companion.report.revision !== report.revision ||
companion.report.workflowRunId !== report.workflowRunId ||
companion.report.workflowRunAttempt !== report.workflowRunAttempt)) ||
(baseline && (report.command !== 'run' || baseline.report.command !== 'run' ||
baseline.report.reportId.replace(/-(?:lint|run)$/, '') === context.reportId ||
baseline.report.repository !== report.repository ||
baseline.report.revision !== report.revision ||
baseline.report.workflowRunId !== report.workflowRunId ||
baseline.report.workflowRunAttempt !== report.workflowRunAttempt))) {
throw new ReportingError('inconsistent-report-evidence');
}
if (companion) {
positive(companion.artifactId);
if (companion.artifactId === artifactId) throw new ReportingError('inconsistent-report-evidence');
}
if (baseline) {
positive(baseline.artifactId);
if (baseline.artifactId === artifactId || baseline.artifactId === companion?.artifactId) {
throw new ReportingError('inconsistent-report-evidence');
}
}
assertReportEvidence(context.reportId, report, artifactId, companion, baseline);
const path = workflowPath(context);
const source = object(await client.request('GET', `/repos/${context.repository}/contents/${path}?ref=${context.workflowSha}`));
if (source.encoding !== 'base64' || typeof source.content !== 'string' || source.content.length > 1_500_000) {
Expand Down Expand Up @@ -140,8 +145,13 @@ export async function postReport(
const decision = selectComment(comments, identity, context.order, author);
if (decision.action === 'stale') return 'stale';
const run = `https://github.com/${context.repository}/actions/runs/${context.runId}`;
const summary = renderComment(report, artifactId, companion, run, baseline);
const body = orderedBody(identity, context.order, summary +
const reportBody = renderReport(report, {
runUrl: run,
...(artifactId !== undefined ? { artifactId } : {}),
...(companion ? { companion } : {}),
...(baseline ? { baseline } : {}),
});
const body = orderedBody(identity, context.order, reportBody +
`\n[Exact revision](https://github.com/${context.repository}/commit/${report.revision}) | [Workflow run](${run})` +
'\n');
if (Buffer.byteLength(body, 'utf8') > 60_000) throw new ReportingError('report-comment-too-large');
Expand All @@ -164,57 +174,3 @@ export async function postReport(
}
return decision.action === 'create' ? 'created' : 'updated';
}

export function renderComment(
report: Report, artifactId: number | undefined, companion: { report: Report; artifactId: number } | undefined, run: string,
baseline?: { report: Report; artifactId: number },
): string {
const lint = companion?.report ?? (report.command === 'lint' ? report : undefined);
const evaluation = report.command === 'run' ? report : undefined;
const status = evaluation?.outcome ?? lint?.outcome ?? report.outcome;
const rows = evaluation?.groups ?? [];
const suite = evaluation?.suite;
const maxEvalRows = baseline ? 25 : 100;
const detailsBody =
(suite ? `**Suite:** ${escapeMarkdown(suite)}\n\n` : evaluation ? '**Selection:** Native eval paths or tags\n\n' : '') +
(lint ? `**Lint:** ${lint.outcome}${lint.outcome === 'validated' ? ' (no model execution)' : ` - ${escapeMarkdown(lint.code)}`}` +
((companion?.artifactId ?? artifactId) !== undefined ? ` - [Evidence](${run}/artifacts/${companion?.artifactId ?? artifactId})` : '') + '\n\n' : '') +
(evaluation ? `**Run:** ${evaluation.outcome} - ${evaluation.executed ?? 'unknown'} ${evaluation.executed === 1 ? 'trial' : 'trials'}` +
(artifactId !== undefined ? ` - [Evidence](${run}/artifacts/${artifactId})` : '') + '\n\n' +
(baseline ? `**Baseline:** ${baseline.report.outcome} - ${baseline.report.executed ?? 'unknown'} ${baseline.report.executed === 1 ? 'trial' : 'trials'} - [Evidence](${run}/artifacts/${baseline.artifactId})\n\n` : '') +
(['error', 'failed', 'cancelled'].includes(evaluation.outcome) ? `Diagnostic: ${escapeMarkdown(evaluation.code)}.\n\n` : '') +
(evaluation.outcome === 'not-run' ? '**Not an evaluation pass.**\n\n' : '') +
(rows.length ? '| Eval | Trials | Result |\n| --- | ---: | --- |\n' +
rows.slice(0, maxEvalRows).map((group) =>
`| ${escapeMarkdown(group.name ?? group.identity.slice(0, 12))} | ${group.trials} | ${group.trials ? group.passed ? 'passed' : 'failed' : 'not-run'} |`,
).join('\n') + '\n\n' +
(rows.length > maxEvalRows ? `${rows.length - maxEvalRows} further groups are in the structured artifact.\n\n` : '') : '') : '');
if (!evaluation) return `# Evals: ${status}\n\n${detailsBody}`;
if (!baseline) {
let output = `# Evals: ${status}\n\n${detailsBody}`;
if (rows.length && hasQualityDetails(rows)) {
const maxQualityBytes = Math.min(16_000, Math.max(0, 57_500 - Buffer.byteLength(output, 'utf8')));
const quality = renderQualitySection('### Quality & token summary', rows, 25, maxQualityBytes);
if (quality) output = `${output}${quality}\n\n`;
}
return output;
}

const { overallVerdict, markdown: verdictTable } = renderVerdictSummaryTable(baseline.report, evaluation, 25);
const header = `# Evals: ${overallVerdict} (${status})\n\n` +
(verdictTable ? `${verdictTable}\n\n` : '') +
(['error', 'failed', 'cancelled'].includes(evaluation.outcome) ? `Diagnostic: ${escapeMarkdown(evaluation.code)}.\n\n` : '') +
(evaluation.outcome === 'not-run' ? '**Not an evaluation pass.**\n\n' : '');

let telemetry = detailsBody;
if (rows.length && hasQualityDetails(rows)) {
const maxQualityBytes = Math.min(16_000, Math.max(0, 56_000 - Buffer.byteLength(header + telemetry, 'utf8')));
const quality = renderQualitySection('### Quality & token summary', rows, 25, maxQualityBytes);
if (quality) telemetry = `${telemetry}${quality}\n\n`;
}
const maxComparisonBytes = Math.min(16_000, Math.max(0, 56_000 - Buffer.byteLength(header + telemetry, 'utf8')));
const comparison = renderComparisonSection('### Baseline vs. Candidate comparison', baseline.report, evaluation, 25, maxComparisonBytes, overallVerdict);
if (comparison) telemetry = `${telemetry}${comparison}\n\n`;

return `${header}<details>\n<summary>📊 <strong>Telemetry, token deltas &amp; run evidence</strong></summary>\n\n${telemetry.trim()}\n\n</details>\n\n`;
}
Loading
Loading