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_init.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright 2024 The Chainloop Authors.
// Copyright 2024-2025 The Chainloop Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -33,6 +33,7 @@ func newAttestationInitCmd() *cobra.Command {
projectName string
projectVersion string
projectVersionRelease bool
existingVersion bool
newWorkflowcontract string
)

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

if existingVersion && projectVersion == "" {
return errors.New("project version is required when using --existing-version")
}

return nil
},
RunE: func(cmd *cobra.Command, _ []string) error {
Expand Down Expand Up @@ -94,6 +99,7 @@ func newAttestationInitCmd() *cobra.Command {
WorkflowName: workflowName,
NewWorkflowContractRef: newWorkflowcontract,
ProjectVersionMarkAsReleased: projectVersionRelease,
RequireExistingVersion: existingVersion,
})

return err
Expand Down Expand Up @@ -152,6 +158,7 @@ func newAttestationInitCmd() *cobra.Command {

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

return cmd
}
1 change: 1 addition & 0 deletions app/cli/documentation/cli-reference.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ Options
--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)
--contract-revision int revision of the contract to retrieve, "latest" by default
--dry-run do not record attestation in the control plane, useful for development
--existing-version return an error if the version doesn't exist in the project
-h, --help help for init
--project string name of the project of this workflow
--release promote the provided version as a release
Expand Down
8 changes: 5 additions & 3 deletions app/cli/pkg/action/attestation_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ type AttestationInitRunOpts struct {
ProjectName string
ProjectVersion string
ProjectVersionMarkAsReleased bool
RequireExistingVersion bool
WorkflowName string
NewWorkflowContractRef string
}
Expand Down Expand Up @@ -190,9 +191,10 @@ func (action *AttestationInit) Run(ctx context.Context, opts *AttestationInitRun
JobUrl: discoveredRunner.RunURI(),
ContractRevision: int32(opts.ContractRevision),
// send the workflow name explicitly provided by the user to detect that functional case
WorkflowName: opts.WorkflowName,
ProjectName: opts.ProjectName,
ProjectVersion: opts.ProjectVersion,
WorkflowName: opts.WorkflowName,
ProjectName: opts.ProjectName,
ProjectVersion: opts.ProjectVersion,
RequireExistingVersion: opts.RequireExistingVersion,
},
)
if err != nil {
Expand Down
530 changes: 271 additions & 259 deletions app/controlplane/api/controlplane/v1/workflow_run.pb.go

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions app/controlplane/api/controlplane/v1/workflow_run.proto
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ message AttestationServiceInitRequest {

// Optional project version
string project_version = 6;
// Optional flag to require that the project version already exists
bool require_existing_version = 7;
}

message AttestationServiceInitResponse {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions app/controlplane/internal/service/attestation.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,13 @@ func (s *AttestationService) Init(ctx context.Context, req *cpAPI.AttestationSer

// Create workflowRun
opts := &biz.WorkflowRunCreateOpts{
WorkflowID: wf.ID.String(),
ContractRevision: contractVersion,
RunnerRunURL: req.GetJobUrl(),
RunnerType: req.GetRunner().String(),
CASBackendID: backend.ID,
ProjectVersion: req.GetProjectVersion(),
WorkflowID: wf.ID.String(),
ContractRevision: contractVersion,
RunnerRunURL: req.GetJobUrl(),
RunnerType: req.GetRunner().String(),
CASBackendID: backend.ID,
ProjectVersion: req.GetProjectVersion(),
RequireExistingVersion: req.GetRequireExistingVersion(),
}

run, err := s.wrUseCase.Create(ctx, opts)
Expand Down
31 changes: 17 additions & 14 deletions app/controlplane/pkg/biz/workflowrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,13 @@ func (uc *WorkflowRunExpirerUseCase) ExpirationSweep(ctx context.Context, olderT
}

type WorkflowRunCreateOpts struct {
WorkflowID string
ContractRevision *WorkflowContractWithVersion
RunnerRunURL string
RunnerType string
CASBackendID uuid.UUID
ProjectVersion string
WorkflowID string
ContractRevision *WorkflowContractWithVersion
RunnerRunURL string
RunnerType string
CASBackendID uuid.UUID
ProjectVersion string
RequireExistingVersion bool
}

type WorkflowRunRepoCreateOpts struct {
Expand All @@ -204,6 +205,7 @@ type WorkflowRunRepoCreateOpts struct {
Backends []uuid.UUID
LatestRevision, UsedRevision int
ProjectVersion string
RequireExistingVersion bool
}

// Create will add a new WorkflowRun, associate it to a schemaVersion and increment the counter in the associated workflow
Expand Down Expand Up @@ -234,14 +236,15 @@ func (uc *WorkflowRunUseCase) Create(ctx context.Context, opts *WorkflowRunCreat
backends := []uuid.UUID{opts.CASBackendID}
result, err := uc.wfRunRepo.Create(ctx,
&WorkflowRunRepoCreateOpts{
WorkflowID: workflowUUID,
SchemaVersionID: contractRevision.Version.ID,
RunURL: opts.RunnerRunURL,
RunnerType: opts.RunnerType,
Backends: backends,
LatestRevision: contractRevision.Contract.LatestRevision,
UsedRevision: contractRevision.Version.Revision,
ProjectVersion: opts.ProjectVersion,
WorkflowID: workflowUUID,
SchemaVersionID: contractRevision.Version.ID,
RunURL: opts.RunnerRunURL,
RunnerType: opts.RunnerType,
Backends: backends,
LatestRevision: contractRevision.Contract.LatestRevision,
UsedRevision: contractRevision.Version.Revision,
ProjectVersion: opts.ProjectVersion,
RequireExistingVersion: opts.RequireExistingVersion,
})
if err != nil {
return nil, err
Expand Down
7 changes: 6 additions & 1 deletion app/controlplane/pkg/data/workflowrun.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright 2024 The Chainloop Authors.
// Copyright 2024-2025 The Chainloop Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -62,6 +62,11 @@ func (r *WorkflowRunRepo) Create(ctx context.Context, opts *biz.WorkflowRunRepoC
return nil, fmt.Errorf("checking existing version: %w", err)
}

// If RequireExistingVersion is set, fail if the version doesn't exist
if opts.RequireExistingVersion && version == nil {
return nil, biz.NewErrValidationStr(fmt.Errorf("project version %q not found", opts.ProjectVersion).Error())
}

var p *ent.WorkflowRun
versionCreated := false
// Create version and workflow in a transaction
Expand Down
2 changes: 1 addition & 1 deletion deployment/chainloop/templates/NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Configure the CLI to point to this instance, for example
--artifact-cas cas.acme.com:80

Refer to this link for more information
https://docs.chainloop.dev/getting-started/installation#configure-cli-optional
https://docs.chainloop.dev/get-started/setup

###########################################################################
USEFUL LINKS
Expand Down
Loading