Update Shell Tasks to match ScriptHandlerHelpers (#575)
* Update Shell Tasks to match ScriptHandlerHelpers Code: https://github.com/actions/runner/blob/main/src/Runner.Worker/Handlers/ScriptHandlerHelpers.cs Docs: https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#using-a-specific-shell Fixes #467 * 🩹 Remove old ps1 handler * ♻️ gocritix fix * 🐛 Powershell command must be a single entry to docker API Fixes #467 * Remove Act Temp * Remove additional Act Directories * remove hard-coded workdir Co-authored-by: Casey Lee <cplee@nektos.com>
This commit is contained in:
parent
c27ef0a65c
commit
957b8ad76d
4 changed files with 48 additions and 4 deletions
|
@ -257,11 +257,12 @@ func (s *Step) GetEnv() map[string]string {
|
|||
func (s *Step) ShellCommand() string {
|
||||
shellCommand := ""
|
||||
|
||||
//Reference: https://github.com/actions/runner/blob/8109c962f09d9acc473d92c595ff43afceddb347/src/Runner.Worker/Handlers/ScriptHandlerHelpers.cs#L9-L17
|
||||
switch s.Shell {
|
||||
case "", "bash":
|
||||
shellCommand = "bash --login --norc -e {0}"
|
||||
shellCommand = "bash --login --noprofile --norc -e -o pipefail {0}"
|
||||
case "pwsh":
|
||||
shellCommand = "pwsh -login -command \"& '{0}'\""
|
||||
shellCommand = "pwsh -login -command . '{0}'"
|
||||
case "python":
|
||||
shellCommand = "python {0}"
|
||||
case "sh":
|
||||
|
@ -269,7 +270,7 @@ func (s *Step) ShellCommand() string {
|
|||
case "cmd":
|
||||
shellCommand = "%ComSpec% /D /E:ON /V:OFF /S /C \"CALL \"{0}\"\""
|
||||
case "powershell":
|
||||
shellCommand = "powershell -command \"& '{0}'\""
|
||||
shellCommand = "powershell -command . '{0}'"
|
||||
default:
|
||||
shellCommand = s.Shell
|
||||
}
|
||||
|
|
|
@ -79,6 +79,7 @@ func TestRunEvent(t *testing.T) {
|
|||
"ubuntu-latest": "node:12.20.1-buster-slim",
|
||||
}
|
||||
tables := []TestJobFileInfo{
|
||||
// {"testdata", "powershell", "push", "", platforms}, // Powershell is not available on default act test runner (yet) but preserving here for posterity
|
||||
{"testdata", "basic", "push", "", platforms, "linux/amd64"},
|
||||
{"testdata", "fail", "push", "exit with `FAILURE`: 1", platforms, "linux/amd64"},
|
||||
{"testdata", "runs-on", "push", "", platforms, "linux/amd64"},
|
||||
|
|
|
@ -159,6 +159,29 @@ func (sc *StepContext) setupShellCommand() common.Executor {
|
|||
return err
|
||||
}
|
||||
scriptName := fmt.Sprintf("workflow/%s", step.ID)
|
||||
|
||||
//Reference: https://github.com/actions/runner/blob/8109c962f09d9acc473d92c595ff43afceddb347/src/Runner.Worker/Handlers/ScriptHandlerHelpers.cs#L47-L64
|
||||
//Reference: https://github.com/actions/runner/blob/8109c962f09d9acc473d92c595ff43afceddb347/src/Runner.Worker/Handlers/ScriptHandlerHelpers.cs#L19-L27
|
||||
runPrepend := ""
|
||||
runAppend := ""
|
||||
scriptExt := ""
|
||||
switch step.Shell {
|
||||
case "bash", "sh":
|
||||
scriptExt = ".sh"
|
||||
case "pwsh", "powershell":
|
||||
scriptExt = ".ps1"
|
||||
runPrepend = "$ErrorActionPreference = 'stop'"
|
||||
runAppend = "if ((Test-Path -LiteralPath variable:/LASTEXITCODE)) { exit $LASTEXITCODE }"
|
||||
case "cmd":
|
||||
scriptExt = ".cmd"
|
||||
runPrepend = "@echo off"
|
||||
case "python":
|
||||
scriptExt = ".py"
|
||||
}
|
||||
|
||||
scriptName += scriptExt
|
||||
run = runPrepend + "\n" + run + "\n" + runAppend
|
||||
|
||||
log.Debugf("Wrote command '%s' to '%s'", run, scriptName)
|
||||
containerPath := fmt.Sprintf("%s/%s", filepath.Dir(rc.Config.Workdir), scriptName)
|
||||
|
||||
|
@ -168,7 +191,14 @@ func (sc *StepContext) setupShellCommand() common.Executor {
|
|||
if step.Shell == "" {
|
||||
step.Shell = rc.Run.Workflow.Defaults.Run.Shell
|
||||
}
|
||||
sc.Cmd = strings.Fields(strings.Replace(step.ShellCommand(), "{0}", containerPath, 1))
|
||||
scCmd := step.ShellCommand()
|
||||
scResolvedCmd := strings.Replace(scCmd, "{0}", containerPath, 1)
|
||||
if step.Shell == "pwsh" || step.Shell == "powershell" {
|
||||
sc.Cmd = strings.SplitN(scResolvedCmd, " ", 3)
|
||||
} else {
|
||||
sc.Cmd = strings.Fields(scResolvedCmd)
|
||||
}
|
||||
|
||||
return rc.JobContainer.Copy(fmt.Sprintf("%s/", filepath.Dir(rc.Config.Workdir)), &container.FileEntry{
|
||||
Name: scriptName,
|
||||
Mode: 0755,
|
||||
|
|
12
pkg/runner/testdata/powershell/push.yml
vendored
Normal file
12
pkg/runner/testdata/powershell/push.yml
vendored
Normal file
|
@ -0,0 +1,12 @@
|
|||
name: powershell
|
||||
on: push
|
||||
|
||||
env:
|
||||
TEST: value
|
||||
jobs:
|
||||
check:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- shell: pwsh
|
||||
run: |
|
||||
echo "hello test"
|
Loading…
Reference in a new issue