feat: attestation progress events, M2 custom events (#3825)
Implements milestone M2 ("Custom events") of the attestation progress events spec. Refs #3825. Builds on M1 (#3859).
What it adds
- Custom event type (R-012).
WorkflowRunEvent.TypegetsTYPE_CUSTOM.RecordEventaccepts it with no attributes. A custom key uses the format of annotation names (letters, digits,_and-), up to 64 characters. It cannot hold a dot, so it never matches an automaticchainloop.key. Custom events do not change the material progress. chainloop attestation event --name <key> --status <started|succeeded|failed|canceled> [--message <text>]. It records a custom step on the run of the attestation in progress, from the local state or with--attestation-id. With remote state, the attestation ID is the run ID, so the command sends one call and does not download the state. Each failure shows a warning, and the command exits with success: no attestation in progress, a rejected key, an older control plane, and also a missing--name, an unexpected positional argument, or a wrong--status. A dry run records nothing.chainloop workflow run describe. The timeline shows each custom step as a line, with the status of its last event. A finished step shows its duration, and a step that still runs on a run in progress shows how long it runs. The events of a repeated step fold below it, as for materials.
├─ 10:01:02 ✓ step `sast-scan` took 2m3s
│ ├─ 10:01:02 ● Semgrep, ruleset p/ci
│ └─ 10:03:05 ✓ succeeded
├─ 10:03:22 ✗ step `unit-tests` 3 tests failed
├─ 10:05:02 ● step `approval` running for 43s
Examples
The output below comes from the command and the timeline renderer in this PR, against a test control plane.
1. Record steps in the pipeline
Record a step between attestation init and attestation push. Events with the same --name are one step of the timeline.
$ chainloop attestation event --name sast-scan --status started --message "Semgrep, ruleset p/ci"
INF event recorded
$ semgrep scan --config p/ci --sarif -o scan.sarif
$ chainloop attestation event --name sast-scan --status succeeded
INF event recorded
$ chainloop attestation add --name sast-report --value scan.sarif
A failed step, and a step that waits on something outside the job:
$ chainloop attestation event --name unit-tests --status started
INF event recorded
$ chainloop attestation event --name unit-tests --status failed --message "3 tests failed"
INF event recorded
$ chainloop attestation event --name approval --status started --message "waiting for release approval"
INF event recorded
In GitHub Actions, wrap a job step, and keep the result of the step:
- name: Unit tests
run: |
chainloop attestation event --name unit-tests --status started
go test ./... && status=succeeded || status=failed
chainloop attestation event --name unit-tests --status "$status"
test "$status" = succeeded
With remote state, add --attestation-id "$ATTESTATION_ID", as for the other attestation commands.
2. See the steps while the run is in progress
$ chainloop workflow run describe --id 4f8d2b7e-...
...
Timeline (reported progress) · started 10:00:02 · running for 5m43s · 0 of 1 required provided · attestation policies: 2 passed
├─ 10:00:02 ✓ initialized contract build rev 3 · GITHUB_ACTION · local state · policies: 2 passed
├─ 10:01:02 ✓ step `sast-scan` took 2m3s
│ ├─ 10:01:02 ● Semgrep, ruleset p/ci
│ └─ 10:03:05 ✓ succeeded
├─ 10:03:12 ✓ added evidence `sast-report` SARIF · scan.sarif · optional · policies: 1 passed
├─ 10:03:22 ✗ step `unit-tests` took 1m2s
│ ├─ 10:03:22 ● started
│ └─ 10:04:24 ✗ 3 tests failed
├─ 10:05:02 ● step `approval` running for 43s · waiting for release approval
├─ ○ missing evidence `sbom` required
└─ ● waiting for push
3. See the steps as history after the push
$ chainloop workflow run describe --id 4f8d2b7e-...
...
Timeline · started 10:00:02 · finished 10:08:22 (8m20s) · stored
├─ 10:00:02 ✓ initialized contract build rev 3 · GITHUB_ACTION · local state · policies: 2 passed
├─ 10:01:02 ✓ step `sast-scan` took 2m3s
│ ├─ 10:01:02 ● Semgrep, ruleset p/ci
│ └─ 10:03:05 ✓ succeeded
├─ 10:03:12 ✓ added evidence `sast-report` SARIF · scan.sarif · policies: 1 passed
├─ 10:03:22 ✗ step `unit-tests` took 1m2s
│ ├─ 10:03:22 ● started
│ └─ 10:04:24 ✗ 3 tests failed
├─ 10:05:02 ✓ step `approval` took 2m0s
│ ├─ 10:05:02 ● waiting for release approval
│ └─ 10:07:02 ✓ succeeded
└─ 10:08:22 ✓ pushed and stored policies: 3 passed · sha256:4de7a1b2c3d4…
4. A failure never breaks the pipeline
Each failure prints a warning, and the command exits with 0:
$ chainloop attestation event --name sast.scan --status started
WRN the event was not recorded error="rpc error: code = InvalidArgument desc = custom event key \"sast.scan\" must contain only letters, digits, _ and -"
$ echo $?
0
$ chainloop attestation event --name sast-scan --status done
WRN the event was not recorded error="invalid status \"done\", valid options are started, succeeded, failed, canceled"
$ chainloop attestation event --status started
WRN the event was not recorded: --name is required
$ chainloop attestation event --name sast-scan --status started # no attestation in progress
WRN the event was not recorded error="attestation not yet initialized"
Spec changes
R-012 supersedes R-009: the command takes the step with the --name flag, not a positional argument, as chainloop attestation add --name does. A wrong call, for example a missing --name, is also a warning with exit 0. CLAUDE.md now records the convention: CLI commands identify what they act on with a flag, not a positional argument.
Differences from the plan
- The key check is in the run events use case (
biz/workflowrunevent.go), next to the other event checks, not in the attestation service. - The plan's M2 step does not name the timeline renderer of
describe. Its "Done when" needs the custom step indescribe, so this PR adds it.
AI assistance: this change was implemented with Claude Code.
🤖 Posted by Maximus bot (Claude Code) on behalf of @migmartri