diff --git a/go.mod b/go.mod index 879186e..9c80911 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/andreaskoch/go-fswatch v1.0.0 github.com/containerd/containerd v1.3.3 // indirect github.com/docker/distribution v2.7.1+incompatible // indirect - github.com/docker/docker v0.0.0-20200229013735-71373c6105e3 + github.com/docker/docker v0.0.0-20200229013735-71373c6105e3 github.com/docker/go-connections v0.4.0 // indirect github.com/emirpasic/gods v1.12.0 // indirect github.com/go-ini/ini v1.41.0 @@ -21,6 +21,7 @@ require ( github.com/jtolds/gls v4.2.1+incompatible // indirect github.com/mgutz/str v1.2.0 // indirect github.com/mitchellh/go-homedir v1.1.0 // indirect + github.com/monochromegane/go-gitignore v0.0.0-20160105113617-38717d0a108c github.com/morikuni/aec v1.0.0 // indirect github.com/opencontainers/go-digest v1.0.0-rc1 // indirect github.com/opencontainers/image-spec v1.0.1 // indirect @@ -51,4 +52,5 @@ require ( ) replace github.com/docker/docker => github.com/docker/docker v0.0.0-20200229013735-71373c6105e3 + replace golang.org/x/sys => golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a diff --git a/go.sum b/go.sum index a550733..36165e8 100644 --- a/go.sum +++ b/go.sum @@ -101,6 +101,8 @@ github.com/mitchellh/go-homedir v1.0.0 h1:vKb8ShqSby24Yrqr/yDYkuFz8d0WUjys40rvnG github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= +github.com/monochromegane/go-gitignore v0.0.0-20160105113617-38717d0a108c h1:RRUev95N3Gq4Aog4avFzXJA2V8fgXmND+cvcH7KLMyk= +github.com/monochromegane/go-gitignore v0.0.0-20160105113617-38717d0a108c/go.mod h1:Pm3mSP3c5uWn86xMLZ5Sa7JB9GsEZySvHYXCTK4E9q4= github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A= github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc= github.com/opencontainers/go-digest v0.0.0-20180430190053-c9281466c8b2/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s= diff --git a/pkg/container/docker_run.go b/pkg/container/docker_run.go index 9ba67b2..f3eb09e 100644 --- a/pkg/container/docker_run.go +++ b/pkg/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 {