@@ -49,21 +49,34 @@ jobs:
4949 shell : bash
5050 run : |
5151 if [ -f trivy-results.json ]; then
52- VULN_COUNT=$(jq -r '.vulnerabilities | length // 0' trivy-results.json)
52+ # Count both vulnerabilities and secrets
53+ VULN_COUNT=$(jq -r '[.Results[] | (.Vulnerabilities, .Secrets) | select(. != null) | length] | add // 0' trivy-results.json)
54+
5355 if [ "${VULN_COUNT:-0}" -gt 0 ]; then
5456 echo "has_vulnerabilities=true" >> "$GITHUB_OUTPUT"
5557
56- # Create native GitHub annotations for vulnerabilities
57- echo "# Security Vulnerabilities Found" >> $GITHUB_STEP_SUMMARY
58- echo "| Severity | Package | Installed Version | Vulnerability ID | Description |" >> $GITHUB_STEP_SUMMARY
59- echo "|----------|---------|-------------------|------------------|-------------|" >> $GITHUB_STEP_SUMMARY
58+ echo "# Security Findings Found" >> $GITHUB_STEP_SUMMARY
6059
61- jq -r '.vulnerabilities[] | "| \(.severity) | \(.pkgName) | \(.installedVersion) | \(.vulnerabilityID) | \(.title) |"' trivy-results.json >> $GITHUB_STEP_SUMMARY
60+ # Handle OS/Package Vulnerabilities
61+ if jq -e '.Results[] | select(.Vulnerabilities != null)' trivy-results.json > /dev/null; then
62+ echo "## Package Vulnerabilities" >> $GITHUB_STEP_SUMMARY
63+ echo "| Severity | Package | Installed Version | Fixed Version | Vulnerability ID |" >> $GITHUB_STEP_SUMMARY
64+ echo "|----------|---------|-------------------|---------------|-----------------|" >> $GITHUB_STEP_SUMMARY
65+ jq -r '.Results[] | select(.Vulnerabilities != null) | .Vulnerabilities[] | "| \(.Severity) | \(.PkgName) | \(.InstalledVersion) | \(.FixedVersion) | \(.VulnerabilityID) |"' trivy-results.json >> $GITHUB_STEP_SUMMARY
66+ fi
6267
63- echo "::notice::Found ${VULN_COUNT} security vulnerabilities that need to be addressed."
68+ # Handle Secrets
69+ if jq -e '.Results[] | select(.Secrets != null)' trivy-results.json > /dev/null; then
70+ echo "## Secrets" >> $GITHUB_STEP_SUMMARY
71+ echo "| Severity | Category | Title | Target | Rule ID |" >> $GITHUB_STEP_SUMMARY
72+ echo "|----------|-----------|--------|---------|----------|" >> $GITHUB_STEP_SUMMARY
73+ jq -r '.Results[] | select(.Secrets != null) | .Secrets[] | "| \(.Severity) | \(.Category) | \(.Title) | \(.Target) | \(.RuleID) |"' trivy-results.json >> $GITHUB_STEP_SUMMARY
74+ fi
75+
76+ echo "::notice::Found ${VULN_COUNT} security findings that need to be addressed."
6477 else
6578 echo "has_vulnerabilities=false" >> "$GITHUB_OUTPUT"
66- echo "No vulnerabilities found." >> $GITHUB_STEP_SUMMARY
79+ echo "No security findings found." >> $GITHUB_STEP_SUMMARY
6780 fi
6881 else
6982 echo "Error: trivy-results.json not found"
0 commit comments