Skip to content

Commit 279e58b

Browse files
committed
add SkipRetry ff to options struct
1 parent 03e50c8 commit 279e58b

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

go/porcelain/deploy.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ type DeployOptions struct {
8383
BuildDir string
8484
LargeMediaEnabled bool
8585

86-
IsDraft bool
86+
IsDraft bool
87+
SkipRetry bool
8788

8889
Title string
8990
Branch string
@@ -344,12 +345,14 @@ func (n *Netlify) DoDeploy(ctx context.Context, options *DeployOptions, deploy *
344345
return deploy, nil
345346
}
346347

347-
if err := n.uploadFiles(ctx, deploy, options.files, options.Observer, fileUpload, options.UploadTimeout); err != nil {
348+
skipRetry := options.SkipRetry || false
349+
350+
if err := n.uploadFiles(ctx, deploy, options.files, options.Observer, fileUpload, options.UploadTimeout, skipRetry); err != nil {
348351
return nil, err
349352
}
350353

351354
if options.functions != nil {
352-
if err := n.uploadFiles(ctx, deploy, options.functions, options.Observer, functionUpload, options.UploadTimeout); err != nil {
355+
if err := n.uploadFiles(ctx, deploy, options.functions, options.Observer, functionUpload, options.UploadTimeout, options.SkipRetry); err != nil {
353356
return nil, err
354357
}
355358
}
@@ -401,7 +404,7 @@ func (n *Netlify) WaitUntilDeployLive(ctx context.Context, d *models.Deploy) (*m
401404
return n.waitForState(ctx, d, "ready")
402405
}
403406

404-
func (n *Netlify) uploadFiles(ctx context.Context, d *models.Deploy, files *deployFiles, observer DeployObserver, t uploadType, timeout time.Duration) error {
407+
func (n *Netlify) uploadFiles(ctx context.Context, d *models.Deploy, files *deployFiles, observer DeployObserver, t uploadType, timeout time.Duration, skipRetry bool) error {
405408
sharedErr := &uploadError{err: nil, mutex: &sync.Mutex{}}
406409
sem := make(chan int, n.uploadLimit)
407410
wg := &sync.WaitGroup{}
@@ -431,7 +434,7 @@ func (n *Netlify) uploadFiles(ctx context.Context, d *models.Deploy, files *depl
431434
select {
432435
case sem <- 1:
433436
wg.Add(1)
434-
go n.uploadFile(ctx, d, file, observer, t, timeout, wg, sem, sharedErr)
437+
go n.uploadFile(ctx, d, file, observer, t, timeout, wg, sem, sharedErr, skipRetry)
435438
case <-ctx.Done():
436439
log.Info("Context terminated, aborting file upload")
437440
return errors.Wrap(ctx.Err(), "aborted file upload early")
@@ -451,7 +454,7 @@ func (n *Netlify) uploadFiles(ctx context.Context, d *models.Deploy, files *depl
451454
return sharedErr.err
452455
}
453456

454-
func (n *Netlify) uploadFile(ctx context.Context, d *models.Deploy, f *FileBundle, c DeployObserver, t uploadType, timeout time.Duration, wg *sync.WaitGroup, sem chan int, sharedErr *uploadError) {
457+
func (n *Netlify) uploadFile(ctx context.Context, d *models.Deploy, f *FileBundle, c DeployObserver, t uploadType, timeout time.Duration, wg *sync.WaitGroup, sem chan int, sharedErr *uploadError, skipRetry bool) {
455458
defer func() {
456459
wg.Done()
457460
<-sem
@@ -545,7 +548,7 @@ func (n *Netlify) uploadFile(ctx context.Context, d *models.Deploy, f *FileBundl
545548
sharedErr.mutex.Unlock()
546549
}
547550

548-
if apiErr.Code() == 400 || apiErr.Code() == 422 {
551+
if skipRetry && (apiErr.Code() == 400 || apiErr.Code() == 422) {
549552
sharedErr.mutex.Lock()
550553
sharedErr.err = operationError
551554
sharedErr.mutex.Unlock()

go/porcelain/deploy_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ func TestUploadFiles_Cancelation(t *testing.T) {
287287
for _, bundle := range files.Files {
288288
d.Required = append(d.Required, bundle.Sum)
289289
}
290-
err = client.uploadFiles(ctx, d, files, nil, fileUpload, time.Minute)
290+
err = client.uploadFiles(ctx, d, files, nil, fileUpload, time.Minute, false)
291291
require.ErrorIs(t, err, gocontext.Canceled)
292292
}
293293

@@ -317,7 +317,7 @@ func TestUploadFiles_Errors(t *testing.T) {
317317
for _, bundle := range files.Files {
318318
d.Required = append(d.Required, bundle.Sum)
319319
}
320-
err = client.uploadFiles(ctx, d, files, nil, fileUpload, time.Minute)
320+
err = client.uploadFiles(ctx, d, files, nil, fileUpload, time.Minute, false)
321321
require.Equal(t, err.Error(), "[PUT /deploys/{deploy_id}/files/{path}][500] uploadDeployFile default &{Code:0 Message:}")
322322
}
323323

@@ -377,11 +377,11 @@ func TestUploadFiles_SkipEqualFiles(t *testing.T) {
377377
d.Required = []string{files.Sums["a.html"]}
378378
d.RequiredFunctions = []string{functions.Sums["a"]}
379379

380-
err = client.uploadFiles(ctx, d, files, nil, fileUpload, time.Minute)
380+
err = client.uploadFiles(ctx, d, files, nil, fileUpload, time.Minute, false)
381381
require.NoError(t, err)
382382
assert.Equal(t, 1, serverRequests)
383383

384-
err = client.uploadFiles(ctx, d, functions, nil, functionUpload, time.Minute)
384+
err = client.uploadFiles(ctx, d, functions, nil, functionUpload, time.Minute, false)
385385
require.NoError(t, err)
386386
assert.Equal(t, 2, serverRequests)
387387
}
@@ -437,7 +437,7 @@ func TestUploadFunctions_RetryCountHeader(t *testing.T) {
437437
d.RequiredFunctions = append(d.RequiredFunctions, bundle.Sum)
438438
}
439439

440-
require.NoError(t, client.uploadFiles(apiCtx, d, files, nil, functionUpload, time.Minute))
440+
require.NoError(t, client.uploadFiles(apiCtx, d, files, nil, functionUpload, time.Minute, false))
441441
}
442442

443443
func TestBundle(t *testing.T) {

0 commit comments

Comments
 (0)