remove .gitignore before docker cp (#288)

* Test setup before I try to understand how things work

* Remove .gitignore before we run docker cp
This commit is contained in:
Jeremy Lempereur 2020-06-23 20:57:24 +02:00 committed by GitHub
parent d4e41a90a2
commit 7cc668707b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 1 deletions

View file

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

View file

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

14
pkg/runner/testdata/issue-228/main.yaml vendored Normal file
View file

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