@@ -70,7 +70,7 @@ func NewAttestationInit(cfg *AttestationInitOpts) (*AttestationInit, error) {
7070}
7171
7272// returns the attestation ID
73- func (action * AttestationInit ) Run (ctx context.Context , contractRevision int , projectName , workflowName string ) (string , error ) {
73+ func (action * AttestationInit ) Run (ctx context.Context , contractRevision int , projectName , workflowName , newWorkflowContractName string ) (string , error ) {
7474 if action .dryRun && action .useRemoteState {
7575 return "" , errors .New ("remote state is not compatible with dry-run mode" )
7676 }
@@ -85,7 +85,18 @@ func (action *AttestationInit) Run(ctx context.Context, contractRevision int, pr
8585
8686 action .Logger .Debug ().Msg ("Retrieving attestation definition" )
8787 client := pb .NewAttestationServiceClient (action .ActionsOpts .CPConnection )
88- // get information of the workflow
88+ // 1 - Find or create the workflow
89+ workflowsResp , err := client .FindOrCreateWorkflow (ctx , & pb.FindOrCreateWorkflowRequest {
90+ ProjectName : projectName ,
91+ WorkflowName : workflowName ,
92+ ContractName : newWorkflowContractName ,
93+ })
94+ if err != nil {
95+ return "" , err
96+ }
97+ workflow := workflowsResp .GetResult ()
98+
99+ // 2 - Get contract
89100 contractResp , err := client .GetContract (ctx , & pb.AttestationServiceGetContractRequest {
90101 ContractRevision : int32 (contractRevision ),
91102 WorkflowName : workflowName ,
@@ -95,10 +106,7 @@ func (action *AttestationInit) Run(ctx context.Context, contractRevision int, pr
95106 return "" , err
96107 }
97108
98- workflow := contractResp .GetResult ().GetWorkflow ()
99109 contractVersion := contractResp .Result .GetContract ()
100- contract := contractResp .GetResult ().GetContract ().GetV1 ()
101-
102110 workflowMeta := & clientAPI.WorkflowMetadata {
103111 WorkflowId : workflow .GetId (),
104112 Name : workflow .GetName (),
@@ -110,7 +118,7 @@ func (action *AttestationInit) Run(ctx context.Context, contractRevision int, pr
110118 action .Logger .Debug ().Msg ("workflow contract and metadata retrieved from the control plane" )
111119
112120 // Auto discover the runner context and enforce against the one in the contract if needed
113- discoveredRunner , err := crafter .DiscoverAndEnforceRunner (contract .GetRunner ().GetType (), action .dryRun , action .Logger )
121+ discoveredRunner , err := crafter .DiscoverAndEnforceRunner (contractVersion . GetV1 () .GetRunner ().GetType (), action .dryRun , action .Logger )
114122 if err != nil {
115123 return "" , ErrRunnerContextNotFound {err .Error ()}
116124 }
0 commit comments