GetShellForStep returns the shell that is used to run the given step.
(step *actionlint.Step, job *actionlint.Job)
| 237 | |
| 238 | // GetShellForStep returns the shell that is used to run the given step. |
| 239 | func GetShellForStep(step *actionlint.Step, job *actionlint.Job) (string, error) { |
| 240 | // https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#using-a-specific-shell. |
| 241 | execRun, ok := step.Exec.(*actionlint.ExecRun) |
| 242 | if !ok { |
| 243 | jobName := GetJobName(job) |
| 244 | stepName := GetStepName(step) |
| 245 | return "", sce.WithMessage(sce.ErrScorecardInternal, |
| 246 | fmt.Sprintf("unable to parse step '%v' for job '%v'", jobName, stepName)) |
| 247 | } |
| 248 | execRunShell := getExecRunShell(execRun) |
| 249 | if execRunShell != "" { |
| 250 | return execRunShell, nil |
| 251 | } |
| 252 | jobDefaultRunShell := getJobDefaultRunShell(job) |
| 253 | if jobDefaultRunShell != "" { |
| 254 | return jobDefaultRunShell, nil |
| 255 | } |
| 256 | |
| 257 | isStepWindows, err := IsStepWindows(step) |
| 258 | if err != nil { |
| 259 | return "", err |
| 260 | } |
| 261 | if isStepWindows { |
| 262 | return defaultShellWindows, nil |
| 263 | } |
| 264 | |
| 265 | alwaysRunsOnWindows, err := JobAlwaysRunsOnWindows(job) |
| 266 | if err != nil { |
| 267 | return "", err |
| 268 | } |
| 269 | if alwaysRunsOnWindows { |
| 270 | return defaultShellWindows, nil |
| 271 | } |
| 272 | |
| 273 | return defaultShellNonWindows, nil |
| 274 | } |
| 275 | |
| 276 | // IsStepWindows returns true if the step will be run on Windows. |
| 277 | func IsStepWindows(step *actionlint.Step) (bool, error) { |