MCPcopy Create free account
hub / github.com/chainloop-dev/chainloop / newWorkflowCreateCmd

Function newWorkflowCreateCmd

app/cli/cmd/workflow_create.go:28–104  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

26)
27
28func newWorkflowCreateCmd() *cobra.Command {
29 var workflowName, description, project, team, contractRef string
30 var public, skipIfExists bool
31
32 cmd := &cobra.Command{
33 Use: "create",
34 Short: "Create a new workflow",
35 Example: ` chainloop workflow create --name [workflowName] --project [projectName]
36
37 # Indicate an optional team name
38 chainloop workflow create --name release --project skynet --team core-cyberdyne
39
40 # Associate an existing contract referenced by its ID
41 chainloop workflow create --name release --project skynet --contract deadbeed
42
43 # Or create a new contract by pointing to a local file or URL
44 chainloop workflow create --name release --project skynet --contract ./skynet.contract.yaml
45 chainloop workflow create --name release --project skynet --contract https://skynet.org/contract.yaml
46 `,
47 RunE: func(cmd *cobra.Command, args []string) error {
48 opts := &action.NewWorkflowCreateOpts{
49 Name: workflowName, Team: team, Project: project, Description: description,
50 Public: public,
51 }
52
53 // Try to load it if it's a file or URL otherwise assume it's an existing contract name
54 if contractRef != "" {
55 raw, err := action.LoadFileOrURL(contractRef)
56 if err != nil {
57 opts.ContractName = contractRef
58 } else {
59 opts.ContractBytes = raw
60 }
61 }
62
63 wf, err := action.NewWorkflowCreate(ActionOpts).Run(opts)
64 if err != nil {
65 if s, ok := status.FromError(err); ok {
66 if s.Code() == codes.AlreadyExists {
67 if skipIfExists {
68 logger.Info().Msg("Workflow already exists")
69 return nil
70 }
71 }
72 }
73
74 return err
75 }
76
77 // Print the workflow table
78 if err := output.EncodeOutput(flagOutputFormat, wf, workflowItemTableOutput); err != nil {
79 return fmt.Errorf("failed to print workflow: %w", err)
80 }
81
82 logger.Info().Msg("To Attest this workflow you'll need to provide an API token. See \"chainloop organization api-token\" command for more information.\n")
83
84 return nil
85 },

Callers 1

newWorkflowCmdFunction · 0.85

Calls 5

LoadFileOrURLFunction · 0.92
NewWorkflowCreateFunction · 0.92
EncodeOutputFunction · 0.92
InfoMethod · 0.65
RunMethod · 0.45

Tested by

no test coverage detected