Skip to content

Commit 14f6f8c

Browse files
committed
chore/security : fix 'Check for vulnerabilities' step
1 parent bf2e7fc commit 14f6f8c

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

.github/workflows/dispatcher-build.yaml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ jobs:
9292
output: 'trivy-dispatcher-${{ matrix.model_version }}-image.sarif'
9393
severity: 'HIGH,CRITICAL'
9494
exit-code: '0'
95+
9596
- name: Upload Dispatcher image scan results to GitHub Security tab
9697
if: always() && hashFiles('trivy-dispatcher-${{ matrix.model_version }}-image.sarif') != ''
9798
uses: github/codeql-action/upload-sarif@v3
@@ -106,10 +107,16 @@ jobs:
106107
path: '*.sarif'
107108
retention-days: 7
108109
- name: Check for vulnerabilities
110+
if: always()
109111
run: |
112+
echo "Checking for SARIF file: trivy-dispatcher-${{ matrix.model_version }}-image.sarif"
110113
if [ -f "trivy-dispatcher-${{ matrix.model_version }}-image.sarif" ]; then
111-
# Check if the SARIF file contains any results indicating vulnerabilities
112-
if grep -q '"results":\s*\[.*\]' "trivy-dispatcher-${{ matrix.model_version }}-image.sarif" && ! grep -q '"results":\s*\[\s*\]' "trivy-dispatcher-${{ matrix.model_version }}-image.sarif"; then
114+
echo "SARIF file found, checking for vulnerabilities..."
115+
# Count the number of vulnerability results in the SARIF file
116+
VULN_COUNT=$(jq '[.runs[].results[] | select(.level == "error" or .level == "warning")] | length' "trivy-dispatcher-${{ matrix.model_version }}-image.sarif" 2>/dev/null || echo "0")
117+
echo "Found $VULN_COUNT HIGH/CRITICAL vulnerabilities"
118+
119+
if [ "$VULN_COUNT" -gt 0 ]; then
113120
echo "HIGH or CRITICAL vulnerabilities found in dispatcher image"
114121
echo "Please check the security scan results in the Security tab"
115122
exit 1
@@ -118,5 +125,6 @@ jobs:
118125
fi
119126
else
120127
echo "SARIF report not found"
128+
echo "This might indicate the Trivy scan failed to complete or generate output"
121129
exit 1
122130
fi

0 commit comments

Comments
 (0)