From 020d6a60832a324e46b72be92ac5754537e57a17 Mon Sep 17 00:00:00 2001 From: Josh Soref Date: Mon, 3 May 2021 17:57:46 -0400 Subject: [PATCH] Composite action (#608) * Refactor maybeCopyToActionDir * Use maybeCopyToActionDir for model.ActionRunsUsingComposite --- pkg/runner/runner_test.go | 3 +-- pkg/runner/step_context.go | 27 ++++++++++++++++++--------- 2 files changed, 19 insertions(+), 11 deletions(-) mode change 100755 => 100644 pkg/runner/runner_test.go diff --git a/pkg/runner/runner_test.go b/pkg/runner/runner_test.go old mode 100755 new mode 100644 index 30fcf3e..541831f --- a/pkg/runner/runner_test.go +++ b/pkg/runner/runner_test.go @@ -96,13 +96,12 @@ func TestRunEvent(t *testing.T) { {"testdata", "workdir", "push", "", platforms, ""}, {"testdata", "defaults-run", "push", "", platforms, ""}, {"testdata", "uses-composite", "push", "", platforms, ""}, - {"testdata", "issue-597", "push", "", platforms, ""}, + {"testdata", "issue-597", "push", "", platforms, ""}, // {"testdata", "powershell", "push", "", platforms, ""}, // Powershell is not available on default act test runner (yet) but preserving here for posterity // {"testdata", "issue-228", "push", "", platforms, ""}, // TODO [igni]: Remove this once everything passes // single test for different architecture: linux/arm64 {"testdata", "basic", "push", "", platforms, "linux/arm64"}, - } log.SetLevel(log.DebugLevel) diff --git a/pkg/runner/step_context.go b/pkg/runner/step_context.go index 0ce3e82..05ba402 100755 --- a/pkg/runner/step_context.go +++ b/pkg/runner/step_context.go @@ -408,17 +408,22 @@ func (sc *StepContext) runAction(actionDir string, actionPath string) common.Exe 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 { + if step.Type() != model.StepTypeUsesActionRemote { + return nil + } + err := removeGitIgnore(actionDir) + if err != nil { + return err + } + return rc.JobContainer.CopyDir(containerActionDir+"/", actionDir, rc.Config.UseGitIgnore)(ctx) + } + switch action.Runs.Using { case model.ActionRunsUsingNode12: - if step.Type() == model.StepTypeUsesActionRemote { - err := removeGitIgnore(actionDir) - if err != nil { - return err - } - err = rc.JobContainer.CopyDir(containerActionDir+"/", actionDir, rc.Config.UseGitIgnore)(ctx) - if err != nil { - return err - } + err := maybeCopyToActionDir() + if err != nil { + return err } containerArgs := []string{"node", path.Join(containerActionDir, actionName, actionPath, action.Runs.Main)} log.Debugf("executing remote job container: %s", containerArgs) @@ -488,6 +493,10 @@ func (sc *StepContext) runAction(actionDir string, actionPath string) common.Exe stepContainer.Remove().IfBool(!rc.Config.ReuseContainers), )(ctx) case model.ActionRunsUsingComposite: + err := maybeCopyToActionDir() + if err != nil { + return err + } for outputName, output := range action.Outputs { re := regexp.MustCompile(`\${{ steps\.([a-zA-Z_][a-zA-Z0-9_-]+)\.outputs\.([a-zA-Z_][a-zA-Z0-9_-]+) }}`) matches := re.FindStringSubmatch(output.Value)