From 7cc668707b9c586a45f717301902224bca6d2a12 Mon Sep 17 00:00:00 2001 From: Jeremy Lempereur Date: Tue, 23 Jun 2020 20:57:24 +0200 Subject: [PATCH] remove .gitignore before docker cp (#288) * Test setup before I try to understand how things work * Remove .gitignore before we run docker cp --- pkg/runner/runner_test.go | 1 + pkg/runner/step_context.go | 24 +++++++++++++++++++++++- pkg/runner/testdata/issue-228/main.yaml | 14 ++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 pkg/runner/testdata/issue-228/main.yaml diff --git a/pkg/runner/runner_test.go b/pkg/runner/runner_test.go index 94ea327..14a576b 100644 --- a/pkg/runner/runner_test.go +++ b/pkg/runner/runner_test.go @@ -53,6 +53,7 @@ func TestRunEvent(t *testing.T) { {"matrix", "push", ""}, {"commands", "push", ""}, {"workdir", "push", ""}, + {"issue-228", "push", ""}, // TODO [igni]: Remove this once everything passes } log.SetLevel(log.DebugLevel) diff --git a/pkg/runner/step_context.go b/pkg/runner/step_context.go index 1ec5fb0..66291b7 100644 --- a/pkg/runner/step_context.go +++ b/pkg/runner/step_context.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "os" + "path" "path/filepath" "regexp" "runtime" @@ -266,7 +267,11 @@ func (sc *StepContext) runAction(actionDir string, actionPath string) common.Exe switch action.Runs.Using { case model.ActionRunsUsingNode12: if step.Type() == model.StepTypeUsesActionRemote { - err := rc.JobContainer.CopyDir(containerActionDir+string(filepath.Separator), actionDir)(ctx) + err := removeGitIgnore(actionDir) + if err != nil { + return err + } + err = rc.JobContainer.CopyDir(containerActionDir+string(filepath.Separator), actionDir)(ctx) if err != nil { return err } @@ -351,3 +356,20 @@ func newRemoteAction(action string) *remoteAction { } return ra } + +// 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 +} diff --git a/pkg/runner/testdata/issue-228/main.yaml b/pkg/runner/testdata/issue-228/main.yaml new file mode 100644 index 0000000..e0a0dfb --- /dev/null +++ b/pkg/runner/testdata/issue-228/main.yaml @@ -0,0 +1,14 @@ +name: issue-228 + +on: + - push + +jobs: + kind: + runs-on: ubuntu-latest + steps: + - run: apt-get update -y && apt-get install git -y # setup git credentials will fail otherwise + - name: Setup git credentials + uses: fusion-engineering/setup-git-credentials@v2 + with: + credentials: https://test@github.com/