Skip to content

feat(cli): extend workflow contract with apply#2469

Merged
Piskoo merged 7 commits into
chainloop-dev:mainfrom
Piskoo:feat-add-apply-to-contracts
Oct 21, 2025
Merged

feat(cli): extend workflow contract with apply#2469
Piskoo merged 7 commits into
chainloop-dev:mainfrom
Piskoo:feat-add-apply-to-contracts

Conversation

@Piskoo

@Piskoo Piskoo commented Oct 15, 2025

Copy link
Copy Markdown
Contributor

This PR adds apply command that combines create and update functionality into one.

Example

# Create/Update v1 contract
cl wf contract apply --contract contract-schema.yaml --name contract-test

Signed-off-by: Sylwester Piskozub <sylwesterpiskozub@gmail.com>
Signed-off-by: Sylwester Piskozub <sylwesterpiskozub@gmail.com>
Signed-off-by: Sylwester Piskozub <sylwesterpiskozub@gmail.com>
@Piskoo Piskoo marked this pull request as ready for review October 15, 2025 21:48
Comment thread app/cli/cmd/workflow_contract_apply.go Outdated
# Apply to a specific project
chainloop workflow contract apply --contract my-contract.yaml --project my-project`,
PreRunE: func(_ *cobra.Command, _ []string) error {
if filePath == "" && name == "" {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would make more sense if this validates that either the explicit name or a name in the spec is available, this new helper can probably be made generically as you did in the middleware

@migmartri migmartri left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

Comment thread app/cli/pkg/action/workflow_contract_apply.go Outdated
}

// extractContractNameFromContent tries to extract the contract name from the contract file content
func extractContractNameFromRawSchema(content []byte) (string, error) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function could be made generically by marshalling to anything with meta and run from cmd as part of the validation as mentioned above.

Comment thread app/cli/pkg/action/workflow_contract_apply.go Outdated
Comment thread app/cli/pkg/action/workflow_contract_apply.go Outdated
Signed-off-by: Sylwester Piskozub <sylwesterpiskozub@gmail.com>
Signed-off-by: Sylwester Piskozub <sylwesterpiskozub@gmail.com>
Comment thread app/cli/cmd/workflow_contract_apply.go Outdated
}

cmd.Flags().StringVarP(&filePath, "contract", "f", "", "workflow contract file path (optional)")
cmd.Flags().StringVar(&name, "name", "", "contract name (required if no contract file provided)")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't match with the command description nor the examples (Apply a contract from a file. This command will create the contract if it doesn't exist). How would it work then? I would expect that the file was mandatory.

Signed-off-by: Sylwester Piskozub <sylwesterpiskozub@gmail.com>
Signed-off-by: Sylwester Piskozub <sylwesterpiskozub@gmail.com>
@Piskoo

Piskoo commented Oct 20, 2025

Copy link
Copy Markdown
Contributor Author

I've decided to remove support for schema v2 from this PR, all schema v2 related code will be a part of #2467. Here we have wf contract apply based on create and update that handles old schema.
cc/ @jiparis @migmartri

@jiparis jiparis left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Thanks!

@Piskoo Piskoo merged commit f9c6b26 into chainloop-dev:main Oct 21, 2025
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants