* bash without "-o pipefail" option when "bash" is not explicitely defined in the workflow * bonus: fix inverted expected and actual in TestGetGitHubContext assertions
This commit is contained in:
committed by
GitHub
parent
013c0d4e18
commit
2e117a4d2b
@@ -572,6 +572,8 @@ type Step struct {
|
||||
Uses string `yaml:"uses"`
|
||||
Run string `yaml:"run"`
|
||||
WorkingDirectory string `yaml:"working-directory"`
|
||||
// WorkflowShell is the shell really configured in the job, directly at step level or higher in defaults.run.shell
|
||||
WorkflowShell string `yaml:"-"`
|
||||
Shell string `yaml:"shell"`
|
||||
Env yaml.Node `yaml:"env"`
|
||||
With map[string]string `yaml:"with"`
|
||||
@@ -614,8 +616,14 @@ func (s *Step) ShellCommand() string {
|
||||
|
||||
//Reference: https://github.com/actions/runner/blob/8109c962f09d9acc473d92c595ff43afceddb347/src/Runner.Worker/Handlers/ScriptHandlerHelpers.cs#L9-L17
|
||||
switch s.Shell {
|
||||
case "", "bash":
|
||||
shellCommand = "bash --noprofile --norc -e -o pipefail {0}"
|
||||
case "":
|
||||
shellCommand = "bash -e {0}"
|
||||
case "bash":
|
||||
if s.WorkflowShell == "" {
|
||||
shellCommand = "bash -e {0}"
|
||||
} else {
|
||||
shellCommand = "bash --noprofile --norc -e -o pipefail {0}"
|
||||
}
|
||||
case "pwsh":
|
||||
shellCommand = "pwsh -command . '{0}'"
|
||||
case "python":
|
||||
|
||||
@@ -397,15 +397,18 @@ func TestReadWorkflow_Strategy(t *testing.T) {
|
||||
func TestStep_ShellCommand(t *testing.T) {
|
||||
tests := []struct {
|
||||
shell string
|
||||
workflowShell string
|
||||
want string
|
||||
}{
|
||||
{"pwsh -v '. {0}'", "pwsh -v '. {0}'"},
|
||||
{"pwsh", "pwsh -command . '{0}'"},
|
||||
{"powershell", "powershell -command . '{0}'"},
|
||||
{"pwsh -v '. {0}'", "", "pwsh -v '. {0}'"},
|
||||
{"pwsh", "", "pwsh -command . '{0}'"},
|
||||
{"powershell", "", "powershell -command . '{0}'"},
|
||||
{"bash", "", "bash -e {0}"},
|
||||
{"bash", "bash", "bash --noprofile --norc -e -o pipefail {0}"},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.shell, func(t *testing.T) {
|
||||
got := (&Step{Shell: tt.shell}).ShellCommand()
|
||||
got := (&Step{Shell: tt.shell, WorkflowShell: tt.workflowShell}).ShellCommand()
|
||||
assert.Equal(t, got, tt.want)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user