@@ -29,12 +29,16 @@ import (
2929type AttestationInitOpts struct {
3030 * ActionsOpts
3131 DryRun bool
32+ // Force the initialization and override any existing, in-progress ones.
33+ // Note that this is only useful when local-based attestation state is configured
34+ // since it's a protection to make sure you don't override the state by mistake
35+ Force bool
3236}
3337
3438type AttestationInit struct {
3539 * ActionsOpts
36- dryRun bool
37- c * crafter.Crafter
40+ dryRun , force bool
41+ c * crafter.Crafter
3842}
3943
4044// ErrAttestationAlreadyExist means that there is an attestation in progress
@@ -58,6 +62,7 @@ func NewAttestationInit(cfg *AttestationInitOpts) (*AttestationInit, error) {
5862 ActionsOpts : cfg .ActionsOpts ,
5963 c : c ,
6064 dryRun : cfg .DryRun ,
65+ force : cfg .Force ,
6166 }, nil
6267}
6368
@@ -67,6 +72,14 @@ func (action *AttestationInit) Run(ctx context.Context, contractRevision int) (s
6772 return "" , errors .New ("remote state is not compatible with dry-run mode" )
6873 }
6974
75+ // During local initializations we need to make sure if there is already an attestation in progress
76+ // If it is and we are not "forcing" the initialization, we should return an error
77+ if ! action .UseAttestationRemoteState && ! action .force {
78+ if initialized , _ := action .c .AlreadyInitialized (ctx , "" ); initialized {
79+ return "" , ErrAttestationAlreadyExist
80+ }
81+ }
82+
7083 action .Logger .Debug ().Msg ("Retrieving attestation definition" )
7184 client := pb .NewAttestationServiceClient (action .ActionsOpts .CPConnection )
7285 // get information of the workflow
0 commit comments