Skip to content

Commit f6ad624

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

File tree

1 file changed

+160
-0
lines changed

1 file changed

+160
-0
lines changed

.github/workflows/govulncheck.yml

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
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+
strategy:
48+
fail-fast: false
49+
matrix:
50+
include:
51+
- component: data-models
52+
- component: commons
53+
- component: platform-connectors
54+
- component: store-client-sdk
55+
- component: health-events-analyzer
56+
- component: fault-quarantine-module
57+
- component: fault-remediation-module
58+
- component: labeler-module
59+
- component: node-drainer-module
60+
- component: janitor
61+
- component: syslog-health-monitor
62+
path: health-monitors/syslog-health-monitor
63+
- component: csp-health-monitor
64+
path: health-monitors/csp-health-monitor
65+
- component: tests
66+
- component: simple-health-client
67+
path: tilt/simple-health-client
68+
steps:
69+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
70+
71+
- name: Setup build environment
72+
uses: ./.github/actions/setup-ci-env
73+
74+
- name: Run govulncheck
75+
id: govulncheck
76+
uses: golang/govulncheck-action@b625fbe08f3bccbe446d94fbf87fcc875a4f50ee # v1.0.4
77+
with:
78+
work-dir: ${{ matrix.path || matrix.component }}
79+
continue-on-error: true
80+
81+
- name: Upload vulnerability results
82+
if: always() && startsWith(github.ref, 'refs/heads/pull-request/')
83+
uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0
84+
with:
85+
name: govulncheck-results-${{ matrix.component }}
86+
path: |
87+
results.json
88+
retention-days: 1
89+
if-no-files-found: ignore
90+
91+
- name: Create result summary
92+
if: always() && startsWith(github.ref, 'refs/heads/pull-request/')
93+
run: |
94+
mkdir -p results
95+
if [ "${{ steps.govulncheck.outcome }}" = "failure" ]; then
96+
echo "${{ matrix.component }}" > results/vulnerable-component.txt
97+
else
98+
echo "${{ matrix.component }}" > results/clean-component.txt
99+
fi
100+
101+
- name: Upload component result
102+
if: always() && startsWith(github.ref, 'refs/heads/pull-request/')
103+
uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0
104+
with:
105+
name: component-result-${{ matrix.component }}
106+
path: results/
107+
retention-days: 1
108+
109+
report-results:
110+
if: always() && startsWith(github.ref, 'refs/heads/pull-request/')
111+
needs: govulncheck
112+
runs-on: ubuntu-latest
113+
permissions:
114+
pull-requests: write
115+
steps:
116+
- name: Download all artifacts
117+
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
118+
with:
119+
pattern: component-result-*
120+
merge-multiple: true
121+
path: all-results
122+
123+
- name: Aggregate results and post comment
124+
run: |
125+
PR_NUM="${{ github.ref }}"
126+
PR_NUM="${PR_NUM##*/}"
127+
128+
# Collect vulnerable and clean components
129+
vulnerable_components=""
130+
clean_components=""
131+
132+
if ls all-results/vulnerable-component.txt &> /dev/null; then
133+
vulnerable_components=$(cat all-results/vulnerable-component.txt 2>/dev/null | sort | tr '\n' ' ' || echo "")
134+
fi
135+
136+
if ls all-results/clean-component.txt &> /dev/null; then
137+
clean_components=$(cat all-results/clean-component.txt 2>/dev/null | sort | tr '\n' ' ' || echo "")
138+
fi
139+
140+
# Only post comment if vulnerabilities were found
141+
if [ -n "$vulnerable_components" ]; then
142+
{
143+
echo "## 🚨 Go Vulnerability Check Results"
144+
echo ""
145+
echo "### ⚠️ Components with vulnerabilities:"
146+
for component in $vulnerable_components; do
147+
echo "- **$component**"
148+
done
149+
echo ""
150+
echo "Please review and address the vulnerabilities found in the above components."
151+
echo ""
152+
echo "_This comment was automatically generated by the govulncheck workflow._"
153+
} | gh pr comment "$PR_NUM" --body-file=-
154+
155+
echo "Posted vulnerability report to PR #$PR_NUM"
156+
else
157+
echo "No vulnerabilities found across all components. Skipping PR comment."
158+
fi
159+
env:
160+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)