55 "fmt"
66 "time"
77
8+ "github.com/cyclimse/mcp-scaleway-functions/internal/constants"
89 "github.com/modelcontextprotocol/go-sdk/mcp"
910 function "github.com/scaleway/scaleway-sdk-go/api/function/v1beta1"
1011 "github.com/scaleway/scaleway-sdk-go/scw"
@@ -107,6 +108,8 @@ func (t *Tools) CreateAndDeployFunction(
107108 return nil , Function {}, fmt .Errorf ("converting to SDK request: %w" , err )
108109 }
109110
111+ // We always create the function first before zipping the code archive for
112+ // faster feedback to the user in case of errors.
110113 fun , err := t .functionsAPI .CreateFunction (createReq , scw .WithContext (ctx ))
111114 if err != nil {
112115 return nil , Function {}, fmt .Errorf ("creating function: %w" , err )
@@ -119,6 +122,20 @@ func (t *Tools) CreateAndDeployFunction(
119122 return nil , Function {}, fmt .Errorf ("creating archive: %w" , err )
120123 }
121124
125+ tags := append (fun .Tags , constants .TagCodeArchiveDigest + archive .Digest )
126+
127+ // However, as a side-effect of doing creation first, we need to
128+ // update the function to add the code archive digest tag (which helps
129+ // avoid redeploying the same code in future updates).
130+ fun , err = t .functionsAPI .UpdateFunction (& function.UpdateFunctionRequest {
131+ FunctionID : fun .ID ,
132+ Redeploy : scw .BoolPtr (false ),
133+ Tags : scw .StringsPtr (tags ),
134+ }, scw .WithContext (ctx ))
135+ if err != nil {
136+ return nil , Function {}, fmt .Errorf ("updating function with code archive digest tag: %w" , err )
137+ }
138+
122139 presignedURLResp , err := t .functionsAPI .GetFunctionUploadURL (
123140 & function.GetFunctionUploadURLRequest {
124141 FunctionID : fun .ID ,
0 commit comments