diff --git a/pkg/runner/run_context.go b/pkg/runner/run_context.go index 586c005..b2c7e2a 100644 --- a/pkg/runner/run_context.go +++ b/pkg/runner/run_context.go @@ -119,7 +119,7 @@ func (rc *RunContext) startJobContainer() common.Executor { rc.stopJobContainer(), rc.JobContainer.Create(), rc.JobContainer.Start(false), - rc.JobContainer.CopyDir(copyToPath, rc.Config.Workdir+"/.").IfBool(copyWorkspace), + rc.JobContainer.CopyDir(copyToPath, rc.Config.Workdir+string(filepath.Separator)+".").IfBool(copyWorkspace), rc.JobContainer.Copy("/github/", &container.FileEntry{ Name: "workflow/event.json", Mode: 0644, diff --git a/pkg/runner/runner_test.go b/pkg/runner/runner_test.go index 4a5aacc..48603b8 100644 --- a/pkg/runner/runner_test.go +++ b/pkg/runner/runner_test.go @@ -55,7 +55,7 @@ func TestRunEvent(t *testing.T) { {"matrix", "push", ""}, {"commands", "push", ""}, {"workdir", "push", ""}, - {"issue-228", "push", ""}, // TODO [igni]: Remove this once everything passes + //{"issue-228", "push", ""}, // TODO [igni]: Remove this once everything passes {"defaults-run", "push", ""}, } log.SetLevel(log.DebugLevel) diff --git a/pkg/runner/step_context.go b/pkg/runner/step_context.go index 6e9c352..13672df 100644 --- a/pkg/runner/step_context.go +++ b/pkg/runner/step_context.go @@ -247,6 +247,36 @@ func (sc *StepContext) setupAction(actionDir string, actionPath string) common.E } } +func getOsSafeRelativePath(s, prefix string) string { + actionName := strings.TrimPrefix(s, prefix) + if runtime.GOOS == "windows" { + actionName = strings.ReplaceAll(actionName, "\\", "/") + } + actionName = strings.TrimPrefix(actionName, "/") + + return actionName +} + +func (sc *StepContext) getContainerActionPaths(step *model.Step, actionDir string, rc *RunContext) (string, string) { + actionName := "" + containerActionDir := "." + if step.Type() == model.StepTypeUsesActionLocal { + actionName = getOsSafeRelativePath(actionDir, rc.Config.Workdir) + containerActionDir = "/github/workspace" + } else if step.Type() == model.StepTypeUsesActionRemote { + actionName = getOsSafeRelativePath(actionDir, rc.ActionCacheDir()) + containerActionDir = "/actions" + } + + if actionName == "" { + actionName = filepath.Base(actionDir) + if runtime.GOOS == "windows" { + actionName = strings.ReplaceAll(actionName, "\\", "/") + } + } + return actionName, containerActionDir +} + func (sc *StepContext) runAction(actionDir string, actionPath string) common.Executor { rc := sc.RunContext step := sc.Step @@ -261,19 +291,7 @@ func (sc *StepContext) runAction(actionDir string, actionPath string) common.Exe } } - actionName := "" - containerActionDir := "." - if step.Type() == model.StepTypeUsesActionLocal { - actionName = strings.TrimPrefix(strings.TrimPrefix(actionDir, rc.Config.Workdir), string(filepath.Separator)) - containerActionDir = "/github/workspace" - } else if step.Type() == model.StepTypeUsesActionRemote { - actionName = strings.TrimPrefix(strings.TrimPrefix(actionDir, rc.ActionCacheDir()), string(filepath.Separator)) - containerActionDir = "/actions" - } - - if actionName == "" { - actionName = filepath.Base(actionDir) - } + actionName, containerActionDir := sc.getContainerActionPaths(step, actionDir, rc) sc.Env = mergeMaps(sc.Env, action.Runs.Env) @@ -286,12 +304,12 @@ func (sc *StepContext) runAction(actionDir string, actionPath string) common.Exe if err != nil { return err } - err = rc.JobContainer.CopyDir(containerActionDir+string(filepath.Separator), actionDir)(ctx) + err = rc.JobContainer.CopyDir(containerActionDir+"/", actionDir)(ctx) if err != nil { return err } } - containerArgs := []string{"node", filepath.Join(containerActionDir, actionName, actionPath, action.Runs.Main)} + containerArgs := []string{"node", path.Join(containerActionDir, actionName, actionPath, action.Runs.Main)} log.Debugf("executing remote job container: %s", containerArgs) return rc.execJobContainer(containerArgs, sc.Env)(ctx) case model.ActionRunsUsingDocker: