diff --git a/app/cli/cmd/attestation_status.go b/app/cli/cmd/attestation_status.go index 57d6e0af9..57b472b23 100644 --- a/app/cli/cmd/attestation_status.go +++ b/app/cli/cmd/attestation_status.go @@ -103,7 +103,7 @@ func attestationStatusTableOutput(status *action.AttestationStatusResult, w io.W gt.AppendRow(table.Row{"Project", meta.Project}) projectVersion := versionStringAttestation(meta.ProjectVersion, status.IsPushed) gt.AppendRow(table.Row{"Version", projectVersion}) - gt.AppendRow(table.Row{"Contract", fmt.Sprintf("%s (revision %s)", meta.ContractName, meta.ContractRevision)}) + gt.AppendRow(contractRow(meta.ContractName, meta.ContractRevision)) if status.RunnerContext.JobURL != "" { gt.AppendRow(table.Row{"Runner Type", status.RunnerContext.RunnerType}) gt.AppendRow(table.Row{"Runner URL", status.RunnerContext.JobURL}) @@ -372,3 +372,10 @@ var ansiPattern = regexp.MustCompile("[\u001B\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z func removeAnsiCharactersFromBytes(input []byte) []byte { return ansiPattern.ReplaceAll(input, nil) } + +const contractLabel = "Contract" + +// contractRow is the table row of the contract of an attestation, with its revision +func contractRow(name, revision string) table.Row { + return table.Row{contractLabel, fmt.Sprintf("%s (revision %s)", name, revision)} +} diff --git a/app/cli/cmd/workflow_run_timeline.go b/app/cli/cmd/workflow_run_timeline.go index dca22d00c..77d2fd738 100644 --- a/app/cli/cmd/workflow_run_timeline.go +++ b/app/cli/cmd/workflow_run_timeline.go @@ -166,31 +166,14 @@ func timelineHeader(started *action.RunEvent, events []*action.RunEvent, closing return strings.Join(parts, " · ") } -// timelineInit is the line of the start of the attestation, with its contract and its runner +// timelineInit is the line of the start of the attestation, with the result of its +// attestation policies. The run table shows the contract and the runner. func timelineInit(e *action.RunEvent) *timelineNode { node := &timelineNode{at: timelineTime(e.CreatedAt), symbol: timelineSymbol(timelineSucceeded), name: "initialized"} - a := e.Attestation - if a == nil { - return node - } - - if a.ContractName != "" { - contract := "contract " + a.ContractName - if a.ContractRevision > 0 { - contract += fmt.Sprintf(" rev %d", a.ContractRevision) + if a := e.Attestation; a != nil { + if s := runPolicyCountSummary(a.Policies); s != "" { + node.details = append(node.details, "policies: "+s) } - node.details = append(node.details, contract) - } - if a.RunnerType != "" { - node.details = append(node.details, a.RunnerType) - } - if a.RemoteState { - node.details = append(node.details, "remote state") - } else { - node.details = append(node.details, "local state") - } - if s := runPolicyCountSummary(a.Policies); s != "" { - node.details = append(node.details, "policies: "+s) } return node diff --git a/app/cli/cmd/workflow_run_timeline_test.go b/app/cli/cmd/workflow_run_timeline_test.go index f00298999..bac71dc9b 100644 --- a/app/cli/cmd/workflow_run_timeline_test.go +++ b/app/cli/cmd/workflow_run_timeline_test.go @@ -35,7 +35,7 @@ func TestRenderRunTimeline(t *testing.T) { return &v } started := &action.RunEvent{CreatedAt: at(0), Source: timelineSourceCLI, Key: timelineKeyAttestation, Status: "started", Attestation: &action.RunEventAttestation{ - ContractName: "build", ContractRevision: 3, RunnerType: "GITHUB_ACTION", Policies: &action.RunEventPolicyCount{Evaluated: 2, Passed: 2}}} + Policies: &action.RunEventPolicyCount{Evaluated: 2, Passed: 2}}} material := func(d time.Duration, name, status, msg string, policies *action.RunEventPolicyCount) *action.RunEvent { return &action.RunEvent{CreatedAt: at(d), Source: timelineSourceCLI, Key: "chainloop.material." + name, Status: status, Message: msg, Material: &action.RunEventMaterial{Name: name, Policies: policies}} @@ -71,7 +71,7 @@ func TestRenderRunTimeline(t *testing.T) { }, }, want: "Timeline (reported progress) · started 10:00:02 · running for 5m43s · 1 of 2 required provided · attestation policies: 2 passed\n" + - "├─ 10:00:02 ✓ initialized contract build rev 3 · GITHUB_ACTION · local state · policies: 2 passed\n" + + "├─ 10:00:02 ✓ initialized policies: 2 passed\n" + "├─ 10:02:21 ✓ added evidence `sast-report` optional · policies: 1 passed, 1 violated\n" + "├─ 10:03:10 ✓ added evidence `sbom` required · policies: 2 passed · 1 failed attempt\n" + "│ ├─ 10:03:10 ✗ invalid CycloneDX document: missing bomFormat\n" + @@ -94,7 +94,7 @@ func TestRenderRunTimeline(t *testing.T) { }, }, want: "Timeline (reported progress) · started 10:00:02 · running for 5m43s · 1 of 1 required provided\n" + - "├─ 10:00:02 ✓ initialized contract build rev 3 · GITHUB_ACTION · local state · policies: 2 passed\n" + + "├─ 10:00:02 ✓ initialized policies: 2 passed\n" + "├─ 10:01:02 ✓ added evidence `sbom` required · 1 failed attempt\n" + "│ ├─ 10:01:02 ✓ succeeded\n" + "│ └─ 10:02:02 ✗ material already exists in the attestation\n" + @@ -117,7 +117,7 @@ func TestRenderRunTimeline(t *testing.T) { }, }, want: "Timeline (reported progress) · started 10:00:02 · running for 5m43s · 1 of 1 required provided\n" + - "├─ 10:00:02 ✓ initialized contract build rev 3 · GITHUB_ACTION · local state · policies: 2 passed\n" + + "├─ 10:00:02 ✓ initialized policies: 2 passed\n" + "├─ 10:01:02 ✓ step `sast-scan` took 2m3s\n" + "│ ├─ 10:01:02 ● Semgrep, ruleset p/ci\n" + "│ └─ 10:03:05 ✓ succeeded\n" + @@ -135,7 +135,7 @@ func TestRenderRunTimeline(t *testing.T) { }, stored: &action.PolicyEvaluationStatus{}, want: "Timeline · started 10:00:02 · finished 10:02:02 (2m0s) · stored\n" + - "├─ 10:00:02 ✓ initialized contract build rev 3 · GITHUB_ACTION · local state · policies: 2 passed\n" + + "├─ 10:00:02 ✓ initialized policies: 2 passed\n" + "├─ 10:01:02 ● step `approval` waiting for approval\n" + "└─ 10:02:02 ✓ pushed and stored\n", }, @@ -149,7 +149,7 @@ func TestRenderRunTimeline(t *testing.T) { }, stored: &action.PolicyEvaluationStatus{Total: 3, Passed: 3}, want: "Timeline · started 10:00:02 · finished 10:08:23 (8m21s) · stored\n" + - "├─ 10:00:02 ✓ initialized contract build rev 3 · GITHUB_ACTION · local state · policies: 2 passed\n" + + "├─ 10:00:02 ✓ initialized policies: 2 passed\n" + "├─ 10:07:33 ✓ added evidence `vulnerability-report`\n" + "└─ 10:08:23 ✓ pushed and stored policies: 3 passed · sha256:4de7a1b2c3d4…\n", }, @@ -162,7 +162,7 @@ func TestRenderRunTimeline(t *testing.T) { }, stored: &action.PolicyEvaluationStatus{Total: 3, Passed: 2, Violated: 1, Blocked: true, HasGatedViolations: true}, want: "Timeline · started 10:00:02 · finished 10:01:02 (1m0s) · stored\n" + - "├─ 10:00:02 ✓ initialized contract build rev 3 · GITHUB_ACTION · local state · policies: 2 passed\n" + + "├─ 10:00:02 ✓ initialized policies: 2 passed\n" + "└─ 10:01:02 ✓ pushed and stored policies: 2 passed, 1 violated · blocked by policy gates · sha256:4de7\n", }, { @@ -172,7 +172,7 @@ func TestRenderRunTimeline(t *testing.T) { {CreatedAt: at(3600 * time.Second), Key: timelineKeyAttestation, Status: "failed", Message: "expired"}, }, want: "Timeline · started 10:00:02 · finished 11:00:02 (1h0m0s) · failed\n" + - "├─ 10:00:02 ✓ initialized contract build rev 3 · GITHUB_ACTION · local state · policies: 2 passed\n" + + "├─ 10:00:02 ✓ initialized policies: 2 passed\n" + "└─ 11:00:02 ✗ failed expired\n", }, } diff --git a/app/cli/cmd/workflow_workflow_run_describe.go b/app/cli/cmd/workflow_workflow_run_describe.go index 87e5fdbb2..9a3eb0b27 100644 --- a/app/cli/cmd/workflow_workflow_run_describe.go +++ b/app/cli/cmd/workflow_workflow_run_describe.go @@ -22,6 +22,7 @@ import ( "io" "net/url" "os" + "strconv" "strings" "time" @@ -132,6 +133,12 @@ func workflowRunDescribeTableOutput(run *action.WorkflowRunItemFull) error { gt.AppendRow(table.Row{"Failure Reason", wr.Reason}) } gt.AppendRow(table.Row{"Policy Status", wr.PolicyStatus}) + if cv := wr.ContractVersion; cv != nil && cv.ContractName != "" { + gt.AppendRow(contractRow(cv.ContractName, strconv.Itoa(cv.Revision))) + } + if wr.RunnerType != "" { + gt.AppendRow(table.Row{"Runner Type", wr.RunnerType}) + } gt.AppendRow(table.Row{"Runner Link", wr.RunURL}) if run.Progress != nil { diff --git a/app/cli/pkg/action/workflow_contract_list.go b/app/cli/pkg/action/workflow_contract_list.go index 1987087c3..60b5d579f 100644 --- a/app/cli/pkg/action/workflow_contract_list.go +++ b/app/cli/pkg/action/workflow_contract_list.go @@ -62,12 +62,13 @@ type WorkflowRef struct { } type WorkflowContractVersionItem struct { - ID string `json:"id"` - Revision int `json:"revision"` - Description string `json:"description"` - CreatedAt *time.Time `json:"createdAt"` - BodyV1 *schemav1.CraftingSchema `json:"bodyV1"` - RawBody *ContractRawBody `json:"rawBody"` + ID string `json:"id"` + Revision int `json:"revision"` + ContractName string `json:"contractName,omitempty"` + Description string `json:"description"` + CreatedAt *time.Time `json:"createdAt"` + BodyV1 *schemav1.CraftingSchema `json:"bodyV1"` + RawBody *ContractRawBody `json:"rawBody"` } type ContractRawBody struct { @@ -127,9 +128,9 @@ func pbWorkflowContractItemToAction(in *pb.WorkflowContractItem) *WorkflowContra func pbWorkflowContractVersionItemToAction(in *pb.WorkflowContractVersionItem) *WorkflowContractVersionItem { return &WorkflowContractVersionItem{ Revision: int(in.GetRevision()), ID: in.GetId(), BodyV1: in.GetV1(), - Description: in.Description, - CreatedAt: toTimePtr(in.GetCreatedAt().AsTime()), - RawBody: &ContractRawBody{Body: string(in.RawContract.GetBody()), Format: in.RawContract.GetFormat().String()}, + Description: in.Description, ContractName: in.GetContractName(), + CreatedAt: toTimePtr(in.GetCreatedAt().AsTime()), + RawBody: &ContractRawBody{Body: string(in.RawContract.GetBody()), Format: in.RawContract.GetFormat().String()}, } }