Skip to content

Commit

Permalink
feat: replace zglob with fileglob (#1889)
Browse files Browse the repository at this point in the history
* fix: replace zglob with gobwas/glob

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: added missing file

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* test: fixed wrong assertions

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: use fileglob

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* feat: update fileglob

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: update fileglob

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: tests

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: test errors

* fix: empty file

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: update fileglob

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
caarlos0 and kodiakhq[bot] committed Nov 10, 2020
1 parent 27aa687 commit 4a6693f
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 36 deletions.
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -12,12 +12,12 @@ require (
github.com/fatih/color v1.10.0
github.com/golangci/golangci-lint v1.32.2
github.com/google/go-github/v28 v28.1.1
github.com/goreleaser/fileglob v0.3.0
github.com/goreleaser/nfpm v1.9.0
github.com/hashicorp/go-version v1.2.1 // indirect
github.com/imdario/mergo v0.3.11
github.com/jarcoal/httpmock v1.0.6
github.com/mattn/go-shellwords v1.0.10
github.com/mattn/go-zglob v0.0.4-0.20201013150311-602f75124917
github.com/mitchellh/go-homedir v1.1.0
github.com/spf13/cobra v1.1.1
github.com/stretchr/testify v1.6.1
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Expand Up @@ -353,6 +353,8 @@ github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGa
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/goreleaser/chglog v0.1.1 h1:UaY3enMEVeavOaZyCraLn+2iM7/2T0yji8Mh7ZFsDp4=
github.com/goreleaser/chglog v0.1.1/go.mod h1:xSDa/73C0TxBcLvoT2JHh47QyXpCx5rrNVzJKyeFGPw=
github.com/goreleaser/fileglob v0.3.0 h1:ef5bTud50fxihAjR2IWP0lGpyaPOgCD5qWfo14azJyI=
github.com/goreleaser/fileglob v0.3.0/go.mod h1:kNcPrPzjCp+Ox3jmXLU5QEsjhqrtLBm6OnXAif8KRl8=
github.com/goreleaser/nfpm v1.9.0 h1:gkSdiy55cACuZsaLOSt9F1hKFiKmNGHNMjw9W/ujv9Y=
github.com/goreleaser/nfpm v1.9.0/go.mod h1:N2SmYHJ8yQum2q5oXh2D4qvip9+X4PDMoyHmuxs/JXo=
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
Expand Down Expand Up @@ -623,6 +625,8 @@ github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasO
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
github.com/spf13/afero v1.3.2 h1:GDarE4TJQI52kYSbSAmLiId1Elfj+xgSDqrUZxFhxlU=
github.com/spf13/afero v1.3.2/go.mod h1:5KUK8ByomD5Ti5Artl0RtHeI5pTF7MIDuXL3yY520V4=
github.com/spf13/afero v1.4.1 h1:asw9sl74539yqavKaglDM5hFpdJVK0Y5Dr/JOgQ89nQ=
github.com/spf13/afero v1.4.1/go.mod h1:Ai8FlHk4v/PARR026UzYexafAt9roJ7LcLMAmO6Z93I=
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
github.com/spf13/cast v1.3.1 h1:nFm6S0SMdyzrzcmThSipiEubIDy8WEXKNZ0UOgiRpng=
github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
Expand Down
4 changes: 2 additions & 2 deletions internal/extrafiles/extra_files.go
Expand Up @@ -6,8 +6,8 @@ import (
"path/filepath"

"github.com/apex/log"
"github.com/goreleaser/fileglob"
"github.com/goreleaser/goreleaser/pkg/config"
"github.com/mattn/go-zglob"
)

// Find resolves extra files globs et al into a map of names/paths or an error.
Expand All @@ -17,7 +17,7 @@ func Find(files []config.ExtraFile) (map[string]string, error) {
if extra.Glob == "" {
continue
}
files, err := zglob.Glob(extra.Glob)
files, err := fileglob.Glob(extra.Glob)
if err != nil {
return result, fmt.Errorf("globbing failed for pattern %s: %w", extra.Glob, err)
}
Expand Down
60 changes: 35 additions & 25 deletions internal/extrafiles/extra_files_test.go
Expand Up @@ -7,18 +7,40 @@ import (
"github.com/stretchr/testify/require"
)

func TestShouldGetAllFiles(t *testing.T) {
func TestShouldGetSpecificFile(t *testing.T) {
globs := []config.ExtraFile{
{Glob: "./testdata/file1.golden"},
}

files, err := Find(globs)
require.NoError(t, err)
require.Equal(t, 1, len(files))
require.Len(t, files, 1)

path, ok := files["file1.golden"]
require.True(t, ok)
require.Equal(t, path, "./testdata/file1.golden")
require.Equal(t, "testdata/file1.golden", files["file1.golden"])
}

func TestFailToGetSpecificFile(t *testing.T) {
globs := []config.ExtraFile{
{Glob: "./testdata/file453.golden"},
}

files, err := Find(globs)
require.EqualError(t, err, "globbing failed for pattern ./testdata/file453.golden: matching \"testdata/file453.golden\": file does not exist")
require.Empty(t, files)
}

func TestShouldGetFilesWithSuperStar(t *testing.T) {
globs := []config.ExtraFile{
{Glob: "./**/file?.golden"},
}

files, err := Find(globs)
require.NoError(t, err)
require.Len(t, files, 3)

require.Equal(t, "testdata/file2.golden", files["file2.golden"])
require.Equal(t, "testdata/file1.golden", files["file1.golden"])
require.Equal(t, "testdata/sub/file5.golden", files["file5.golden"])
}

func TestShouldGetAllFilesWithGoldenExtension(t *testing.T) {
Expand All @@ -28,15 +50,10 @@ func TestShouldGetAllFilesWithGoldenExtension(t *testing.T) {

files, err := Find(globs)
require.NoError(t, err)
require.Equal(t, 2, len(files))

path, ok := files["file1.golden"]
require.True(t, ok)
require.Equal(t, path, "testdata/file1.golden")
require.Len(t, files, 2)

path, ok = files["file2.golden"]
require.True(t, ok)
require.Equal(t, path, "testdata/file2.golden")
require.Equal(t, "testdata/file1.golden", files["file1.golden"])
require.Equal(t, "testdata/file2.golden", files["file2.golden"])
}

func TestShouldGetAllFilesInsideTestdata(t *testing.T) {
Expand All @@ -46,17 +63,10 @@ func TestShouldGetAllFilesInsideTestdata(t *testing.T) {

files, err := Find(globs)
require.NoError(t, err)
require.Equal(t, 3, len(files))

path, ok := files["file1.golden"]
require.True(t, ok)
require.Equal(t, path, "testdata/file1.golden")

path, ok = files["file2.golden"]
require.True(t, ok)
require.Equal(t, path, "testdata/file2.golden")
require.Len(t, files, 4)

path, ok = files["file3.gold"]
require.True(t, ok)
require.Equal(t, path, "testdata/file3.gold")
require.Equal(t, "testdata/file1.golden", files["file1.golden"])
require.Equal(t, "testdata/file2.golden", files["file2.golden"])
require.Equal(t, "testdata/file3.gold", files["file3.gold"])
require.Equal(t, "testdata/sub/file5.golden", files["file5.golden"])
}
Empty file.
4 changes: 2 additions & 2 deletions internal/pipe/archive/archive.go
Expand Up @@ -13,7 +13,7 @@ import (

"github.com/apex/log"
"github.com/campoy/unique"
"github.com/mattn/go-zglob"
"github.com/goreleaser/fileglob"

"github.com/goreleaser/goreleaser/internal/artifact"
"github.com/goreleaser/goreleaser/internal/ids"
Expand Down Expand Up @@ -240,7 +240,7 @@ func findFiles(template *tmpl.Template, archive config.Archive) (result []string
if err != nil {
return result, fmt.Errorf("failed to apply template %s: %w", glob, err)
}
files, err := zglob.Glob(replaced)
files, err := fileglob.Glob(replaced)
if err != nil {
return result, fmt.Errorf("globbing failed for pattern %s: %w", glob, err)
}
Expand Down
4 changes: 1 addition & 3 deletions internal/pipe/archive/archive_test.go
Expand Up @@ -157,8 +157,6 @@ func TestRunPipe(t *testing.T) {
t,
[]string{
fmt.Sprintf("README.%s.md", os),
"foo/bar",
"foo/bar/foobar",
"foo/bar/foobar/blah.txt",
"bin/mybin",
},
Expand Down Expand Up @@ -426,7 +424,7 @@ func TestRunPipeInvalidGlob(t *testing.T) {
"ID": "default",
},
})
require.EqualError(t, Pipe{}.Run(ctx), `failed to find files to archive: globbing failed for pattern [x-]: file does not exist`)
require.EqualError(t, Pipe{}.Run(ctx), `failed to find files to archive: globbing failed for pattern [x-]: compile glob pattern: unexpected end of input`)
}

func TestRunPipeInvalidNameTemplate(t *testing.T) {
Expand Down
4 changes: 1 addition & 3 deletions internal/pipe/release/release_test.go
Expand Up @@ -163,8 +163,6 @@ func TestRunPipeWithIDsThenFilters(t *testing.T) {
require.True(t, client.UploadedFile)
require.Contains(t, client.UploadedFileNames, "bin.deb")
require.Contains(t, client.UploadedFileNames, "bin.tar.gz")
require.Contains(t, client.UploadedFileNames, "release1.golden")
require.Contains(t, client.UploadedFileNames, "release2.golden")
require.Contains(t, client.UploadedFileNames, "f1")
require.NotContains(t, client.UploadedFileNames, "filtered.deb")
require.NotContains(t, client.UploadedFileNames, "filtered.tar.gz")
Expand Down Expand Up @@ -255,7 +253,7 @@ func TestRunPipeExtraFileNotFound(t *testing.T) {
var ctx = context.New(config)
ctx.Git = context.GitInfo{CurrentTag: "v1.0.0"}
client := &DummyClient{}
require.EqualError(t, doPublish(ctx, client), "globbing failed for pattern ./nope: file does not exist")
require.EqualError(t, doPublish(ctx, client), "globbing failed for pattern ./nope: matching \"nope\": file does not exist")
require.True(t, client.CreatedRelease)
require.False(t, client.UploadedFile)
}
Expand Down

1 comment on commit 4a6693f

@vercel
Copy link

@vercel vercel bot commented on 4a6693f Nov 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.