You've already forked goreleaser
mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-07-15 01:34:21 +02:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
@ -89,18 +89,31 @@ func doPublish(ctx *context.Context, c client.Client) error {
|
|||||||
).List() {
|
).List() {
|
||||||
artifact := artifact
|
artifact := artifact
|
||||||
g.Go(func() error {
|
g.Go(func() error {
|
||||||
return upload(ctx, c, releaseID, artifact)
|
return upload(ctx, c, releaseID, artifact, 1)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return g.Wait()
|
return g.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
func upload(ctx *context.Context, c client.Client, releaseID int64, artifact artifact.Artifact) error {
|
const maxTries = 10
|
||||||
|
|
||||||
|
func upload(ctx *context.Context, c client.Client, releaseID int64, artifact artifact.Artifact, try int) error {
|
||||||
file, err := os.Open(artifact.Path)
|
file, err := os.Open(artifact.Path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer file.Close() // nolint: errcheck
|
defer file.Close() // nolint: errcheck
|
||||||
log.WithField("file", file.Name()).WithField("name", artifact.Name).Info("uploading to release")
|
log.WithField("file", file.Name()).WithField("name", artifact.Name).Info("uploading to release")
|
||||||
return c.Upload(ctx, releaseID, artifact.Name, file)
|
err = c.Upload(ctx, releaseID, artifact.Name, file)
|
||||||
|
if err != nil {
|
||||||
|
if try == maxTries {
|
||||||
|
return errors.Wrapf(err, "failed to upload %s after %d retries", artifact.Name, try)
|
||||||
|
}
|
||||||
|
log.WithFields(log.Fields{
|
||||||
|
"try": try,
|
||||||
|
"artifact": artifact.Name,
|
||||||
|
}).Warnf("failed to upload artifact, will retry")
|
||||||
|
return upload(ctx, c, releaseID, artifact, try+1)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@ package release
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -13,6 +12,7 @@ import (
|
|||||||
"github.com/goreleaser/goreleaser/internal/testlib"
|
"github.com/goreleaser/goreleaser/internal/testlib"
|
||||||
"github.com/goreleaser/goreleaser/pkg/config"
|
"github.com/goreleaser/goreleaser/pkg/config"
|
||||||
"github.com/goreleaser/goreleaser/pkg/context"
|
"github.com/goreleaser/goreleaser/pkg/context"
|
||||||
|
"github.com/pkg/errors"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -120,11 +120,39 @@ func TestRunPipeUploadFailure(t *testing.T) {
|
|||||||
client := &DummyClient{
|
client := &DummyClient{
|
||||||
FailToUpload: true,
|
FailToUpload: true,
|
||||||
}
|
}
|
||||||
assert.Error(t, doPublish(ctx, client))
|
assert.EqualError(t, doPublish(ctx, client), "failed to upload bin.tar.gz after 10 retries: upload failed")
|
||||||
assert.True(t, client.CreatedRelease)
|
assert.True(t, client.CreatedRelease)
|
||||||
assert.False(t, client.UploadedFile)
|
assert.False(t, client.UploadedFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRunPipeUploadRetry(t *testing.T) {
|
||||||
|
folder, err := ioutil.TempDir("", "goreleasertest")
|
||||||
|
assert.NoError(t, err)
|
||||||
|
tarfile, err := os.Create(filepath.Join(folder, "bin.tar.gz"))
|
||||||
|
assert.NoError(t, err)
|
||||||
|
var config = config.Project{
|
||||||
|
Release: config.Release{
|
||||||
|
GitHub: config.Repo{
|
||||||
|
Owner: "test",
|
||||||
|
Name: "test",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
var ctx = context.New(config)
|
||||||
|
ctx.Git = context.GitInfo{CurrentTag: "v1.0.0"}
|
||||||
|
ctx.Artifacts.Add(artifact.Artifact{
|
||||||
|
Type: artifact.UploadableArchive,
|
||||||
|
Name: "bin.tar.gz",
|
||||||
|
Path: tarfile.Name(),
|
||||||
|
})
|
||||||
|
client := &DummyClient{
|
||||||
|
FailFirstUpload: true,
|
||||||
|
}
|
||||||
|
assert.NoError(t, doPublish(ctx, client))
|
||||||
|
assert.True(t, client.CreatedRelease)
|
||||||
|
assert.True(t, client.UploadedFile)
|
||||||
|
}
|
||||||
|
|
||||||
func TestPipeDisabled(t *testing.T) {
|
func TestPipeDisabled(t *testing.T) {
|
||||||
var ctx = context.New(config.Project{
|
var ctx = context.New(config.Project{
|
||||||
Release: config.Release{
|
Release: config.Release{
|
||||||
@ -263,6 +291,7 @@ type DummyClient struct {
|
|||||||
CreatedRelease bool
|
CreatedRelease bool
|
||||||
UploadedFile bool
|
UploadedFile bool
|
||||||
UploadedFileNames []string
|
UploadedFileNames []string
|
||||||
|
FailFirstUpload bool
|
||||||
Lock sync.Mutex
|
Lock sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -278,13 +307,22 @@ func (client *DummyClient) CreateFile(ctx *context.Context, commitAuthor config.
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (client *DummyClient) Upload(ctx *context.Context, releaseID int64, name string, file *os.File) (err error) {
|
func (client *DummyClient) Upload(ctx *context.Context, releaseID int64, name string, file *os.File) error {
|
||||||
client.Lock.Lock()
|
client.Lock.Lock()
|
||||||
defer client.Lock.Unlock()
|
defer client.Lock.Unlock()
|
||||||
|
// ensure file is read to better mimic real behavior
|
||||||
|
_, err := ioutil.ReadAll(file)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrapf(err, "unexpected error")
|
||||||
|
}
|
||||||
if client.FailToUpload {
|
if client.FailToUpload {
|
||||||
return errors.New("upload failed")
|
return errors.New("upload failed")
|
||||||
}
|
}
|
||||||
|
if client.FailFirstUpload {
|
||||||
|
client.FailFirstUpload = false
|
||||||
|
return errors.New("upload failed, should retry")
|
||||||
|
}
|
||||||
client.UploadedFile = true
|
client.UploadedFile = true
|
||||||
client.UploadedFileNames = append(client.UploadedFileNames, name)
|
client.UploadedFileNames = append(client.UploadedFileNames, name)
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user