When running on Windows the correct path separator must be used (#386)

* 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
This commit is contained in:
Taliesin Sisson 2020-10-09 06:30:50 +01:00 committed by GitHub
parent 569ebaccae
commit 014d71af43
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 17 deletions

View file

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

View file

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

View file

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