@@ -125,11 +125,11 @@ func (r *Runtime) AddRelocation(args ActionArguments) cnabaction.OperationConfig
125
125
}
126
126
}
127
127
128
- func (r * Runtime ) Execute (ctx context.Context , args ActionArguments ) error {
128
+ func (r * Runtime ) Execute (ctx context.Context , args ActionArguments ) (storage. Run , storage. Result , error ) {
129
129
// Check if we've been asked to stop before executing long blocking calls
130
130
select {
131
131
case <- ctx .Done ():
132
- return ctx .Err ()
132
+ return storage. Run {}, storage. Result {}, ctx .Err ()
133
133
default :
134
134
ctx , log := tracing .StartSpan (ctx ,
135
135
attribute .String ("action" , args .Action ),
@@ -140,33 +140,33 @@ func (r *Runtime) Execute(ctx context.Context, args ActionArguments) error {
140
140
args .Installation .AddToTrace (ctx )
141
141
142
142
if args .Action == "" {
143
- return log .Error (errors .New ("action is required" ))
143
+ return storage. Run {}, storage. Result {}, log .Error (errors .New ("action is required" ))
144
144
}
145
145
146
146
b , err := r .ProcessBundle (ctx , args .BundleReference .Definition )
147
147
if err != nil {
148
- return log .Error (err )
148
+ return storage. Run {}, storage. Result {}, log .Error (err )
149
149
}
150
150
151
151
currentRun , err := r .CreateRun (ctx , args , b )
152
152
if err != nil {
153
- return log .Error (err )
153
+ return storage. Run {}, storage. Result {}, log .Error (err )
154
154
}
155
155
156
156
// Validate the action
157
157
if _ , err := b .GetAction (currentRun .Action ); err != nil {
158
- return log .Error (fmt .Errorf ("invalid action '%s' specified for bundle %s: %w" , currentRun .Action , b .Name , err ))
158
+ return storage. Run {}, storage. Result {}, log .Error (fmt .Errorf ("invalid action '%s' specified for bundle %s: %w" , currentRun .Action , b .Name , err ))
159
159
}
160
160
161
161
creds , err := r .loadCredentials (ctx , b , args )
162
162
if err != nil {
163
- return log .Error (fmt .Errorf ("not load credentials: %w" , err ))
163
+ return storage. Run {}, storage. Result {}, log .Error (fmt .Errorf ("not load credentials: %w" , err ))
164
164
}
165
165
166
166
log .Debugf ("Using runtime driver %s\n " , args .Driver )
167
167
driver , err := r .newDriver (args .Driver , args )
168
168
if err != nil {
169
- return log .Error (fmt .Errorf ("unable to instantiate driver: %w" , err ))
169
+ return storage. Run {}, storage. Result {}, log .Error (fmt .Errorf ("unable to instantiate driver: %w" , err ))
170
170
}
171
171
172
172
a := cnabaction .New (driver )
@@ -175,7 +175,7 @@ func (r *Runtime) Execute(ctx context.Context, args ActionArguments) error {
175
175
if currentRun .ShouldRecord () {
176
176
err = r .SaveRun (ctx , args .Installation , currentRun , cnab .StatusRunning )
177
177
if err != nil {
178
- return log .Error (fmt .Errorf ("could not save the pending action's status, the bundle was not executed: %w" , err ))
178
+ return currentRun , storage. Result {}, log .Error (fmt .Errorf ("could not save the pending action's status, the bundle was not executed: %w" , err ))
179
179
}
180
180
}
181
181
@@ -187,19 +187,20 @@ func (r *Runtime) Execute(ctx context.Context, args ActionArguments) error {
187
187
tracing .ObjectAttribute ("cnab-credentials" , cnabCreds ))
188
188
opResult , result , err := a .Run (cnabClaim , cnabCreds , r .ApplyConfig (ctx , args )... )
189
189
190
+ currentResult := currentRun .NewResultFrom (result )
190
191
if currentRun .ShouldRecord () {
191
192
if err != nil {
192
193
err = r .appendFailedResult (ctx , err , currentRun )
193
- return log .Error (fmt .Errorf ("failed to record that %s for installation %s failed: %w" , args .Action , args .Installation .Name , err ))
194
+ return currentRun , currentResult , log .Error (fmt .Errorf ("failed to record that %s for installation %s failed: %w" , args .Action , args .Installation .Name , err ))
194
195
}
195
- return r .SaveOperationResult (ctx , opResult , args .Installation , currentRun , currentRun . NewResultFrom ( result ) )
196
+ return currentRun , currentResult , r .SaveOperationResult (ctx , opResult , args .Installation , currentRun , currentResult )
196
197
}
197
198
198
199
if err != nil {
199
- return log .Error (fmt .Errorf ("execution of %s for installation %s failed: %w" , args .Action , args .Installation .Name , err ))
200
+ return currentRun , currentResult , log .Error (fmt .Errorf ("execution of %s for installation %s failed: %w" , args .Action , args .Installation .Name , err ))
200
201
}
201
202
202
- return nil
203
+ return currentRun , currentResult , nil
203
204
}
204
205
}
205
206
0 commit comments