Skip to content

Commit a9171c6

Browse files
authored
feat: expose latest_revision on workflow (#542)
Signed-off-by: Miguel Martinez Trivino <[email protected]>
1 parent 625b153 commit a9171c6

30 files changed

+963
-307
lines changed

app/cli/internal/action/workflow_list.go

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,16 @@ type WorkflowList struct {
2828
}
2929

3030
type WorkflowItem struct {
31-
Name string `json:"name"`
32-
Description string `json:"description,omitempty"`
33-
ID string `json:"id"`
34-
Team string `json:"team"`
35-
Project string `json:"project,omitempty"`
36-
CreatedAt *time.Time `json:"createdAt"`
37-
RunsCount int32 `json:"runsCount"`
38-
ContractID string `json:"contractID,omitempty"`
39-
LastRun *WorkflowRunItem `json:"lastRun,omitempty"`
31+
Name string `json:"name"`
32+
Description string `json:"description,omitempty"`
33+
ID string `json:"id"`
34+
Team string `json:"team"`
35+
Project string `json:"project,omitempty"`
36+
CreatedAt *time.Time `json:"createdAt"`
37+
RunsCount int32 `json:"runsCount"`
38+
ContractID string `json:"contractID,omitempty"`
39+
ContractRevisionLatest int32 `json:"contractRevisionLatest,omitempty"`
40+
LastRun *WorkflowRunItem `json:"lastRun,omitempty"`
4041
// A public workflow means that any user can
4142
// - access to all its workflow runs
4243
// - their attestation and materials
@@ -76,10 +77,11 @@ func pbWorkflowItemToAction(wf *pb.WorkflowItem) *WorkflowItem {
7677
res := &WorkflowItem{
7778
Name: wf.Name, ID: wf.Id, CreatedAt: toTimePtr(wf.CreatedAt.AsTime()),
7879
Project: wf.Project, Team: wf.Team, RunsCount: wf.RunsCount,
79-
ContractID: wf.ContractId,
80-
LastRun: pbWorkflowRunItemToAction(wf.LastRun),
81-
Public: wf.Public,
82-
Description: wf.Description,
80+
ContractID: wf.ContractId,
81+
ContractRevisionLatest: wf.ContractRevisionLatest,
82+
LastRun: pbWorkflowRunItemToAction(wf.LastRun),
83+
Public: wf.Public,
84+
Description: wf.Description,
8385
}
8486

8587
return res

app/cli/internal/action/workflow_run_list.go

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,17 @@ type WorkflowRunList struct {
2828
}
2929

3030
type WorkflowRunItem struct {
31-
ID string `json:"id"`
32-
State string `json:"state"`
33-
Reason string `json:"reason,omitempty"`
34-
CreatedAt *time.Time `json:"createdAt,omitempty"`
35-
FinishedAt *time.Time `json:"finishedAt,omitempty"`
36-
Workflow *WorkflowItem `json:"workflow,omitempty"`
37-
RunURL string `json:"runURL,omitempty"`
38-
RunnerType string `json:"runnerType,omitempty"`
39-
ContractVersion *WorkflowContractVersionItem `json:"contractVersion,omitempty"`
31+
ID string `json:"id"`
32+
State string `json:"state"`
33+
Reason string `json:"reason,omitempty"`
34+
CreatedAt *time.Time `json:"createdAt,omitempty"`
35+
FinishedAt *time.Time `json:"finishedAt,omitempty"`
36+
Workflow *WorkflowItem `json:"workflow,omitempty"`
37+
RunURL string `json:"runURL,omitempty"`
38+
RunnerType string `json:"runnerType,omitempty"`
39+
ContractVersion *WorkflowContractVersionItem `json:"contractVersion,omitempty"`
40+
ContractRevisionUsed int `json:"contractRevisionUsed"`
41+
ContractRevisionLatest int `json:"contractRevisionLatest"`
4042
}
4143

4244
type PaginatedWorkflowRunItem struct {
@@ -93,9 +95,11 @@ func pbWorkflowRunItemToAction(in *pb.WorkflowRunItem) *WorkflowRunItem {
9395

9496
item := &WorkflowRunItem{
9597
ID: in.Id, State: in.State, Reason: in.Reason, CreatedAt: toTimePtr(in.CreatedAt.AsTime()),
96-
Workflow: pbWorkflowItemToAction(in.Workflow),
97-
RunURL: in.GetJobUrl(),
98-
RunnerType: humanizedRunnerType(in.GetRunnerType()),
98+
Workflow: pbWorkflowItemToAction(in.Workflow),
99+
RunURL: in.GetJobUrl(),
100+
RunnerType: humanizedRunnerType(in.GetRunnerType()),
101+
ContractRevisionUsed: int(in.GetContractRevisionUsed()),
102+
ContractRevisionLatest: int(in.GetContractRevisionLatest()),
99103
}
100104

101105
if in.GetContractVersion() != nil {

app/controlplane/api/controlplane/v1/response_messages.pb.go

Lines changed: 218 additions & 180 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/controlplane/api/controlplane/v1/response_messages.pb.validate.go

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/controlplane/api/controlplane/v1/response_messages.proto

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ message WorkflowItem {
3333

3434
WorkflowRunItem last_run = 7;
3535
string contract_id = 8;
36+
// Current, latest revision of the contract
37+
int32 contract_revision_latest = 11;
3638
// A public workflow means that any user can
3739
// - access to all its workflow runs
3840
// - their attestation and materials
@@ -51,6 +53,11 @@ message WorkflowRunItem {
5153
// string runner_type = 8;
5254
workflowcontract.v1.CraftingSchema.Runner.RunnerType runner_type = 8;
5355
WorkflowContractVersionItem contract_version = 9;
56+
57+
// The revision of the contract used for this run
58+
int32 contract_revision_used = 10;
59+
// The latest revision available for this contract at the time of the run
60+
int32 contract_revision_latest = 11;
5461
}
5562

5663
message AttestationItem {

app/controlplane/api/gen/frontend/controlplane/v1/response_messages.ts

Lines changed: 50 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/controlplane/internal/biz/casmapping_integration_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,13 +367,13 @@ func (s *casMappingIntegrationSuite) SetupTest() {
367367
assert.NoError(err)
368368

369369
s.workflowRun, err = s.WorkflowRun.Create(ctx, &biz.WorkflowRunCreateOpts{
370-
WorkflowID: workflow.ID.String(), RobotaccountID: robotAccount.ID.String(), ContractRevisionUUID: contractVersion.Version.ID, CASBackendID: s.casBackend1.ID,
370+
WorkflowID: workflow.ID.String(), RobotaccountID: robotAccount.ID.String(), ContractRevision: contractVersion, CASBackendID: s.casBackend1.ID,
371371
RunnerType: "runnerType", RunnerRunURL: "runURL",
372372
})
373373
assert.NoError(err)
374374

375375
s.publicWorkflowRun, err = s.WorkflowRun.Create(ctx, &biz.WorkflowRunCreateOpts{
376-
WorkflowID: publicWorkflow.ID.String(), RobotaccountID: robotAccount.ID.String(), ContractRevisionUUID: contractVersion.Version.ID, CASBackendID: s.casBackend1.ID,
376+
WorkflowID: publicWorkflow.ID.String(), RobotaccountID: robotAccount.ID.String(), ContractRevision: contractVersion, CASBackendID: s.casBackend1.ID,
377377
RunnerType: "runnerType", RunnerRunURL: "runURL",
378378
})
379379
assert.NoError(err)

app/controlplane/internal/biz/mocks/WorkflowRunRepo.go

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/controlplane/internal/biz/workflow.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ type Workflow struct {
3131
RunsCounter int
3232
LastRun *WorkflowRun
3333
ID, ContractID, OrgID uuid.UUID
34+
// Latest available contract revision
35+
ContractRevisionLatest int
3436
// Public means that the associated workflow runs, attestations and materials
3537
// are reachable by other users, regardless of their organization
3638
// This field is also used to calculate if an user can download attestations/materials from the CAS

app/controlplane/internal/biz/workflow_integration_test.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"testing"
2121
"time"
2222

23+
v1 "github.com/chainloop-dev/chainloop/app/controlplane/api/workflowcontract/v1"
2324
"github.com/chainloop-dev/chainloop/app/controlplane/internal/biz"
2425
"github.com/chainloop-dev/chainloop/app/controlplane/internal/biz/testhelpers"
2526
"github.com/docker/distribution/uuid"
@@ -30,6 +31,29 @@ import (
3031
"github.com/stretchr/testify/suite"
3132
)
3233

34+
func (s *workflowIntegrationTestSuite) TestContractLatestAvailable() {
35+
ctx := context.Background()
36+
var workflow *biz.Workflow
37+
var err error
38+
s.Run("by default is 1", func() {
39+
workflow, err = s.Workflow.Create(ctx, &biz.WorkflowCreateOpts{
40+
Description: description, Name: "name", Team: "team", Project: "project", OrgID: s.org.ID})
41+
require.NoError(s.T(), err)
42+
s.Equal(1, workflow.ContractRevisionLatest)
43+
})
44+
45+
s.Run("it will increment if the contract is updated", func() {
46+
_, err := s.WorkflowContract.Update(ctx, s.org.ID, workflow.ContractID.String(), "new-name", &v1.CraftingSchema{
47+
Runner: &v1.CraftingSchema_Runner{Type: v1.CraftingSchema_Runner_CIRCLECI_BUILD},
48+
})
49+
s.NoError(err)
50+
51+
workflow, err := s.Workflow.FindByID(ctx, workflow.ID.String())
52+
s.NoError(err)
53+
s.Equal(2, workflow.ContractRevisionLatest)
54+
})
55+
}
56+
3357
func (s *workflowIntegrationTestSuite) TestUpdate() {
3458
ctx := context.Background()
3559
const (
@@ -129,7 +153,7 @@ func (s *workflowIntegrationTestSuite) TestUpdate() {
129153
s.NoError(err)
130154

131155
if diff := cmp.Diff(tc.want, got,
132-
cmpopts.IgnoreFields(biz.Workflow{}, "CreatedAt", "ID", "OrgID", "ContractID"),
156+
cmpopts.IgnoreFields(biz.Workflow{}, "CreatedAt", "ID", "OrgID", "ContractID", "ContractRevisionLatest"),
133157
); diff != "" {
134158
s.Failf("mismatch (-want +got):\n%s", diff)
135159
}

0 commit comments

Comments
 (0)