Skip to content

Commit 5cf0fbe

Browse files
committed
add govulncheck for scanning vulnerabilities
Signed-off-by: Davanum Srinivas <[email protected]>
1 parent 2419fbd commit 5cf0fbe

File tree

1 file changed

+142
-0
lines changed

1 file changed

+142
-0
lines changed

.github/workflows/govulncheck.yml

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
# Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
name: Go Vulnerability Check
16+
17+
on:
18+
push:
19+
branches:
20+
- main
21+
- "pull-request/[0-9]+"
22+
paths-ignore:
23+
- '**/*.md'
24+
- 'docs/**'
25+
- 'LICENSE'
26+
- '.github/ISSUE_TEMPLATE/**'
27+
- '.github/headers/**'
28+
tags:
29+
- 'v*'
30+
workflow_dispatch:
31+
schedule:
32+
- cron: '0 6 * * *'
33+
34+
concurrency:
35+
group: ${{ github.workflow }}-${{ github.ref }}
36+
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
37+
38+
permissions:
39+
contents: read
40+
security-events: write
41+
pull-requests: write
42+
43+
jobs:
44+
govulncheck:
45+
runs-on: ubuntu-latest
46+
timeout-minutes: 30
47+
permissions:
48+
contents: read
49+
security-events: write
50+
steps:
51+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
52+
53+
- name: Setup Go
54+
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
55+
with:
56+
go-version: 'stable'
57+
58+
- name: Install govulncheck
59+
run: go install golang.org/x/vuln/cmd/govulncheck@latest
60+
61+
- name: Run govulncheck on all Go modules
62+
run: |
63+
# Find all directories with go.mod files
64+
go_modules=$(find . -name "go.mod" -type f | grep -v ".git" | sort)
65+
66+
if [ -z "$go_modules" ]; then
67+
echo "No Go modules found in repository"
68+
exit 0
69+
fi
70+
71+
failed_modules=()
72+
exit_code=0
73+
total_modules=0
74+
75+
echo "🔍 Discovered Go modules:"
76+
for mod_file in $go_modules; do
77+
mod_dir=$(dirname "$mod_file")
78+
# Extract module name from go.mod file
79+
mod_name=$(grep "^module " "$mod_file" | awk '{print $2}')
80+
echo " - $mod_name (path: $mod_dir)"
81+
total_modules=$((total_modules + 1))
82+
done
83+
echo ""
84+
85+
echo "Running govulncheck on $total_modules module(s)..."
86+
echo ""
87+
88+
for mod_file in $go_modules; do
89+
mod_dir=$(dirname "$mod_file")
90+
mod_name=$(grep "^module " "$mod_file" | awk '{print $2}')
91+
92+
echo "Checking $mod_name (path: $mod_dir)..."
93+
94+
# Run govulncheck and capture output
95+
vuln_output=$(govulncheck -C "$mod_dir" ./... 2>&1)
96+
vuln_exit_code=$?
97+
98+
if [ $vuln_exit_code -eq 0 ]; then
99+
echo "✅ $mod_name: No vulnerabilities found"
100+
else
101+
# Check if all vulnerabilities have "Fixed in: N/A" (non-actionable)
102+
if echo "$vuln_output" | grep -q "Fixed in: N/A"; then
103+
# Count total vulnerabilities and those with no fix
104+
total_vulns=$(echo "$vuln_output" | grep -c "Fixed in:")
105+
no_fix_vulns=$(echo "$vuln_output" | grep -c "Fixed in: N/A")
106+
107+
if [ "$total_vulns" -eq "$no_fix_vulns" ]; then
108+
echo "⚠️ $mod_name: Found $no_fix_vulns non-actionable vulnerability(ies) (no fixes available)"
109+
echo " Skipping as these vulnerabilities cannot be fixed at this time"
110+
else
111+
actionable_vulns=$((total_vulns - no_fix_vulns))
112+
echo "❌ $mod_name: Found $actionable_vulns actionable vulnerability(ies) that need fixing"
113+
failed_modules+=("$mod_name")
114+
exit_code=1
115+
fi
116+
else
117+
echo "❌ $mod_name: Vulnerabilities detected"
118+
failed_modules+=("$mod_name")
119+
exit_code=1
120+
fi
121+
122+
# Show the vulnerability details
123+
echo "$vuln_output" | head -20
124+
fi
125+
echo ""
126+
done
127+
128+
echo "=== SUMMARY ==="
129+
if [ ${#failed_modules[@]} -eq 0 ]; then
130+
echo "🎉 All $total_modules module(s) passed actionable vulnerability checks!"
131+
echo " (Non-actionable vulnerabilities with 'Fixed in: N/A' are ignored)"
132+
else
133+
echo "🚨 Actionable vulnerabilities found in ${#failed_modules[@]} of $total_modules module(s):"
134+
for module in "${failed_modules[@]}"; do
135+
echo " - $module"
136+
done
137+
echo ""
138+
echo "Please review and address the actionable vulnerabilities in the modules listed above."
139+
echo "Note: Vulnerabilities marked 'Fixed in: N/A' are ignored as they have no available fixes."
140+
fi
141+
142+
exit $exit_code

0 commit comments

Comments
 (0)