Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Fixing parsing for Github workflow when matrix is an expression #1145

Merged
merged 5 commits into from
Oct 25, 2021

Conversation

ristomcgehee
Copy link
Contributor

  • Please check if the PR fulfills these requirements
  • What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
    Bug fix

  • What is the current behavior? (You can also link to an open issue here)
    Running ./scorecard --repo=ljharb/array-includes --show-details --checks=Pinned-Dependencies errors out when parsing one of the gh workflow files. This is because matrix does not have an os key:

  stable:
    needs: [matrix]
    name: 'stable minors'
    runs-on: ubuntu-latest

    strategy:
      matrix: ${{ fromJson(needs.matrix.outputs.stable) }}

Part of #839

  • Does this PR introduce a breaking change? (What changes might users need to make in their application due to this PR?)
    No

}
for _, os := range jobOses {
if !strings.HasPrefix(strings.ToLower(os), "windows-") {
return false
if !strings.HasPrefix(strings.ToLower(os), "windows") {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the - because I noticed in lucas-clemente/quic-go that you can use expressions to construct the OS name. 🤮

Copy link
Contributor

@laurentsimon laurentsimon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Chris!

jobOses = job.Strategy.Matrix.Os
} else {
jobOses = job.RunsOn
if len(job.RunsOn) != 1 || !strings.Contains(job.RunsOn[0], "matrix.os") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. does this work if there's a single os defined, i.e., len(job.RunsOn) == 1? Seems like the following code assumes data is in the job.Strategy.Matrix if this if-statement is false.
  2. is there a chance that job.RunsOn has length 0 and !strings.Contains(job.RunsOn[0], "matrix.os") evaluation will crash?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tweaked this code to make it more readable. With my changes I think it'll be easier to see the code will work when len(job.RunsOn) is 1 or 0.

oliverchang
oliverchang previously approved these changes Oct 20, 2021
checks/pinned_dependencies.go Outdated Show resolved Hide resolved
checks/pinned_dependencies.go Outdated Show resolved Hide resolved
@oliverchang oliverchang dismissed their stale review October 20, 2021 04:39

accidental approval

name: "Matrix as expression",
filename: "./testdata/github-workflow-matrix-expression.yaml",
expected: scut.TestReturn{
Error: nil,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have thought this test would return an error since we don't try to parse things like fromJson(needs.matrix.outputs.latest) and return error unable to determine OS for job.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In github-workflow-matrix-expression.yaml and in ljharb/array-includes, the runs-on field contains the OS so we are able to avoid returning an error.

@naveensrinivasan naveensrinivasan enabled auto-merge (rebase) October 23, 2021 21:31
@naveensrinivasan naveensrinivasan merged commit faab696 into ossf:main Oct 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants