feat: cmd support for windows (#1941)
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
parent
6468dd7fc8
commit
83140951bf
5 changed files with 22 additions and 3 deletions
|
@ -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 {
|
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 {
|
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 {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return fmt.Errorf("this step has been cancelled: %w", err)
|
return fmt.Errorf("this step has been cancelled: %w", err)
|
||||||
|
|
|
@ -568,7 +568,7 @@ func (s *Step) ShellCommand() string {
|
||||||
case "sh":
|
case "sh":
|
||||||
shellCommand = "sh -e {0}"
|
shellCommand = "sh -e {0}"
|
||||||
case "cmd":
|
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":
|
case "powershell":
|
||||||
shellCommand = "powershell -command . '{0}'"
|
shellCommand = "powershell -command . '{0}'"
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -390,6 +390,7 @@ func TestRunEventHostEnvironment(t *testing.T) {
|
||||||
tables = append(tables, []TestJobFileInfo{
|
tables = append(tables, []TestJobFileInfo{
|
||||||
{workdir, "windows-prepend-path", "push", "", platforms, secrets},
|
{workdir, "windows-prepend-path", "push", "", platforms, secrets},
|
||||||
{workdir, "windows-add-env", "push", "", platforms, secrets},
|
{workdir, "windows-add-env", "push", "", platforms, secrets},
|
||||||
|
{workdir, "windows-shell-cmd", "push", "", platforms, secrets},
|
||||||
}...)
|
}...)
|
||||||
} else {
|
} else {
|
||||||
platforms := map[string]string{
|
platforms := map[string]string{
|
||||||
|
|
|
@ -18,6 +18,7 @@ type stepRun struct {
|
||||||
Step *model.Step
|
Step *model.Step
|
||||||
RunContext *RunContext
|
RunContext *RunContext
|
||||||
cmd []string
|
cmd []string
|
||||||
|
cmdline string
|
||||||
env map[string]string
|
env map[string]string
|
||||||
WorkingDirectory string
|
WorkingDirectory string
|
||||||
}
|
}
|
||||||
|
@ -34,6 +35,9 @@ func (sr *stepRun) main() common.Executor {
|
||||||
sr.setupShellCommandExecutor(),
|
sr.setupShellCommandExecutor(),
|
||||||
func(ctx context.Context) error {
|
func(ctx context.Context) error {
|
||||||
sr.getRunContext().ApplyExtraPath(ctx, &sr.env)
|
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)
|
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()
|
rc := sr.getRunContext()
|
||||||
scriptPath := fmt.Sprintf("%s/%s", rc.JobContainer.GetActPath(), name)
|
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
|
return name, script, err
|
||||||
}
|
}
|
||||||
|
|
9
pkg/runner/testdata/windows-shell-cmd/push.yml
vendored
Normal file
9
pkg/runner/testdata/windows-shell-cmd/push.yml
vendored
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
runs-on: windows-latest
|
||||||
|
steps:
|
||||||
|
- run: |
|
||||||
|
echo Hi
|
||||||
|
shell: cmd
|
Loading…
Reference in a new issue