Skip to content

Commit d9ea33a

Browse files
bug/issue nektos#2448 - manage special bash options when no shell is defined
1 parent f75a2d8 commit d9ea33a

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

pkg/model/workflow.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,8 @@ type Step struct {
572572
Uses string `yaml:"uses"`
573573
Run string `yaml:"run"`
574574
WorkingDirectory string `yaml:"working-directory"`
575+
// WorkflowShell is the shell really configured in the job, directly at step level or higher in defaults.run.shell
576+
WorkflowShell string
575577
Shell string `yaml:"shell"`
576578
Env yaml.Node `yaml:"env"`
577579
With map[string]string `yaml:"with"`
@@ -614,8 +616,14 @@ func (s *Step) ShellCommand() string {
614616

615617
//Reference: https://github.com/actions/runner/blob/8109c962f09d9acc473d92c595ff43afceddb347/src/Runner.Worker/Handlers/ScriptHandlerHelpers.cs#L9-L17
616618
switch s.Shell {
617-
case "", "bash":
618-
shellCommand = "bash --noprofile --norc -e -o pipefail {0}"
619+
case "":
620+
shellCommand = "bash -e {0}"
621+
case "bash":
622+
if s.WorkflowShell == "" {
623+
shellCommand = "bash -e {0}"
624+
} else {
625+
shellCommand = "bash --noprofile --norc -e -o pipefail {0}"
626+
}
619627
case "pwsh":
620628
shellCommand = "pwsh -command . '{0}'"
621629
case "python":

pkg/runner/step_run.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -166,16 +166,16 @@ func (sr *stepRun) setupShell(ctx context.Context) {
166166
step := sr.Step
167167

168168
if step.Shell == "" {
169-
step.Shell = rc.Run.Job().Defaults.Run.Shell
169+
step.WorkflowShell = rc.Run.Job().Defaults.Run.Shell
170170
}
171171

172-
step.Shell = rc.NewExpressionEvaluator(ctx).Interpolate(ctx, step.Shell)
172+
step.WorkflowShell = rc.NewExpressionEvaluator(ctx).Interpolate(ctx, step.Shell)
173173

174-
if step.Shell == "" {
175-
step.Shell = rc.Run.Workflow.Defaults.Run.Shell
174+
if step.WorkflowShell == "" {
175+
step.WorkflowShell = rc.Run.Workflow.Defaults.Run.Shell
176176
}
177177

178-
if step.Shell == "" {
178+
if step.WorkflowShell == "" {
179179
if _, ok := rc.JobContainer.(*container.HostEnvironment); ok {
180180
shellWithFallback := []string{"bash", "sh"}
181181
// Don't use bash on windows by default, if not using a docker container
@@ -196,6 +196,8 @@ func (sr *stepRun) setupShell(ctx context.Context) {
196196
// Currently only linux containers are supported, use sh by default like actions/runner
197197
step.Shell = "sh"
198198
}
199+
} else {
200+
step.Shell = step.WorkflowShell
199201
}
200202
}
201203

0 commit comments

Comments
 (0)