1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-26 04:22:05 +02:00
goreleaser/internal/extrafiles/extra_files.go
Carlos Alexandro Becker 4a6693fb72
feat: replace zglob with fileglob (#1889)
* 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>
2020-11-10 11:20:55 -03:00

39 lines
920 B
Go

package extrafiles
import (
"fmt"
"os"
"path/filepath"
"github.com/apex/log"
"github.com/goreleaser/fileglob"
"github.com/goreleaser/goreleaser/pkg/config"
)
// Find resolves extra files globs et al into a map of names/paths or an error.
func Find(files []config.ExtraFile) (map[string]string, error) {
var result = map[string]string{}
for _, extra := range files {
if extra.Glob == "" {
continue
}
files, err := fileglob.Glob(extra.Glob)
if err != nil {
return result, fmt.Errorf("globbing failed for pattern %s: %w", extra.Glob, err)
}
for _, file := range files {
info, err := os.Stat(file)
if err == nil && info.IsDir() {
log.Debugf("ignoring directory %s", file)
continue
}
var name = filepath.Base(file)
if old, ok := result[name]; ok {
log.Warnf("overriding %s with %s for name %s", old, file, name)
}
result[name] = file
}
}
return result, nil
}