@@ -3,12 +3,14 @@ package runner
33import (
44 "context"
55 "fmt"
6+ "runtime"
67 "strings"
78
89 "github.com/kballard/go-shellquote"
910
1011 "github.com/nektos/act/pkg/common"
1112 "github.com/nektos/act/pkg/container"
13+ "github.com/nektos/act/pkg/lookpath"
1214 "github.com/nektos/act/pkg/model"
1315)
1416
@@ -138,6 +140,22 @@ func (sr *stepRun) setupShellCommand(ctx context.Context) (name, script string,
138140 return name , script , err
139141}
140142
143+ type localEnv struct {
144+ env map [string ]string
145+ }
146+
147+ func (l * localEnv ) Getenv (name string ) string {
148+ if runtime .GOOS == "windows" {
149+ for k , v := range l .env {
150+ if strings .EqualFold (name , k ) {
151+ return v
152+ }
153+ }
154+ return ""
155+ }
156+ return l .env [name ]
157+ }
158+
141159func (sr * stepRun ) setupShell (ctx context.Context ) {
142160 rc := sr .RunContext
143161 step := sr .Step
@@ -152,13 +170,25 @@ func (sr *stepRun) setupShell(ctx context.Context) {
152170 step .Shell = rc .Run .Workflow .Defaults .Run .Shell
153171 }
154172
155- // current GitHub Runner behaviour is that default is `sh`,
156- // but if it's not container it validates with `which` command
157- // if `bash` is available, and provides `bash` if it is
158- // for now I'm going to leave below logic, will address it in different PR
159- // https://github.com/actions/runner/blob/9a829995e02d2db64efb939dc2f283002595d4d9/src/Runner.Worker/Handlers/ScriptHandler.cs#L87-L91
160- if rc .Run .Job ().Container () != nil {
161- if rc .Run .Job ().Container ().Image != "" && step .Shell == "" {
173+ if step .Shell == "" {
174+ if _ , ok := rc .JobContainer .(* container.HostEnvironment ); ok {
175+ shellWithFallback := []string {"bash" , "sh" }
176+ // Don't use bash on windows by default, if not using a docker container
177+ if runtime .GOOS == "windows" {
178+ shellWithFallback = []string {"pwsh" , "powershell" }
179+ }
180+ step .Shell = shellWithFallback [0 ]
181+ lenv := & localEnv {env : map [string ]string {}}
182+ for k , v := range sr .env {
183+ lenv .env [k ] = v
184+ }
185+ sr .getRunContext ().ApplyExtraPath (ctx , & lenv .env )
186+ _ , err := lookpath .LookPath2 (shellWithFallback [0 ], lenv )
187+ if err != nil {
188+ step .Shell = shellWithFallback [1 ]
189+ }
190+ } else if containerImage := rc .containerImage (ctx ); containerImage != "" {
191+ // Currently only linux containers are supported, use sh by default like actions/runner
162192 step .Shell = "sh"
163193 }
164194 }
0 commit comments