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 <[email protected]>
  • Loading branch information
ZauberNerd and KnisterPeter committed May 26, 2021
1 parent b84f5b8 commit e36e094
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 21 deletions.
5 changes: 5 additions & 0 deletions pkg/container/docker_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,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
21 changes: 0 additions & 21 deletions pkg/runner/step_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,10 +428,6 @@ func (sc *StepContext) runAction(actionDir string, actionPath string) common.Exe
return nil
}
}
err := removeGitIgnore(actionDir)
if err != nil {
return err
}
return rc.JobContainer.CopyDir(containerActionDir+"/", actionLocation+"/", rc.Config.UseGitIgnore)(ctx)
}

Expand Down Expand Up @@ -644,20 +640,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 e36e094

Please sign in to comment.