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
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,20 @@ Repository commands use the checkout’s `origin` by default. Use `--remote NAME

In GitHub Actions, `proofline ci review --annotations` prints unresolved findings as workflow annotations at verified cited lines. Findings without a verified head location appear on the job. The review link contains the full result.

A pull-request job can require the review to have checked a particular environment:

```sh
proofline ci review --require-environment production --fail-on serious
```

Use the environment's exact external key (`environment_external_key` in the review's `environments` array), not its display name. The final review response must contain exactly one entry with that key and state `CHECKED`. A staging-only or code-only review cannot satisfy a requirement for production. The command exits 2 with an explanation on stderr if evidence is missing, unreadable, duplicated or unchecked. If any entry has a malformed field used by this check, the requirement fails. A `CHECKED` entry that also records a reason it was not checked does not satisfy it either.

The existing review identity and completeness checks still run first. Only after the environment requirement is met does `--fail-on` apply, including its check for available finding counts. An unmet environment requirement therefore exits 2 even when findings would cause exit 3 or missing counts would cause exit 4. Without `--require-environment`, behaviour is unchanged. The option adds no API request and does not start a separate environment check.

With `--json`, the review document and its completeness `outcome` are unchanged. The command can therefore exit 2 even when the review says `COMPLETED`, just as it can exit 3 under `--fail-on`. Always read the process exit code. This option applies to pull-request reviews; it does not verify a deployment or establish that a change is safe.

See [who configures this check and what happens on a checkout pull request](docs/diagrams/required-environment.md).

For a CodePipeline execution or Amplify job, run `proofline ci deploy --commit SHA --aws-run ID` in a later pipeline. Add `--environment-id UUID` to select its Proofline environment. The output names the AWS provider and run ID. Proofline records successful CodePipeline executions and failed, stopped or cancelled ones it ties to the ECS rollout that served the commit. A reader inside a still-running execution finds no matching deploy, waits until its timeout and exits 2. On a GitHub `workflow_run` event, an explicit `--aws-run` disables the default Actions run and attempt filters.

`proofline ci deploy --until 1h` waits until Proofline has recorded the deploy checks of the job's commit through the hour check, then exits 0 when each recorded `HEALTHY` with no gap, 3 when a deploy failed or regressed, and 2 when the result is not established, including when a deploy reads a state this CLI version does not know. After a read that answered, the wait keeps reading through a read that fails in transport, times out or gets a 5xx answer, and exits 4 after five such failures in a row, naming the last error; the first read and a refusal end it at once. Without `--timeout`, a wait for `--until landing`, `--until 20m` or `--until 1h` lasts until that check is due for the selected deploys, and at least 30 minutes, so a landing check that reads the runtime again, up to 75 minutes after landing, is still read; `--until 1d` needs `--timeout`. `--environment-id` (the Proofline environment's UUID, the `environment_id` that `--json` prints for each deploy), `--environment` (the GitHub Environment name), `--task`, `--deployment` (the ID of the GitHub deployment a pipeline created), `--run` and `--attempt` select the deploy, and on a `workflow_run` event the commit, `--run` and `--attempt` default to the completed run's. When `--run` defaults to a completed run that did not succeed, the command waits at most 5 minutes for a deploy from that run, then exits 2 with a last line that names the run's conclusion and says it recorded no deploy; a deploy the run did record gets the usual wait for its check. `--json` prints the response. Each deploy prints one line per check. A deploy that rolled the environment back to an earlier commit first prints a `rollback` line with the page of the deploy it restores, when Proofline recorded one, and the pages of the deploys it rolled back. A deploy whose newest check found its service serving an earlier deploy again first prints a `rolled back` line, and stops printing it once a later check finds none; with `--json` the response carries it as `rolled_back`. Both lines can appear for one deploy. A rollback's exit code comes from its checks like any other deploy's; neither line changes it or means the rollback fixed anything. A deploy whose deploy checks ended without recording the `--until` check ends the wait at once with exit 2, and the last line names the check and the deploy's page; a check that is overdue while the checks still run keeps the wait going until the timeout.
Expand Down
67 changes: 67 additions & 0 deletions docs/diagrams/required-environment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Requiring a production review for a webshop checkout

## Who uses the check?

The webshop has a test shop called `staging` and a live shop called `production`. A release engineer configures CI once to require evidence that the review checked production. Developers see the result on each checkout pull request.

```mermaid
---
config:
htmlLabels: false
---
flowchart LR
accTitle: Who uses the production review requirement?
accDescr: The release engineer configures the requirement, CI checks the review for production coverage, and the checkout developer reads the result on the pull request.
engineer["Release engineer"]
ci["Webshop CI"]
developer["Developer"]
subgraph workflow["Checkout pull request"]
policy(["Require production"])
verify(["Check coverage"])
result(["Read CI result"])
end
engineer --- policy
ci --- verify
developer --- result
classDef actor fill:#19384d,color:#ffffff,stroke:#7796ab
classDef goal fill:#e7f2fa,color:#183247,stroke:#88aabf
class engineer,ci,developer actor
class policy,verify,result goal
```

The release engineer adds this step to a CI job that already uses the Proofline CLI:

```yaml
- name: Require production coverage for this pull request
run: proofline ci review --require-environment production --fail-on serious
```

## What happens when a developer opens a checkout PR?

CI reads the completed review for this commit. With `--fail-on serious`, the CLI uses the server’s count of open serious findings.

```mermaid
sequenceDiagram
accTitle: A checkout pull request with production required
accDescr: CI reads the completed Proofline review. If the review skipped production, the job exits 2. If production was checked, the open serious findings determine the result.
actor Dev as Checkout developer
participant CI as Webshop CI
participant CLI as Proofline CLI
participant API as Proofline API
Dev->>CI: Open a checkout PR
CI->>CLI: Run the configured review step
CLI->>API: Read the PR review for this commit
API-->>CLI: Final review and recorded results
alt Only the test shop was checked
CLI-->>CI: Stop (exit 2), production check missing
else Live shop checked, no open serious findings
CLI-->>CI: Pass (exit 0)
else Live shop checked, open serious findings
CLI-->>CI: Stop (exit 3)
else Live shop checked, finding counts unavailable
CLI-->>CI: Stop (exit 4)
end
CI-->>Dev: Show the check result on the PR
```

With the default `proofline ci review` command, the same staging-only review can pass. Adding `--require-environment production` makes CI stop when the final review lacks evidence that production was checked.
21 changes: 21 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub mod origin;
pub mod outcome;
mod preflight;
pub mod render;
mod required_environment;
mod result;
mod sarif;
mod scan;
Expand Down Expand Up @@ -247,6 +248,11 @@ struct CiReviewArgs {
/// review exits 2 whatever it found.
#[arg(long, value_enum, value_name = "SEVERITY")]
fail_on: Option<Severity>,
/// Require the final pull-request review to report this environment as
/// CHECKED. Use its exact external key, not its display name. Missing,
/// ambiguous or unchecked evidence exits 2 before --fail-on is measured.
#[arg(long, value_name = "KEY", value_parser = required_environment::key)]
require_environment: Option<String>,
#[command(flatten)]
repository: RepositoryArgs,
}
Expand Down Expand Up @@ -1639,6 +1645,15 @@ async fn ci_review(
if args.annotations {
annotations::write(&detail, &mut std::io::stderr().lock())?;
}
let environment_gap = if state == Some(Outcome::Completed) {
args.require_environment.as_deref().and_then(|key| {
required_environment::check(&raw, key)
.err()
.map(|gap| gap.message(key))
})
} else {
None
};
print_review(
api,
review_id,
Expand All @@ -1647,6 +1662,10 @@ async fn ci_review(
state,
OutputFormat::from_json(args.json),
)?;
if let Some(message) = environment_gap {
say(&message);
return Ok(Verdict::NotComplete);
}
let verdict = ci_verdict(state, detail.open_items.as_ref(), args.fail_on);
say_ci_ending(api, review_id, &detail, state, verdict, args.timeout);
Ok(verdict)
Expand Down Expand Up @@ -2172,6 +2191,7 @@ mod tests {
json: false,
timeout: 3,
fail_on: None,
require_environment: None,
repository: RepositoryArgs {
repo: Some("acme/app".to_owned()),
source_provider: None,
Expand Down Expand Up @@ -2244,6 +2264,7 @@ mod tests {
json: false,
timeout: 3,
fail_on: None,
require_environment: None,
repository: RepositoryArgs {
repo: Some("acme/app".to_owned()),
source_provider: None,
Expand Down
Loading