Skip to content

Commit e721348

Browse files
authored
Merge pull request #1081 from fabriziosestito/ci/upload-govulncheck-sarif
ci(govulncheck): upload results as SARIF to the security tab rather than failing
2 parents 7dc6881 + ac6d1e8 commit e721348

1 file changed

Lines changed: 36 additions & 8 deletions

File tree

.github/workflows/govulncheck.yml

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ on:
44
paths:
55
- go.sum
66
- go.mod
7+
pull_request:
8+
paths:
9+
- go.sum
10+
- go.mod
711
schedule:
812
- cron: "0 0 * * *"
913

@@ -14,19 +18,43 @@ jobs:
1418
govulncheck:
1519
name: govulncheck
1620
runs-on: ubuntu-latest
21+
permissions:
22+
contents: read
23+
security-events: write
24+
actions: read
25+
env:
26+
GOEXPERIMENT: jsonv2
1727
steps:
18-
# checkout the source, required to have `go.mod`
1928
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
2029
with:
21-
fetch-depth: 0
2230
persist-credentials: false
23-
- name: govulncheck
31+
- name: Run govulncheck
32+
# With `output-format: sarif` the action exits 0 even when
33+
# vulnerabilities are found; findings are surfaced via the SARIF
34+
# upload below. See https://pkg.go.dev/golang.org/x/vuln/cmd/govulncheck#hdr-Exit_codes
2435
uses: golang/govulncheck-action@b625fbe08f3bccbe446d94fbf87fcc875a4f50ee # v1.0.4
25-
env:
26-
GOEXPERIMENT: jsonv2
2736
with:
28-
# required to override the default value that is 'stable'
29-
# in this way `go-version-file` is going to be taken into account
37+
# Override the default 'stable' so go-version-file is actually used
38+
# (setup-go gives precedence to go-version over go-version-file).
3039
go-version-input: ""
31-
go-version-file: "go.mod"
40+
go-version-file: go.mod
3241
go-package: ./...
42+
output-format: sarif
43+
output-file: govulncheck.sarif
44+
repo-checkout: false
45+
- name: Upload SARIF to GitHub Security tab
46+
# Skip for PRs from forks: GitHub strips `security-events: write` from
47+
# the token in that case, so the upload would fail. The SARIF is still
48+
# available as a workflow artifact (uploaded below) for reviewers.
49+
if: github.event.pull_request.head.repo.fork != true
50+
uses: github/codeql-action/upload-sarif@ce64ddcb0d8d890d2df4a9d1c04ff297367dea2a # v3.35.2
51+
with:
52+
sarif_file: govulncheck.sarif
53+
category: govulncheck
54+
- name: Upload SARIF as workflow artifact
55+
if: always()
56+
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
57+
with:
58+
name: govulncheck-sarif
59+
path: govulncheck.sarif
60+
if-no-files-found: warn

0 commit comments

Comments
 (0)