fix: copy whole action dir to container (#774)

fixes https://github.com/nektos/act/issues/754
this will prevent actions from failing that use resources outside
of the action directory
This commit is contained in:
Ryan 2021-08-11 05:21:52 +00:00 committed by GitHub
parent bea32d5651
commit de44a505da
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -467,24 +467,30 @@ func (sc *StepContext) runAction(actionDir string, actionPath string, localActio
sc.Env = mergeMaps(sc.Env, action.Runs.Env) sc.Env = mergeMaps(sc.Env, action.Runs.Env)
log.Debugf("type=%v actionDir=%s actionPath=%s Workdir=%s ActionCacheDir=%s actionName=%s containerActionDir=%s", step.Type(), actionDir, actionPath, rc.Config.Workdir, rc.ActionCacheDir(), actionName, containerActionDir) log.Debugf("type=%v actionDir=%s actionPath=%s workdir=%s actionCacheDir=%s actionName=%s containerActionDir=%s", step.Type(), actionDir, actionPath, rc.Config.Workdir, rc.ActionCacheDir(), actionName, containerActionDir)
maybeCopyToActionDir := func() error { maybeCopyToActionDir := func() error {
sc.Env["GITHUB_ACTION_PATH"] = containerActionDir sc.Env["GITHUB_ACTION_PATH"] = containerActionDir
if step.Type() != model.StepTypeUsesActionRemote { if step.Type() != model.StepTypeUsesActionRemote {
return nil return nil
} }
err := removeGitIgnore(actionDir) if err := removeGitIgnore(actionDir); err != nil {
if err != nil {
return err return err
} }
return rc.JobContainer.CopyDir(containerActionDir+"/", actionLocation+"/", rc.Config.UseGitIgnore)(ctx)
var containerActionDirCopy string
containerActionDirCopy = strings.TrimSuffix(containerActionDir, actionPath)
log.Debug(containerActionDirCopy)
if !strings.HasSuffix(containerActionDirCopy, `/`) {
containerActionDirCopy += `/`
}
return rc.JobContainer.CopyDir(containerActionDirCopy, actionDir+"/", rc.Config.UseGitIgnore)(ctx)
} }
switch action.Runs.Using { switch action.Runs.Using {
case model.ActionRunsUsingNode12: case model.ActionRunsUsingNode12:
err := maybeCopyToActionDir() if err := maybeCopyToActionDir(); err != nil {
if err != nil {
return err return err
} }
containerArgs := []string{"node", path.Join(containerActionDir, action.Runs.Main)} containerArgs := []string{"node", path.Join(containerActionDir, action.Runs.Main)}