diff --git a/pkg/container/host_environment.go b/pkg/container/host_environment.go index 04ff12d..91dae4c 100644 --- a/pkg/container/host_environment.go +++ b/pkg/container/host_environment.go @@ -353,8 +353,12 @@ func (e *HostEnvironment) exec(ctx context.Context, command []string, cmdline st } func (e *HostEnvironment) Exec(command []string /*cmdline string, */, env map[string]string, user, workdir string) common.Executor { + return e.ExecWithCmdLine(command, "", env, user, workdir) +} + +func (e *HostEnvironment) ExecWithCmdLine(command []string, cmdline string, env map[string]string, user, workdir string) common.Executor { return func(ctx context.Context) error { - if err := e.exec(ctx, command, "" /*cmdline*/, env, user, workdir); err != nil { + if err := e.exec(ctx, command, cmdline, env, user, workdir); err != nil { select { case <-ctx.Done(): return fmt.Errorf("this step has been cancelled: %w", err) diff --git a/pkg/model/workflow.go b/pkg/model/workflow.go index 4fd9be9..1573c76 100644 --- a/pkg/model/workflow.go +++ b/pkg/model/workflow.go @@ -568,7 +568,7 @@ func (s *Step) ShellCommand() string { case "sh": shellCommand = "sh -e {0}" case "cmd": - shellCommand = "%ComSpec% /D /E:ON /V:OFF /S /C \"CALL \"{0}\"\"" + shellCommand = "cmd /D /E:ON /V:OFF /S /C \"CALL \"{0}\"\"" case "powershell": shellCommand = "powershell -command . '{0}'" default: diff --git a/pkg/runner/runner_test.go b/pkg/runner/runner_test.go index 5b8257c..4034e96 100644 --- a/pkg/runner/runner_test.go +++ b/pkg/runner/runner_test.go @@ -390,6 +390,7 @@ func TestRunEventHostEnvironment(t *testing.T) { tables = append(tables, []TestJobFileInfo{ {workdir, "windows-prepend-path", "push", "", platforms, secrets}, {workdir, "windows-add-env", "push", "", platforms, secrets}, + {workdir, "windows-shell-cmd", "push", "", platforms, secrets}, }...) } else { platforms := map[string]string{ diff --git a/pkg/runner/step_run.go b/pkg/runner/step_run.go index 53de414..054ed70 100644 --- a/pkg/runner/step_run.go +++ b/pkg/runner/step_run.go @@ -18,6 +18,7 @@ type stepRun struct { Step *model.Step RunContext *RunContext cmd []string + cmdline string env map[string]string WorkingDirectory string } @@ -34,6 +35,9 @@ func (sr *stepRun) main() common.Executor { sr.setupShellCommandExecutor(), func(ctx context.Context) error { sr.getRunContext().ApplyExtraPath(ctx, &sr.env) + if he, ok := sr.getRunContext().JobContainer.(*container.HostEnvironment); ok && he != nil { + return he.ExecWithCmdLine(sr.cmd, sr.cmdline, sr.env, "", sr.WorkingDirectory)(ctx) + } return sr.getRunContext().JobContainer.Exec(sr.cmd, sr.env, "", sr.WorkingDirectory)(ctx) }, )) @@ -135,7 +139,8 @@ func (sr *stepRun) setupShellCommand(ctx context.Context) (name, script string, rc := sr.getRunContext() scriptPath := fmt.Sprintf("%s/%s", rc.JobContainer.GetActPath(), name) - sr.cmd, err = shellquote.Split(strings.Replace(scCmd, `{0}`, scriptPath, 1)) + sr.cmdline = strings.Replace(scCmd, `{0}`, scriptPath, 1) + sr.cmd, err = shellquote.Split(sr.cmdline) return name, script, err } diff --git a/pkg/runner/testdata/windows-shell-cmd/push.yml b/pkg/runner/testdata/windows-shell-cmd/push.yml new file mode 100644 index 0000000..ea672a3 --- /dev/null +++ b/pkg/runner/testdata/windows-shell-cmd/push.yml @@ -0,0 +1,9 @@ +on: + push: +jobs: + test: + runs-on: windows-latest + steps: + - run: | + echo Hi + shell: cmd \ No newline at end of file