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
9 changes: 8 additions & 1 deletion app/cli/cmd/attestation_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down Expand Up @@ -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)}
}
27 changes: 5 additions & 22 deletions app/cli/cmd/workflow_run_timeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions app/cli/cmd/workflow_run_timeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down Expand Up @@ -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" +
Expand All @@ -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" +
Expand All @@ -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" +
Expand All @@ -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",
},
Expand All @@ -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",
},
Expand All @@ -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",
},
{
Expand All @@ -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",
},
}
Expand Down
7 changes: 7 additions & 0 deletions app/cli/cmd/workflow_workflow_run_describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"io"
"net/url"
"os"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -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 {
Expand Down
19 changes: 10 additions & 9 deletions app/cli/pkg/action/workflow_contract_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Comment thread
migmartri marked this conversation as resolved.
Resolved
Description string `json:"description"`
CreatedAt *time.Time `json:"createdAt"`
BodyV1 *schemav1.CraftingSchema `json:"bodyV1"`
RawBody *ContractRawBody `json:"rawBody"`
}

type ContractRawBody struct {
Expand Down Expand Up @@ -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()},
}
}

Expand Down
Loading