From 37f8167fd90173b17598beb40b977d95553e34d9 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Tue, 23 Nov 2021 09:40:47 -0300 Subject: [PATCH] fix: checksum extra_files when no builds (#2692) --- internal/pipe/checksums/checksums.go | 7 ++++--- internal/pipe/checksums/checksums_test.go | 11 +++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/internal/pipe/checksums/checksums.go b/internal/pipe/checksums/checksums.go index 1e7d81657..373c92689 100644 --- a/internal/pipe/checksums/checksums.go +++ b/internal/pipe/checksums/checksums.go @@ -47,9 +47,6 @@ func (Pipe) Run(ctx *context.Context) (err error) { } artifactList := ctx.Artifacts.Filter(filter).List() - if len(artifactList) == 0 { - return nil - } extraFiles, err := extrafiles.Find(ctx, ctx.Config.Checksum.ExtraFiles) if err != nil { @@ -64,6 +61,10 @@ func (Pipe) Run(ctx *context.Context) (err error) { }) } + if len(artifactList) == 0 { + return nil + } + g := semerrgroup.New(ctx.Parallelism) sumLines := make([]string, len(artifactList)) for i, artifact := range artifactList { diff --git a/internal/pipe/checksums/checksums_test.go b/internal/pipe/checksums/checksums_test.go index 8fb41f45c..e324cf348 100644 --- a/internal/pipe/checksums/checksums_test.go +++ b/internal/pipe/checksums/checksums_test.go @@ -230,6 +230,7 @@ func TestPipeCheckSumsWithExtraFiles(t *testing.T) { tests := map[string]struct { extraFiles []config.ExtraFile + ids []string want []string }{ "default": { @@ -256,6 +257,15 @@ func TestPipeCheckSumsWithExtraFiles(t *testing.T) { extraFileBar, }, }, + "one extra file with no builds": { + extraFiles: []config.ExtraFile{ + {Glob: extraFileFooRelPath}, + }, + ids: []string{"yada yada yada"}, + want: []string{ + extraFileFoo, + }, + }, } for name, tt := range tests { @@ -271,6 +281,7 @@ func TestPipeCheckSumsWithExtraFiles(t *testing.T) { Algorithm: "sha256", NameTemplate: "checksums.txt", ExtraFiles: tt.extraFiles, + IDs: tt.ids, }, }, )