From 96f6ad0f432ec4344873474050b382d6d2618339 Mon Sep 17 00:00:00 2001 From: Casey Lee Date: Mon, 9 Mar 2020 18:32:48 -0700 Subject: [PATCH] fix #50 - exclude anything in .gitignore from being copied into the job volume --- act/container/docker_run.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/act/container/docker_run.go b/act/container/docker_run.go index 9ba67b22..f3eb09ed 100644 --- a/act/container/docker_run.go +++ b/act/container/docker_run.go @@ -16,6 +16,7 @@ import ( "github.com/docker/docker/api/types/mount" "github.com/docker/docker/client" "github.com/docker/docker/pkg/stdcopy" + gitignore "github.com/monochromegane/go-gitignore" "github.com/nektos/act/pkg/common" "github.com/pkg/errors" log "github.com/sirupsen/logrus" @@ -305,6 +306,7 @@ func (cr *containerReference) exec(cmd []string, env map[string]string) common.E } } +// nolint: gocyclo func (cr *containerReference) copyDir(dstPath string, srcPath string) common.Executor { return func(ctx context.Context) error { logger := common.Logger(ctx) @@ -323,6 +325,11 @@ func (cr *containerReference) copyDir(dstPath string, srcPath string) common.Exe } log.Debugf("Stripping prefix:%s src:%s", srcPrefix, srcPath) + gitignore, err := gitignore.NewGitIgnore(filepath.Join(srcPath, ".gitignore")) + if err != nil { + log.Debugf("Error loading .gitignore: %v", err) + } + err = filepath.Walk(srcPath, func(file string, fi os.FileInfo, err error) error { if err != nil { return err @@ -333,6 +340,10 @@ func (cr *containerReference) copyDir(dstPath string, srcPath string) common.Exe return nil } + if gitignore != nil && gitignore.Match(file, fi.IsDir()) { + return nil + } + // create a new dir/file header header, err := tar.FileInfoHeader(fi, fi.Name()) if err != nil {