Skip to content
Open
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
70 changes: 63 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,48 @@ may access that token. This is convenient, not credential isolation. Use only
trusted reviewed sources, grant no unnecessary permissions, and use separate
commands/jobs below when you need a narrower model token.

## Running after another workflow

The following lint-only example checks out the commit from a successful `CI`
push to `main`. Replace `CI` with the name of an existing workflow and `evals`
with your project directory. The `workflow_run` workflow file must exist on the
default branch.

```yaml
name: Evals after CI
on:
workflow_run:
workflows: [CI]
types: [completed]
branches: [main]

permissions:
contents: read

jobs:
lint:
if: >-
github.event.workflow_run.conclusion == 'success' &&
github.event.workflow_run.event == 'push' &&
github.event.workflow_run.head_repository.full_name == github.repository
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
with:
ref: ${{ github.event.workflow_run.head_sha }}
persist-credentials: false
- uses: github/evals-action@v0
with:
command: lint
working-directory: evals
```

This example evaluates a same-repository push, not a PR. For PR-triggered
workflows, establish the intended source and revision using trusted GitHub data
before checkout. `workflow_run` does not itself make executed code trusted,
even for lint; configure approvals and permissions accordingly. Results appear
in the job summary and artifacts, not a PR comment.

## Advanced: separate jobs and permissions

The **same Action** can be used in separate jobs. There is no custom verdict
Expand Down Expand Up @@ -249,7 +291,8 @@ Providing the primary ID/digest pair bypasses discovery entirely; it reports
only that artifact and any explicitly supplied lint companion, preserving
existing workflows without requiring `actions: read`. Alternatively, supply
only the lint ID/digest pair to override lint while discovering run evidence.
Overrides still undergo digest and repository/revision/run/attempt checks.
Overrides still undergo digest and repository/run/attempt checks; combined
reports must also agree on checkout revision.
Artifacts uploaded by older Action versions require explicit IDs/digests.

### Baseline vs. Candidate PR comparison
Expand Down Expand Up @@ -298,7 +341,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 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. |
| `report` | Verify structured artifacts and write the report to the job summary. On pull requests, also update the sticky comment; other events do not call PR APIs. 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 Down Expand Up @@ -375,11 +418,24 @@ owned process group; hard job cancellation may prevent artifacts/comments.
## Trust and authentication

Use trusted reviewed evals and select your own triggers/approval policy.
Fork PRs and `pull_request_target` are excluded before acquisition. Native lint
Fork `pull_request` events and `pull_request_target` are excluded before acquisition. Native lint
can load executable plugins; run can invoke setup scripts, graders, providers
and model tools. Environment filtering is not an OS sandbox. The Action
verifies checkout revision before execution, but this does not prove that
workflow preparation left every working file unchanged.
records the checkout HEAD and checks that it remains unchanged before execution,
but this does not prove that workflow preparation left every working file unchanged.

The caller selects the trigger and checkout. For `workflow_run`, `GITHUB_SHA`
identifies the workflow's default-branch context and need not be the evaluated
revision. Check out the intended commit explicitly; the report records that
checkout's HEAD. The Action does not authenticate the triggering run, PR, or
revision, and does not comment on PRs for `workflow_run`. If provenance matters,
validate it in the caller using trusted GitHub data, not artifact claims alone.
For `pull_request` events, PR comment publication additionally requires the
reported checkout revision to match the current PR head or merge revision.
Configure protected environment approvals and minimum job permissions, including
`copilot-requests: write` for workflow-token model use and `actions: read` for
artifact discovery. Executing untrusted code can expose credentials and network
access even after approval; use isolated jobs and trusted inputs.

All mode deliberately shares the job token between Copilot and PR reporting.
The Action cannot remove a token's permissions. Separate jobs are an optional
Expand Down Expand Up @@ -441,9 +497,9 @@ mutually exclusive. Separate reporting jobs must use the same concurrency group.
Report mode discovers artifacts using the authenticated current-run listing
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
repository/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. On push and `workflow_dispatch`,
but it can originate in a separate lint job. On events other than `pull_request`,
report mode writes the verified report to the job summary without looking up a
pull request or calling comment APIs.

Expand Down
11 changes: 8 additions & 3 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@ The Action invokes the acquired Vally CLI directly. Use only trusted,
reviewed workflows and evaluation sources. Native project configuration can
load executable plugins, including during lint; lint does not run subjects or
judges, but it is not a sandbox. Native run may execute project setup, providers,
executors and graders. Fork jobs and `pull_request_target` are excluded.
executors and graders. Fork `pull_request` jobs and `pull_request_target` are excluded.

The checkout revision is checked before acquisition and again before execution.
The caller selects the checkout; its HEAD is recorded before acquisition and
checked again before execution, not compared to `GITHUB_SHA`. For `workflow_run`,
the caller must authenticate source run and revision provenance when needed;
artifacts alone do not establish it.
Workflow preparation can still intentionally change files in that checkout;
the reported Git revision is not a claim that all working files are unchanged.
The default `all` step, or an explicit `run` step, is the team's execution
Expand Down Expand Up @@ -59,7 +62,9 @@ For stronger separation, use the same Action in independent lint, run, and
report jobs. Grant the run job only contents read and Copilot permission; grant
the report job contents read and PR-write, but no Copilot permission. Explicit
run rejects `report-token`. Reporting downloads and digest-verifies the current
run's structured artifacts and checks repository/revision/run/attempt identity.
run's structured artifacts and checks repository/run/attempt identity and
revision consistency across combined reports. PR comments additionally validate
the reported revision against the current PR.
It never invokes Vally. Separate jobs reduce evaluator access to PR-write
authority; they are optional, not a platform requirement.

Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ 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. 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.
description: Default all validates, lints, and runs the selected evals. All and report update a PR comment on pull_request; other events use the job summary. Report verifies evidence without running evals. Plan is unsupported.
default: all
github-token:
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.
Expand Down
2 changes: 1 addition & 1 deletion dist/index.cjs

Large diffs are not rendered by default.

30 changes: 20 additions & 10 deletions src/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { promisify } from 'node:util';
import { lstat, mkdir, mkdtemp, readFile, readdir, rm, writeFile } from 'node:fs/promises';
import { join } from 'node:path';
import { parseInputs, type Inputs } from './inputs.js';
import { assertRevision, containedFile, eventEligibility, inertEnvironment, object, projectDirectory } from './policy.js';
import { checkoutRevision, containedFile, eventEligibility, inertEnvironment, object, projectDirectory } from './policy.js';
import { NativeError, nativeArguments, nativeEnvironment, runNative } from './native.js';
import { parseStructuredReport, renderReport, renderRunDiagnostics, structuredReport, type Report } from './reporting.js';
import { githubClient, ReportingError, takeReportToken, takeSecretInput } from './github.js';
Expand All @@ -30,7 +30,7 @@ export async function runAction(): Promise<void> {
workflowRunId: Number(process.env.GITHUB_RUN_ID ?? 0), workflowRunAttempt: Number(process.env.GITHUB_RUN_ATTEMPT ?? 0),
sourceJob: process.env.GITHUB_JOB ?? 'unknown', selection: '0'.repeat(64),
command: allMode ? 'lint' : requestedCommand, outcome: 'error', completeness: 'unknown',
revision: /^[a-f0-9]{40}$/.test(process.env.GITHUB_SHA ?? '') ? process.env.GITHUB_SHA! : 'unknown',
revision: 'unknown',
Comment thread
wbreza marked this conversation as resolved.
Resolved
category: 'configuration', code: 'invalid-input-or-context',
};
let inputs: Inputs | undefined;
Expand Down Expand Up @@ -94,7 +94,9 @@ export async function runAction(): Promise<void> {
} else throw new NativeError('report-artifacts-not-found', 'evidence');
}
const imported = await readReportArtifact(primary.id, primary.digest, primary.reportId, primary.command);
if (inputs.lintArtifactId !== undefined && primary.command !== 'lint') {
if (imported.revision === 'unknown') {
core.warning('The checkout revision is unknown; lint and baseline evidence cannot be combined with this report.');
} else if (inputs.lintArtifactId !== undefined && primary.command !== 'lint') {
if (!inputs.lintArtifactDigest) throw new NativeError('lint-artifact-identity-required', 'configuration');
companion = {
report: await readReportArtifact(inputs.lintArtifactId, inputs.lintArtifactDigest,
Expand All @@ -107,7 +109,7 @@ export async function runAction(): Promise<void> {
artifactId: discoveredLint.id,
};
}
if (imported.command === 'run') {
if (imported.command === 'run' && imported.revision !== 'unknown') {
if (inputs.baselineArtifactId !== undefined && inputs.baselineArtifactDigest) {
const expectedBaselineId = inputs.baselineReportId
? [inputs.baselineReportId, reportPrefix(inputs.baselineReportId), `${reportPrefix(inputs.baselineReportId)}-run`]
Expand Down Expand Up @@ -146,7 +148,7 @@ export async function runAction(): Promise<void> {
core.warning('Lint scans all evals under working-directory. Suite, eval-paths and tags selectors are ignored for lint.');
}
const cwd = await projectDirectory(requiredEnv('GITHUB_WORKSPACE'), inputs.workingDirectory);
await verifyCheckout(cwd);
report.revision = await readCheckoutRevision(cwd);
Comment thread
wbreza marked this conversation as resolved.
Resolved
Comment thread
wbreza marked this conversation as resolved.
Resolved
nativeDirectory = await mkdtemp(join(requiredEnv('RUNNER_TEMP'), 'evals-native-'));
const home = join(nativeDirectory, 'home');
await mkdir(home, { mode: 0o700 });
Expand All @@ -168,7 +170,7 @@ export async function runAction(): Promise<void> {
version: engine.version, sha256: engine.sha256,
dependencySha256: engine.dependencySha256, lockSha256: engine.lockSha256,
};
await verifyCheckout(cwd);
await verifyCheckout(cwd, report.revision);
if (await projectDirectory(requiredEnv('GITHUB_WORKSPACE'), inputs.workingDirectory) !== cwd) {
throw new NativeError('project-directory-changed', 'policy');
}
Expand All @@ -189,7 +191,7 @@ export async function runAction(): Promise<void> {
core.setOutput('lint-artifact-digest', saved.digest);
report.category = 'policy';
report.code = 'checkout-revision-changed';
await verifyCheckout(cwd);
await verifyCheckout(cwd, report.revision);
if (await projectDirectory(requiredEnv('GITHUB_WORKSPACE'), inputs.workingDirectory) !== cwd) {
throw new NativeError('project-directory-changed', 'policy');
}
Expand Down Expand Up @@ -266,6 +268,10 @@ function reportPrefix(id: string): string { return id.replace(/-(?:lint|run)$/,
async function commentReport(
report: Report, token: string, pullNumber: number, artifactId?: number, companion?: Evidence, baseline?: Evidence,
): Promise<void> {
if (report.revision === 'unknown') {
core.warning('PR comment skipped because the checkout revision is unknown. See the job summary and structured artifact.');
return;
}
try {
const client = githubClient(token, requiredEnv('RUNNER_TEMP'));
const context = {
Expand Down Expand Up @@ -301,11 +307,15 @@ async function writeSummary(
}
}

async function verifyCheckout(cwd: string): Promise<void> {
async function readCheckoutRevision(cwd: string): Promise<string> {
const revision = await execute('git', ['-C', cwd, 'rev-parse', 'HEAD'], {
env: inertEnvironment(process.env), timeout: 10_000, maxBuffer: 4096,
});
assertRevision(revision.stdout, requiredEnv('GITHUB_SHA'));
return checkoutRevision(revision.stdout);
}

async function verifyCheckout(cwd: string, expected: string): Promise<void> {
if (await readCheckoutRevision(cwd) !== expected) throw new NativeError('checkout-revision-changed', 'policy');
}

async function uploadReport(report: Report, retentionDays: number): Promise<{ id: number; digest: string; path: string }> {
Expand Down Expand Up @@ -337,7 +347,7 @@ async function readReportArtifact(
const path = await containedFile(directory, 'report.json', 1024 * 1024);
const report = parseStructuredReport(await readFile(path, 'utf8'), {
reportId, repository: requiredEnv('GITHUB_REPOSITORY'), workflowRunId: positiveEnv('GITHUB_RUN_ID'),
workflowRunAttempt: positiveEnv('GITHUB_RUN_ATTEMPT'), revision: requiredEnv('GITHUB_SHA'),
workflowRunAttempt: positiveEnv('GITHUB_RUN_ATTEMPT'),
});
if (command !== undefined && report.command !== command) throw new NativeError('source-artifact-command-mismatch', 'evidence');
return report;
Expand Down
7 changes: 4 additions & 3 deletions src/policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ export function eventEligibility(eventName: string, payload: unknown, repository
}
return head.full_name === repository && head.fork === false ? 'eligible' : 'fork';
}
if (eventName !== 'push' && eventName !== 'workflow_dispatch') throw new Error('Unsupported workflow event.');
return 'eligible';
}

export function assertRevision(actual: string, expected: string): void {
if (!/^[a-f0-9]{40}$/.test(expected) || actual.trim() !== expected) throw new Error('Checkout revision does not match GITHUB_SHA.');
export function checkoutRevision(actual: string): string {
const revision = actual.trim();
if (!/^[a-f0-9]{40}$/.test(revision)) throw new Error('Checkout revision is not a commit SHA.');
return revision;
}

export async function projectDirectory(workspace: string, input: string): Promise<string> {
Expand Down
9 changes: 6 additions & 3 deletions src/reporting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export interface ReportExpectation {
repository: string;
workflowRunId: number;
workflowRunAttempt: number;
revision: string;
revision?: string;
}

export function escapeMarkdown(value: string): string {
Expand Down Expand Up @@ -670,11 +670,11 @@ export function parseStructuredReport(text: string, expected: ReportExpectation)
const repository = string(raw.repository, 'repository', /^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/);
const workflowRunId = positive(raw.workflowRunId, 'workflowRunId');
const workflowRunAttempt = positive(raw.workflowRunAttempt, 'workflowRunAttempt');
const revision = string(raw.revision, 'revision', /^[a-f0-9]{40}$/);
const revision = string(raw.revision, 'revision', /^(?:[a-f0-9]{40}|unknown)$/);
if (!(typeof expected.reportId === 'string' ? reportId === expected.reportId : expected.reportId.includes(reportId)) ||
repository !== expected.repository ||
workflowRunId !== expected.workflowRunId || workflowRunAttempt !== expected.workflowRunAttempt ||
revision !== expected.revision) {
(expected.revision !== undefined && revision !== expected.revision)) {
throw new Error('Structured report identity does not match the current workflow.');
}
const command = string(raw.command, 'command');
Expand All @@ -686,6 +686,9 @@ export function parseStructuredReport(text: string, expected: ReportExpectation)
const outcomes: Report['outcome'][] = ['error', 'not-run', 'validated', 'passed', 'failed', 'cancelled'];
const outcome = string(raw.outcome, 'outcome') as Report['outcome'];
if (!outcomes.includes(outcome)) throw new Error('Invalid structured report outcome.');
if (revision === 'unknown' && outcome !== 'error' && outcome !== 'not-run') {
throw new Error('A successful structured report requires a checkout revision.');
}
const completeness = string(raw.completeness, 'completeness') as Report['completeness'];
if (!['complete', 'partial', 'unknown'].includes(completeness)) throw new Error('Invalid structured report completeness.');
const category = string(raw.category, 'category') as Report['category'];
Expand Down
Loading
Loading