Skip to content

Commit

Permalink
When running on Windows the correct path separator must be used (#386)
Browse files Browse the repository at this point in the history
* When running on Windows the correct path separator must be used. filePath.join is OS aware, so when we want to use forward slash use path.join instead.

on windows docker cp should end with \. when copying a directory
when running npm modules we should pass in path with all forward slashes

This fixes #331

* When calculating relative folders on Windows for destination path on Linux, we need to change \ for /

* Reduce complexity by extracting methods

* V1 does not point to a file that does not exist

* Looks like something else is the cause of this test breaking. Last successful build is #371, builds after that are failing
  • Loading branch information
taliesins authored Oct 9, 2020
1 parent 569ebac commit 014d71a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 17 deletions.
2 changes: 1 addition & 1 deletion pkg/runner/run_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion pkg/runner/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
48 changes: 33 additions & 15 deletions pkg/runner/step_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand All @@ -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:
Expand Down

0 comments on commit 014d71a

Please sign in to comment.