|
56 | 56 | fi |
57 | 57 |
|
58 | 58 | # Check if file has any error-level results using jq |
59 | | - # Exit code 0 means results found, 1 means no results (which is good), >1 means jq error |
60 | | - if jq -e '.runs[]?.results[]? | select(.level == "error")' gosec-results.sarif > /dev/null 2>&1; then |
| 59 | + # We use jq to filter, then check if output is non-empty with grep -q . |
| 60 | + # This handles the case where jq returns empty output (no vulnerabilities) |
| 61 | + if jq -r '.runs[]?.results[]? | select(.level == "error")' gosec-results.sarif 2>/dev/null | grep -q .; then |
61 | 62 | echo "❌ High or critical security vulnerabilities found!" |
62 | 63 | jq -r '.runs[]?.results[]? | select(.level == "error") | " - \(.ruleId): \(.message.text)"' gosec-results.sarif || true |
63 | 64 | exit 1 |
|
97 | 98 | exit 1 |
98 | 99 | fi |
99 | 100 |
|
100 | | - if jq -e '.runs[]?.results[]? | select(.level == "error" or .level == "warning")' trivy-repo-results.sarif > /dev/null 2>&1; then |
| 101 | + # Check if file has any error or warning level results |
| 102 | + # We use jq to filter, then check if output is non-empty with grep -q . |
| 103 | + if jq -r '.runs[]?.results[]? | select(.level == "error" or .level == "warning")' trivy-repo-results.sarif 2>/dev/null | grep -q .; then |
101 | 104 | echo "❌ High or critical vulnerabilities found in repository scan!" |
| 105 | + jq -r '.runs[]?.results[]? | select(.level == "error" or .level == "warning") | " - \(.ruleId): \(.message.text)"' trivy-repo-results.sarif || true |
102 | 106 | exit 1 |
103 | 107 | else |
104 | 108 | echo "✅ No high or critical vulnerabilities found" |
@@ -136,8 +140,11 @@ jobs: |
136 | 140 | exit 1 |
137 | 141 | fi |
138 | 142 |
|
139 | | - if jq -e '.runs[]?.results[]? | select(.level == "error" or .level == "warning")' trivy-config-results.sarif > /dev/null 2>&1; then |
| 143 | + # Check if file has any error or warning level results |
| 144 | + # We use jq to filter, then check if output is non-empty with grep -q . |
| 145 | + if jq -r '.runs[]?.results[]? | select(.level == "error" or .level == "warning")' trivy-config-results.sarif 2>/dev/null | grep -q .; then |
140 | 146 | echo "❌ High or critical configuration issues found!" |
| 147 | + jq -r '.runs[]?.results[]? | select(.level == "error" or .level == "warning") | " - \(.ruleId): \(.message.text)"' trivy-config-results.sarif || true |
141 | 148 | exit 1 |
142 | 149 | else |
143 | 150 | echo "✅ No high or critical configuration issues found" |
|
0 commit comments