From eb2774275fa3ccb6748cd43f91ace3846106245f Mon Sep 17 00:00:00 2001 From: hackercat Date: Sat, 13 Mar 2021 01:23:03 +0100 Subject: [PATCH] Fix tests on Windows (#562) * fix: replace `\` with `/` in git ref to fix `git_test.go` on windows Paths on Windows use backslash (`\`) as directory separator and this breaks `TestGitFindRef()`. Replacing `\` with `/` in git ref fixes that issue. * fix: replace `gopkg.in/godo.v2/glob` with std library `path/filepath` `github.com/go-godo/godo` lib has been last updated in 2016 and it also depends on another outdated lib `github.com/MichaelTJones/walk` with last update in 2016. This also fixes `permission_denied` errors on Windows (and perhaps Linux in some specific cases). I'm not aware of any performance improvement or drawback because of that change. --- pkg/common/git.go | 3 ++- pkg/runner/expression.go | 7 +++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pkg/common/git.go b/pkg/common/git.go index 982eec4..d25b8bd 100644 --- a/pkg/common/git.go +++ b/pkg/common/git.go @@ -98,7 +98,8 @@ func findGitPrettyRef(head, root, sub string) (string, error) { } var pointsTo = strings.TrimSpace(string(bts)) if head == pointsTo { - name = strings.TrimPrefix(strings.Replace(path, root, "", 1), "/") + // On Windows paths are separated with backslash character so they should be replaced to provide proper git refs format + name = strings.TrimPrefix(strings.ReplaceAll(strings.Replace(path, root, "", 1), `\`, `/`), "/") log.Debugf("HEAD matches %s", name) } return nil diff --git a/pkg/runner/expression.go b/pkg/runner/expression.go index e9dc56b..505ae16 100644 --- a/pkg/runner/expression.go +++ b/pkg/runner/expression.go @@ -13,7 +13,6 @@ import ( "github.com/robertkrimen/otto" log "github.com/sirupsen/logrus" - "gopkg.in/godo.v2/glob" ) var expressionPattern, operatorPattern *regexp.Regexp @@ -319,9 +318,9 @@ func vmFromJSON(vm *otto.Otto) { func (rc *RunContext) vmHashFiles() func(*otto.Otto) { return func(vm *otto.Otto) { _ = vm.Set("hashFiles", func(paths ...string) string { - var files []*glob.FileAsset + var files []string for i := range paths { - newFiles, _, err := glob.Glob([]string{filepath.Join(rc.Config.Workdir, paths[i])}) + newFiles, err := filepath.Glob(filepath.Join(rc.Config.Workdir, paths[i])) if err != nil { log.Errorf("Unable to glob.Glob: %v", err) return "" @@ -330,7 +329,7 @@ func (rc *RunContext) vmHashFiles() func(*otto.Otto) { } hasher := sha256.New() for _, file := range files { - f, err := os.Open(file.Path) + f, err := os.Open(file) if err != nil { log.Errorf("Unable to os.Open: %v", err) }