Skip to content

Commit a262aab

Browse files
Fix OSV-Scanner
Use the reusable workflow instead of actions directly, as recommended. Signed-off-by: erjavaskivuori <[email protected]>
1 parent 29996db commit a262aab

File tree

2 files changed

+72
-69
lines changed

2 files changed

+72
-69
lines changed

.github/workflows/osv-scanner-scan.yml

Lines changed: 0 additions & 69 deletions
This file was deleted.
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# runs vulnerability scans and add them to Github Security tab
2+
3+
name: OSV-Scanner Scheduled
4+
5+
on:
6+
workflow_dispatch:
7+
schedule:
8+
- cron: "12 6 * * *"
9+
pull_request:
10+
paths:
11+
- ".github/workflows/osv-scanner-scan.yml"
12+
13+
permissions:
14+
actions: read
15+
contents: read
16+
security-events: write # for uploading SARIF files
17+
18+
jobs:
19+
set-go-version:
20+
name: Set up Go version
21+
runs-on: ubuntu-latest
22+
steps:
23+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
24+
- name: Calculate go version
25+
id: vars
26+
run: echo "go_version=$(make go-version)" >> "${GITHUB_OUTPUT}"
27+
- name: Set up Go
28+
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
29+
with:
30+
go-version: ${{ steps.vars.outputs.go_version }}
31+
- name: Create config.toml
32+
run: echo "GoVersionOverride = \"${{ steps.vars.outputs.go_version }}\"" > config.toml
33+
- name: Upload config.toml
34+
uses: actions/upload-artifact@v4
35+
with:
36+
name: calculated-go-version
37+
path: ./config.toml
38+
39+
scan-scheduled:
40+
name: Run OSV Scanner
41+
needs: set-go-version
42+
uses: "google/osv-scanner-action/.github/workflows/[email protected]"
43+
with:
44+
download-artifact: calculated-go-version
45+
scan-args: |-
46+
--config=./config.toml
47+
--fail-on-vuln=false
48+
49+
check-and-notify:
50+
name: Check vulnerabilities and notify
51+
needs: [set-go-version, scan-scheduled]
52+
runs-on: ubuntu-latest
53+
if: always()
54+
steps:
55+
- uses: actions/download-artifact@v4
56+
with:
57+
name: SARIF file
58+
- name: Check for vulnerabilities in SARIF
59+
id: check
60+
run: |
61+
HAS_VULN=$(jq '[.runs[].results[]] | length > 0' results.sarif)
62+
echo "has_vulnerabilities=$HAS_VULN" >> $GITHUB_OUTPUT
63+
- name: Slack Notification on Vulnerability or Failure
64+
if: ${{ steps.check.outputs.has_vulnerabilities == 'true' || contains(needs.*.result, 'failure') }}
65+
uses: rtCamp/action-slack-notify@e31e87e03dd19038e411e38ae27cbad084a90661 # 2.3.3
66+
env:
67+
SLACK_TITLE: "OSV-Scanner failed or detected vulnerabilities in ${{ github.repository }}"
68+
SLACK_COLOR: "#FF0000"
69+
SLACK_MESSAGE: "OSV-Scanner failed or detected vulnerabilities in ${{ github.repository }}"
70+
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
71+
SLACK_CHANNEL: metal3-github-actions-notify
72+
SLACK_USERNAME: metal3-github-actions-notify

0 commit comments

Comments
 (0)