Skip to content

Commit 09d65fb

Browse files
authored
feat: add --existing-version flag to attestation init (#2541)
Signed-off-by: Miguel Martinez <[email protected]>
1 parent 0e3e8b0 commit 09d65fb

File tree

12 files changed

+358
-286
lines changed

12 files changed

+358
-286
lines changed

app/cli/cmd/attestation_init.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright 2024 The Chainloop Authors.
2+
// Copyright 2024-2025 The Chainloop Authors.
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.
@@ -33,6 +33,7 @@ func newAttestationInitCmd() *cobra.Command {
3333
projectName string
3434
projectVersion string
3535
projectVersionRelease bool
36+
existingVersion bool
3637
newWorkflowcontract string
3738
)
3839

@@ -67,6 +68,10 @@ func newAttestationInitCmd() *cobra.Command {
6768
return errors.New("project version is required when using --release")
6869
}
6970

71+
if existingVersion && projectVersion == "" {
72+
return errors.New("project version is required when using --existing-version")
73+
}
74+
7075
return nil
7176
},
7277
RunE: func(cmd *cobra.Command, _ []string) error {
@@ -94,6 +99,7 @@ func newAttestationInitCmd() *cobra.Command {
9499
WorkflowName: workflowName,
95100
NewWorkflowContractRef: newWorkflowcontract,
96101
ProjectVersionMarkAsReleased: projectVersionRelease,
102+
RequireExistingVersion: existingVersion,
97103
})
98104

99105
return err
@@ -152,6 +158,7 @@ func newAttestationInitCmd() *cobra.Command {
152158

153159
cmd.Flags().StringVar(&projectVersion, "version", "", "project version, i.e 0.1.0")
154160
cmd.Flags().BoolVar(&projectVersionRelease, "release", false, "promote the provided version as a release")
161+
cmd.Flags().BoolVar(&existingVersion, "existing-version", false, "return an error if the version doesn't exist in the project")
155162

156163
return cmd
157164
}

app/cli/documentation/cli-reference.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ Options
277277
--contract string name of an existing contract or the path/URL to a contract file, to attach it to the auto-created workflow (it doesn't update an existing one)
278278
--contract-revision int revision of the contract to retrieve, "latest" by default
279279
--dry-run do not record attestation in the control plane, useful for development
280+
--existing-version return an error if the version doesn't exist in the project
280281
-h, --help help for init
281282
--project string name of the project of this workflow
282283
--release promote the provided version as a release

app/cli/pkg/action/attestation_init.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ type AttestationInitRunOpts struct {
8181
ProjectName string
8282
ProjectVersion string
8383
ProjectVersionMarkAsReleased bool
84+
RequireExistingVersion bool
8485
WorkflowName string
8586
NewWorkflowContractRef string
8687
}
@@ -190,9 +191,10 @@ func (action *AttestationInit) Run(ctx context.Context, opts *AttestationInitRun
190191
JobUrl: discoveredRunner.RunURI(),
191192
ContractRevision: int32(opts.ContractRevision),
192193
// send the workflow name explicitly provided by the user to detect that functional case
193-
WorkflowName: opts.WorkflowName,
194-
ProjectName: opts.ProjectName,
195-
ProjectVersion: opts.ProjectVersion,
194+
WorkflowName: opts.WorkflowName,
195+
ProjectName: opts.ProjectName,
196+
ProjectVersion: opts.ProjectVersion,
197+
RequireExistingVersion: opts.RequireExistingVersion,
196198
},
197199
)
198200
if err != nil {

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

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

app/controlplane/api/controlplane/v1/workflow_run.proto

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ message AttestationServiceInitRequest {
122122

123123
// Optional project version
124124
string project_version = 6;
125+
// Optional flag to require that the project version already exists
126+
bool require_existing_version = 7;
125127
}
126128

127129
message AttestationServiceInitResponse {

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

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

app/controlplane/api/gen/jsonschema/controlplane.v1.AttestationServiceInitRequest.jsonschema.json

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

app/controlplane/api/gen/jsonschema/controlplane.v1.AttestationServiceInitRequest.schema.json

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

app/controlplane/internal/service/attestation.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,13 @@ func (s *AttestationService) Init(ctx context.Context, req *cpAPI.AttestationSer
186186

187187
// Create workflowRun
188188
opts := &biz.WorkflowRunCreateOpts{
189-
WorkflowID: wf.ID.String(),
190-
ContractRevision: contractVersion,
191-
RunnerRunURL: req.GetJobUrl(),
192-
RunnerType: req.GetRunner().String(),
193-
CASBackendID: backend.ID,
194-
ProjectVersion: req.GetProjectVersion(),
189+
WorkflowID: wf.ID.String(),
190+
ContractRevision: contractVersion,
191+
RunnerRunURL: req.GetJobUrl(),
192+
RunnerType: req.GetRunner().String(),
193+
CASBackendID: backend.ID,
194+
ProjectVersion: req.GetProjectVersion(),
195+
RequireExistingVersion: req.GetRequireExistingVersion(),
195196
}
196197

197198
run, err := s.wrUseCase.Create(ctx, opts)

app/controlplane/pkg/biz/workflowrun.go

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,13 @@ func (uc *WorkflowRunExpirerUseCase) ExpirationSweep(ctx context.Context, olderT
190190
}
191191

192192
type WorkflowRunCreateOpts struct {
193-
WorkflowID string
194-
ContractRevision *WorkflowContractWithVersion
195-
RunnerRunURL string
196-
RunnerType string
197-
CASBackendID uuid.UUID
198-
ProjectVersion string
193+
WorkflowID string
194+
ContractRevision *WorkflowContractWithVersion
195+
RunnerRunURL string
196+
RunnerType string
197+
CASBackendID uuid.UUID
198+
ProjectVersion string
199+
RequireExistingVersion bool
199200
}
200201

201202
type WorkflowRunRepoCreateOpts struct {
@@ -204,6 +205,7 @@ type WorkflowRunRepoCreateOpts struct {
204205
Backends []uuid.UUID
205206
LatestRevision, UsedRevision int
206207
ProjectVersion string
208+
RequireExistingVersion bool
207209
}
208210

209211
// Create will add a new WorkflowRun, associate it to a schemaVersion and increment the counter in the associated workflow
@@ -234,14 +236,15 @@ func (uc *WorkflowRunUseCase) Create(ctx context.Context, opts *WorkflowRunCreat
234236
backends := []uuid.UUID{opts.CASBackendID}
235237
result, err := uc.wfRunRepo.Create(ctx,
236238
&WorkflowRunRepoCreateOpts{
237-
WorkflowID: workflowUUID,
238-
SchemaVersionID: contractRevision.Version.ID,
239-
RunURL: opts.RunnerRunURL,
240-
RunnerType: opts.RunnerType,
241-
Backends: backends,
242-
LatestRevision: contractRevision.Contract.LatestRevision,
243-
UsedRevision: contractRevision.Version.Revision,
244-
ProjectVersion: opts.ProjectVersion,
239+
WorkflowID: workflowUUID,
240+
SchemaVersionID: contractRevision.Version.ID,
241+
RunURL: opts.RunnerRunURL,
242+
RunnerType: opts.RunnerType,
243+
Backends: backends,
244+
LatestRevision: contractRevision.Contract.LatestRevision,
245+
UsedRevision: contractRevision.Version.Revision,
246+
ProjectVersion: opts.ProjectVersion,
247+
RequireExistingVersion: opts.RequireExistingVersion,
245248
})
246249
if err != nil {
247250
return nil, err

0 commit comments

Comments
 (0)