Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: eventual race condition in artifacts #3310

Merged
merged 6 commits into from Aug 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 6 additions & 4 deletions internal/artifact/artifact.go
Expand Up @@ -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
Expand All @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand All @@ -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
}
Expand Down
8 changes: 4 additions & 4 deletions internal/pipe/aur/aur_test.go
Expand Up @@ -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))
Expand Down
8 changes: 4 additions & 4 deletions internal/pipe/brew/brew_test.go
Expand Up @@ -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{
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions internal/pipe/docker/docker_test.go
Expand Up @@ -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)))
}
Expand Down
8 changes: 4 additions & 4 deletions internal/pipe/krew/krew_test.go
Expand Up @@ -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),
Expand All @@ -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)
Expand Down