Add variadic version of hashFiles (#411)
This commit is contained in:
parent
d6b2e9df78
commit
d5b2d60c35
@ -236,11 +236,15 @@ func vmFromJSON(vm *otto.Otto) {
|
|||||||
|
|
||||||
func (rc *RunContext) vmHashFiles() func(*otto.Otto) {
|
func (rc *RunContext) vmHashFiles() func(*otto.Otto) {
|
||||||
return func(vm *otto.Otto) {
|
return func(vm *otto.Otto) {
|
||||||
_ = vm.Set("hashFiles", func(path string) string {
|
_ = vm.Set("hashFiles", func(paths ...string) string {
|
||||||
files, _, err := glob.Glob([]string{filepath.Join(rc.Config.Workdir, path)})
|
files := []*glob.FileAsset{}
|
||||||
if err != nil {
|
for i := range paths {
|
||||||
logrus.Errorf("Unable to glob.Glob: %v", err)
|
newFiles, _, err := glob.Glob([]string{filepath.Join(rc.Config.Workdir, paths[i])})
|
||||||
return ""
|
if err != nil {
|
||||||
|
logrus.Errorf("Unable to glob.Glob: %v", err)
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
files = append(files, newFiles...)
|
||||||
}
|
}
|
||||||
hasher := sha256.New()
|
hasher := sha256.New()
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
|
@ -83,6 +83,7 @@ func TestEvaluate(t *testing.T) {
|
|||||||
{"(fromJSON('{\"foo\":\"bar\"}')).foo", "bar", ""},
|
{"(fromJSON('{\"foo\":\"bar\"}')).foo", "bar", ""},
|
||||||
{"(fromJson('{\"foo\":\"bar\"}')).foo", "bar", ""},
|
{"(fromJson('{\"foo\":\"bar\"}')).foo", "bar", ""},
|
||||||
{"hashFiles('**/non-extant-files')", "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", ""},
|
{"hashFiles('**/non-extant-files')", "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", ""},
|
||||||
|
{"hashFiles('**/non-extant-files', '**/more-non-extant-files')", "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", ""},
|
||||||
{"success()", "true", ""},
|
{"success()", "true", ""},
|
||||||
{"failure()", "false", ""},
|
{"failure()", "false", ""},
|
||||||
{"always()", "true", ""},
|
{"always()", "true", ""},
|
||||||
|
Loading…
Reference in New Issue
Block a user