Skip to content

Commit

Permalink
fix: ignore .gitignore when copying actions into container
Browse files Browse the repository at this point in the history
Removing the .gitignore file can lead to race conditions when multiple
jobs run in parallel. Ignoring the file during tar archive creation does
not create this side effect.

Co-authored-by: Markus Wolf <markus.wolf@new-work.se>
  • Loading branch information
ZauberNerd and KnisterPeter committed Sep 20, 2021
1 parent 919a16d commit dad7e92
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 20 deletions.
5 changes: 5 additions & 0 deletions pkg/container/docker_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,11 @@ func (cr *containerReference) copyDir(dstPath string, srcPath string, useGitIgno
return err
}

if !useGitIgnore && fi.Name() == ".gitignore" {
log.Debugf("Ignoring .gitignore file %s", file)
return nil
}

sansPrefix := strings.TrimPrefix(file, srcPrefix)
split := strings.Split(sansPrefix, string(filepath.Separator))
if ignorer != nil && ignorer.Match(split, fi.IsDir()) {
Expand Down
20 changes: 0 additions & 20 deletions pkg/runner/step_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,9 +474,6 @@ func (sc *StepContext) runAction(actionDir string, actionPath string, localActio
if step.Type() != model.StepTypeUsesActionRemote {
return nil
}
if err := removeGitIgnore(actionDir); err != nil {
return err
}

var containerActionDirCopy string
containerActionDirCopy = strings.TrimSuffix(containerActionDir, actionPath)
Expand Down Expand Up @@ -710,20 +707,3 @@ func newRemoteAction(action string) *remoteAction {
URL: "github.com",
}
}

// https://github.com/nektos/act/issues/228#issuecomment-629709055
// files in .gitignore are not copied in a Docker container
// this causes issues with actions that ignore other important resources
// such as `node_modules` for example
func removeGitIgnore(directory string) error {
gitIgnorePath := path.Join(directory, ".gitignore")
if _, err := os.Stat(gitIgnorePath); err == nil {
// .gitignore exists
log.Debugf("Removing %s before docker cp", gitIgnorePath)
err := os.Remove(gitIgnorePath)
if err != nil {
return err
}
}
return nil
}

0 comments on commit dad7e92

Please sign in to comment.