Skip to content

Commit

Permalink
Don't error on workflow parse failure in Binary-Artifacts (#2170)
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanent authored Aug 19, 2022
1 parent 2cbf5af commit 4a15760
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 9 deletions.
7 changes: 4 additions & 3 deletions checks/raw/binary_artifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,9 @@ func checkWorkflowValidatesGradleWrapper(path string, content []byte, args ...in
}

action, errs := actionlint.Parse(content)
if len(errs) > 0 {
return true, errs[0]
if len(errs) > 0 || action == nil {
// Parse fail, so not this file.
return true, nil
}

for _, j := range action.Jobs {
Expand All @@ -249,7 +250,7 @@ func checkWorkflowValidatesGradleWrapper(path string, content []byte, args ...in
}
// OK! This is it.
*validatingWorkflowFile = filepath.Base(path)
return true, nil
return false, nil
}
}
}
Expand Down
50 changes: 44 additions & 6 deletions checks/raw/binary_artifact_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ func TestBinaryArtifacts(t *testing.T) {
files: [][]string{
{"../testdata/binaryartifacts/jars/gradle-wrapper.jar"},
{
"../testdata/binaryartifacts/workflows/nonverify.yml",
"../testdata/binaryartifacts/workflows/verify.yml",
"../testdata/binaryartifacts/workflows/nonverify.yaml",
"../testdata/binaryartifacts/workflows/verify.yaml",
},
},
successfulWorkflowRuns: []clients.WorkflowRun{
Expand All @@ -124,7 +124,7 @@ func TestBinaryArtifacts(t *testing.T) {
err: nil,
files: [][]string{
{"../testdata/binaryartifacts/jars/gradle-wrapper.jar"},
{"../testdata/binaryartifacts/workflows/nonverify.yml"},
{"../testdata/binaryartifacts/workflows/nonverify.yaml"},
},
getFileContentCount: 2,
expect: 1,
Expand All @@ -134,7 +134,7 @@ func TestBinaryArtifacts(t *testing.T) {
err: nil,
files: [][]string{
{"../testdata/binaryartifacts/jars/gradle-wrapper.jar"},
{"../testdata/binaryartifacts/workflows/verify.yml"},
{"../testdata/binaryartifacts/workflows/verify.yaml"},
},
successfulWorkflowRuns: []clients.WorkflowRun{
{
Expand All @@ -158,13 +158,51 @@ func TestBinaryArtifacts(t *testing.T) {
files: [][]string{
{"../testdata/binaryartifacts/jars/gradle-wrapper.jar"},
{
"../testdata/binaryartifacts/workflows/nonverify.yml",
"../testdata/binaryartifacts/workflows/verify-outdated-action.yml",
"../testdata/binaryartifacts/workflows/nonverify.yaml",
"../testdata/binaryartifacts/workflows/verify-outdated-action.yaml",
},
},
getFileContentCount: 3,
expect: 1,
},
{
name: "gradle-wrapper.jar with no verification action due to bad workflow",
err: nil,
files: [][]string{
{"../testdata/binaryartifacts/jars/gradle-wrapper.jar"},
{
"../testdata/binaryartifacts/workflows/invalid.yaml",
},
},
getFileContentCount: 2,
expect: 1,
},
{
name: "gradle-wrapper.jar with verification and bad workflow",
err: nil,
files: [][]string{
{"../testdata/binaryartifacts/jars/gradle-wrapper.jar"},
{
"../testdata/binaryartifacts/workflows/invalid.yaml",
"../testdata/binaryartifacts/workflows/verify.yaml",
},
},
successfulWorkflowRuns: []clients.WorkflowRun{
{
HeadSHA: strptr("sha-a"),
},
},
commits: []clients.Commit{
{
SHA: "sha-a",
},
{
SHA: "sha-old",
},
},
getFileContentCount: 3,
expect: 0,
},
}
for _, tt := range tests {
tt := tt // Re-initializing variable so it is not changed while executing the closure below
Expand Down
12 changes: 12 additions & 0 deletions checks/testdata/binaryartifacts/workflows/invalid.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: "Workflow with no on property"

jobs:
validation:
name: "Build"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: '1.18.3' # The Go version to download (if necessary) and use.
- run: go run main.go

0 comments on commit 4a15760

Please sign in to comment.