-
Notifications
You must be signed in to change notification settings - Fork 28
/
artifacts.go
48 lines (40 loc) · 882 Bytes
/
artifacts.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"os"
"path/filepath"
"github.com/bitrise-io/go-utils/log"
"github.com/ryanuber/go-glob"
)
type filePatterns struct {
include []string
exclude []string
}
func findArtifacts(searchDir string, patterns filePatterns) ([]string, error) {
var artifacts []string
return artifacts, filepath.Walk(searchDir, func(path string, info os.FileInfo, err error) error {
if err != nil {
log.Warnf("failed to walk path: %s", err)
return err
}
if info.IsDir() {
return nil
}
includeMatch := false
for _, includePattern := range patterns.include {
if glob.Glob(includePattern, path) {
includeMatch = true
break
}
}
if !includeMatch {
return nil
}
for _, excludePattern := range patterns.exclude {
if glob.Glob(excludePattern, path) {
return nil
}
}
artifacts = append(artifacts, path)
return nil
})
}