Skip to content

Commit 8314095

Browse files
feat: cmd support for windows (#1941)
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent 6468dd7 commit 8314095

File tree

5 files changed

+22
-3
lines changed

5 files changed

+22
-3
lines changed

pkg/container/host_environment.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,12 @@ func (e *HostEnvironment) exec(ctx context.Context, command []string, cmdline st
353353
}
354354

355355
func (e *HostEnvironment) Exec(command []string /*cmdline string, */, env map[string]string, user, workdir string) common.Executor {
356+
return e.ExecWithCmdLine(command, "", env, user, workdir)
357+
}
358+
359+
func (e *HostEnvironment) ExecWithCmdLine(command []string, cmdline string, env map[string]string, user, workdir string) common.Executor {
356360
return func(ctx context.Context) error {
357-
if err := e.exec(ctx, command, "" /*cmdline*/, env, user, workdir); err != nil {
361+
if err := e.exec(ctx, command, cmdline, env, user, workdir); err != nil {
358362
select {
359363
case <-ctx.Done():
360364
return fmt.Errorf("this step has been cancelled: %w", err)

pkg/model/workflow.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ func (s *Step) ShellCommand() string {
568568
case "sh":
569569
shellCommand = "sh -e {0}"
570570
case "cmd":
571-
shellCommand = "%ComSpec% /D /E:ON /V:OFF /S /C \"CALL \"{0}\"\""
571+
shellCommand = "cmd /D /E:ON /V:OFF /S /C \"CALL \"{0}\"\""
572572
case "powershell":
573573
shellCommand = "powershell -command . '{0}'"
574574
default:

pkg/runner/runner_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,7 @@ func TestRunEventHostEnvironment(t *testing.T) {
390390
tables = append(tables, []TestJobFileInfo{
391391
{workdir, "windows-prepend-path", "push", "", platforms, secrets},
392392
{workdir, "windows-add-env", "push", "", platforms, secrets},
393+
{workdir, "windows-shell-cmd", "push", "", platforms, secrets},
393394
}...)
394395
} else {
395396
platforms := map[string]string{

pkg/runner/step_run.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ type stepRun struct {
1818
Step *model.Step
1919
RunContext *RunContext
2020
cmd []string
21+
cmdline string
2122
env map[string]string
2223
WorkingDirectory string
2324
}
@@ -34,6 +35,9 @@ func (sr *stepRun) main() common.Executor {
3435
sr.setupShellCommandExecutor(),
3536
func(ctx context.Context) error {
3637
sr.getRunContext().ApplyExtraPath(ctx, &sr.env)
38+
if he, ok := sr.getRunContext().JobContainer.(*container.HostEnvironment); ok && he != nil {
39+
return he.ExecWithCmdLine(sr.cmd, sr.cmdline, sr.env, "", sr.WorkingDirectory)(ctx)
40+
}
3741
return sr.getRunContext().JobContainer.Exec(sr.cmd, sr.env, "", sr.WorkingDirectory)(ctx)
3842
},
3943
))
@@ -135,7 +139,8 @@ func (sr *stepRun) setupShellCommand(ctx context.Context) (name, script string,
135139

136140
rc := sr.getRunContext()
137141
scriptPath := fmt.Sprintf("%s/%s", rc.JobContainer.GetActPath(), name)
138-
sr.cmd, err = shellquote.Split(strings.Replace(scCmd, `{0}`, scriptPath, 1))
142+
sr.cmdline = strings.Replace(scCmd, `{0}`, scriptPath, 1)
143+
sr.cmd, err = shellquote.Split(sr.cmdline)
139144

140145
return name, script, err
141146
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
on:
2+
push:
3+
jobs:
4+
test:
5+
runs-on: windows-latest
6+
steps:
7+
- run: |
8+
echo Hi
9+
shell: cmd

0 commit comments

Comments
 (0)