IsStepWindows returns true if the step will be run on Windows.
(step *actionlint.Step)
| 275 | |
| 276 | // IsStepWindows returns true if the step will be run on Windows. |
| 277 | func IsStepWindows(step *actionlint.Step) (bool, error) { |
| 278 | if step.If == nil { |
| 279 | return false, nil |
| 280 | } |
| 281 | windowsRegexes := []string{ |
| 282 | // Looking for "if: runner.os == 'Windows'" (and variants) |
| 283 | `(?i)runner\.os\s*==\s*['"]windows['"]`, |
| 284 | // Looking for "if: ${{ startsWith(runner.os, 'Windows') }}" (and variants) |
| 285 | `(?i)\$\{\{\s*startsWith\(runner\.os,\s*['"]windows['"]\)`, |
| 286 | // Looking for "if: matrix.os == 'windows-2019'" (and variants) |
| 287 | `(?i)matrix\.os\s*==\s*['"]windows-`, |
| 288 | } |
| 289 | |
| 290 | for _, windowsRegex := range windowsRegexes { |
| 291 | matches, err := regexp.MatchString(windowsRegex, step.If.Value) |
| 292 | if err != nil { |
| 293 | return false, sce.WithMessage(sce.ErrScorecardInternal, fmt.Sprintf("error matching Windows regex: %v", err)) |
| 294 | } |
| 295 | if matches { |
| 296 | return true, nil |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | return false, nil |
| 301 | } |
| 302 | |
| 303 | // IsWorkflowFile returns true if this is a GitHub workflow file. |
| 304 | func IsWorkflowFile(pathfn string) bool { |
no test coverage detected