@@ -70,7 +70,7 @@ func NewAttestationInit(cfg *AttestationInitOpts) (*AttestationInit, error) {
70
70
}
71
71
72
72
// 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 ) {
74
74
if action .dryRun && action .useRemoteState {
75
75
return "" , errors .New ("remote state is not compatible with dry-run mode" )
76
76
}
@@ -85,7 +85,18 @@ func (action *AttestationInit) Run(ctx context.Context, contractRevision int, pr
85
85
86
86
action .Logger .Debug ().Msg ("Retrieving attestation definition" )
87
87
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
89
100
contractResp , err := client .GetContract (ctx , & pb.AttestationServiceGetContractRequest {
90
101
ContractRevision : int32 (contractRevision ),
91
102
WorkflowName : workflowName ,
@@ -95,10 +106,7 @@ func (action *AttestationInit) Run(ctx context.Context, contractRevision int, pr
95
106
return "" , err
96
107
}
97
108
98
- workflow := contractResp .GetResult ().GetWorkflow ()
99
109
contractVersion := contractResp .Result .GetContract ()
100
- contract := contractResp .GetResult ().GetContract ().GetV1 ()
101
-
102
110
workflowMeta := & clientAPI.WorkflowMetadata {
103
111
WorkflowId : workflow .GetId (),
104
112
Name : workflow .GetName (),
@@ -110,7 +118,7 @@ func (action *AttestationInit) Run(ctx context.Context, contractRevision int, pr
110
118
action .Logger .Debug ().Msg ("workflow contract and metadata retrieved from the control plane" )
111
119
112
120
// 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 )
114
122
if err != nil {
115
123
return "" , ErrRunnerContextNotFound {err .Error ()}
116
124
}
0 commit comments