1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-03-17 20:47:50 +02:00

fix: eventual race condition in artifacts (#3310)

* fix: eventual race condition in artifacts

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>

* fix: locks

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>

* fix: tests

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
Carlos Alexandro Becker 2022-08-16 02:05:36 -03:00 committed by GitHub
parent bb4bbde2ac
commit c83663cc26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 21 additions and 19 deletions

View File

@ -268,13 +268,15 @@ func New() Artifacts {
// List return the actual list of artifacts.
func (artifacts Artifacts) List() []*Artifact {
artifacts.lock.Lock()
defer artifacts.lock.Unlock()
return artifacts.items
}
// GroupByID groups the artifacts by their ID.
func (artifacts Artifacts) GroupByID() map[string][]*Artifact {
result := map[string][]*Artifact{}
for _, a := range artifacts.items {
for _, a := range artifacts.List() {
id := a.ID()
if id == "" {
continue
@ -287,7 +289,7 @@ func (artifacts Artifacts) GroupByID() map[string][]*Artifact {
// GroupByPlatform groups the artifacts by their platform.
func (artifacts Artifacts) GroupByPlatform() map[string][]*Artifact {
result := map[string][]*Artifact{}
for _, a := range artifacts.items {
for _, a := range artifacts.List() {
plat := a.Goos + a.Goarch + a.Goarm + a.Gomips + a.Goamd64
result[plat] = append(result[plat], a)
}
@ -485,7 +487,7 @@ func (artifacts *Artifacts) Filter(filter Filter) Artifacts {
}
result := New()
for _, a := range artifacts.items {
for _, a := range artifacts.List() {
if filter(a) {
result.items = append(result.items, a)
}
@ -507,7 +509,7 @@ type VisitFn func(a *Artifact) error
// Visit executes the given function for each artifact in the list.
func (artifacts Artifacts) Visit(fn VisitFn) error {
for _, artifact := range artifacts.items {
for _, artifact := range artifacts.List() {
if err := fn(artifact); err != nil {
return err
}

View File

@ -465,13 +465,13 @@ func TestRunPipe(t *testing.T) {
}
func TestRunPipeNoBuilds(t *testing.T) {
ctx := &context.Context{
TokenType: context.TokenTypeGitHub,
Config: config.Project{
ctx := context.New(
config.Project{
ProjectName: "foo",
AURs: []config.AUR{{}},
},
}
)
ctx.TokenType = context.TokenTypeGitHub
client := client.NewMock()
require.NoError(t, Pipe{}.Default(ctx))
require.Equal(t, ErrNoArchivesFound, runAll(ctx, client))

View File

@ -747,9 +747,8 @@ func TestRunPipeForMultipleArmVersions(t *testing.T) {
}
func TestRunPipeNoBuilds(t *testing.T) {
ctx := &context.Context{
TokenType: context.TokenTypeGitHub,
Config: config.Project{
ctx := context.New(
config.Project{
Brews: []config.Homebrew{
{
Tap: config.RepoRef{
@ -759,7 +758,8 @@ func TestRunPipeNoBuilds(t *testing.T) {
},
},
},
}
)
ctx.TokenType = context.TokenTypeGitHub
client := client.NewMock()
require.Equal(t, ErrNoArchivesFound, runAll(ctx, client))
require.False(t, client.CreatedFile)

View File

@ -1252,13 +1252,13 @@ func TestDefaultDockerfile(t *testing.T) {
}
func TestDraftRelease(t *testing.T) {
ctx := &context.Context{
Config: config.Project{
ctx := context.New(
config.Project{
Release: config.Release{
Draft: true,
},
},
}
)
require.False(t, pipe.IsSkip(Pipe{}.Publish(ctx)))
}

View File

@ -731,9 +731,8 @@ func TestRunPipeForMultipleArmVersions(t *testing.T) {
}
func TestRunPipeNoBuilds(t *testing.T) {
ctx := &context.Context{
TokenType: context.TokenTypeGitHub,
Config: config.Project{
ctx := context.New(
config.Project{
Krews: []config.Krew{
{
Name: manifestName(t),
@ -746,7 +745,8 @@ func TestRunPipeNoBuilds(t *testing.T) {
},
},
},
}
)
ctx.TokenType = context.TokenTypeGitHub
client := client.NewMock()
require.Equal(t, ErrNoArchivesFound, runAll(ctx, client))
require.False(t, client.CreatedFile)