MCPcopy
hub / github.com/ossf/scorecard / GetShellForStep

Function GetShellForStep

checks/fileparser/github_workflow.go:239–274  ·  view source on GitHub ↗

GetShellForStep returns the shell that is used to run the given step.

(step *actionlint.Step, job *actionlint.Job)

Source from the content-addressed store, hash-verified

237
238// GetShellForStep returns the shell that is used to run the given step.
239func 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.
277func IsStepWindows(step *actionlint.Step) (bool, error) {

Callers 2

TestGitHubWorkflowShellFunction · 0.85

Calls 7

GetJobNameFunction · 0.85
GetStepNameFunction · 0.85
getExecRunShellFunction · 0.85
getJobDefaultRunShellFunction · 0.85
IsStepWindowsFunction · 0.85
JobAlwaysRunsOnWindowsFunction · 0.85
WithMessageMethod · 0.80

Tested by 1

TestGitHubWorkflowShellFunction · 0.68