Skip to content

Conversation

@Piskoo
Copy link
Collaborator

@Piskoo Piskoo commented Oct 15, 2025

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
# 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
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

Copy link
Member

@migmartri migmartri left a comment

Choose a reason for hiding this comment

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

Thanks

}

// extractContractNameFromContent tries to extract the contract name from the contract file content
func extractContractNameFromRawSchema(content []byte) (string, error) {
Copy link
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.

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

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
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
Copy link
Collaborator Author

Piskoo commented Oct 20, 2025

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

Copy link
Member

@jiparis jiparis left a comment

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