Skip to content

Commit

Permalink
bug/issue #2448 - manage special bash options when no shell is defined
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastien-perpignane committed Sep 12, 2024
1 parent f75a2d8 commit d9ea33a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
12 changes: 10 additions & 2 deletions pkg/model/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Shell string `yaml:"shell"`
Env yaml.Node `yaml:"env"`
With map[string]string `yaml:"with"`
Expand Down Expand Up @@ -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":
Expand Down
12 changes: 7 additions & 5 deletions pkg/runner/step_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,16 +166,16 @@ func (sr *stepRun) setupShell(ctx context.Context) {
step := sr.Step

if step.Shell == "" {
step.Shell = rc.Run.Job().Defaults.Run.Shell
step.WorkflowShell = rc.Run.Job().Defaults.Run.Shell
}

step.Shell = rc.NewExpressionEvaluator(ctx).Interpolate(ctx, step.Shell)
step.WorkflowShell = rc.NewExpressionEvaluator(ctx).Interpolate(ctx, step.Shell)

if step.Shell == "" {
step.Shell = rc.Run.Workflow.Defaults.Run.Shell
if step.WorkflowShell == "" {
step.WorkflowShell = rc.Run.Workflow.Defaults.Run.Shell
}

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

Expand Down

0 comments on commit d9ea33a

Please sign in to comment.