@@ -30,7 +30,7 @@ func NewWorkflowContractApply(cfg *ActionsOpts) *WorkflowContractApply {
3030 return & WorkflowContractApply {cfg }
3131}
3232
33- func (action * WorkflowContractApply ) Run (ctx context.Context , contractName string , contractPath string , description * string , projectName string ) (* WorkflowContractItem , error ) {
33+ func (action * WorkflowContractApply ) Run (ctx context.Context , contractName string , contractPath string , description * string , projectName string ) (* WorkflowContractItem , bool , error ) {
3434 client := pb .NewWorkflowContractServiceClient (action .cfg .CPConnection )
3535
3636 // Try to describe the specific contract first to determine if we should create or update
@@ -43,14 +43,16 @@ func (action *WorkflowContractApply) Run(ctx context.Context, contractName strin
4343 raw , err := LoadFileOrURL (contractPath )
4444 if err != nil {
4545 action .cfg .Logger .Debug ().Err (err ).Msg ("loading the contract" )
46- return nil , err
46+ return nil , false , err
4747 }
4848 rawContract = raw
4949 }
5050
51- _ , err := client .Describe (ctx , describeReq )
51+ describeRes , err := client .Describe (ctx , describeReq )
5252 if err == nil {
5353 // Contract exists, perform update
54+ prevRevision := describeRes .Result .GetRevision ().GetRevision ()
55+
5456 updateReq := & pb.WorkflowContractServiceUpdateRequest {
5557 Name : contractName ,
5658 Description : description ,
@@ -59,10 +61,12 @@ func (action *WorkflowContractApply) Run(ctx context.Context, contractName strin
5961
6062 res , err := client .Update (ctx , updateReq )
6163 if err != nil {
62- return nil , fmt .Errorf ("failed to update existing contract '%s': %w" , contractName , err )
64+ return nil , false , fmt .Errorf ("failed to update existing contract '%s': %w" , contractName , err )
6365 }
6466
65- return pbWorkflowContractItemToAction (res .Result .Contract ), nil
67+ unchanged := prevRevision == res .Result .GetRevision ().GetRevision ()
68+
69+ return pbWorkflowContractItemToAction (res .Result .Contract ), unchanged , nil
6670 }
6771
6872 // Contract doesn't exist, perform create
@@ -80,8 +84,8 @@ func (action *WorkflowContractApply) Run(ctx context.Context, contractName strin
8084
8185 res , err := client .Create (ctx , createReq )
8286 if err != nil {
83- return nil , fmt .Errorf ("failed to create new contract '%s': %w" , contractName , err )
87+ return nil , false , fmt .Errorf ("failed to create new contract '%s': %w" , contractName , err )
8488 }
8589
86- return pbWorkflowContractItemToAction (res .Result ), nil
90+ return pbWorkflowContractItemToAction (res .Result ), false , nil
8791}
0 commit comments