1
0
Fork 0
mirror of https://code.forgejo.org/forgejo/runner.git synced 2025-09-15 18:57:01 +00:00

fix #50 - exclude anything in .gitignore from being copied into the job volume

This commit is contained in:
Casey Lee 2020-03-09 18:32:48 -07:00
parent 99b5da6086
commit 96f6ad0f43

View file

@ -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 {