Skip to content

Commit 28dbaac

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 28dbaac

File tree

2 files changed

+74
-69
lines changed

2 files changed

+74
-69
lines changed

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

Lines changed: 0 additions & 69 deletions
This file was deleted.
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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-scheduled.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+
if: ${{ github.repository == 'metal3-io/ip-address-manager' }}
23+
steps:
24+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
25+
- name: Calculate go version
26+
id: vars
27+
run: echo "go_version=$(make go-version)" >> "${GITHUB_OUTPUT}"
28+
- name: Set up Go
29+
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
30+
with:
31+
go-version: ${{ steps.vars.outputs.go_version }}
32+
- name: Create config.toml
33+
run: echo "GoVersionOverride = \"${{ steps.vars.outputs.go_version }}\"" > config.toml
34+
- name: Upload config.toml
35+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
36+
with:
37+
name: calculated-go-version
38+
path: ./config.toml
39+
40+
scan-scheduled:
41+
name: Run OSV Scanner
42+
needs: set-go-version
43+
if: ${{ github.repository == 'metal3-io/ip-address-manager' }}
44+
uses: "google/osv-scanner-action/.github/workflows/osv-scanner-reusable.yml@90b209d0ea55cea1da9fc0c4e65782cc6acb6e2e" # v2.2.2
45+
with:
46+
download-artifact: calculated-go-version
47+
fail-on-vuln: false
48+
scan-args: |-
49+
--config=./config.toml
50+
51+
check-and-notify:
52+
name: Check vulnerabilities and notify
53+
needs: [set-go-version, scan-scheduled]
54+
runs-on: ubuntu-latest
55+
if: ${{ always() && github.repository == 'metal3-io/ip-address-manager' }}
56+
steps:
57+
- uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0
58+
with:
59+
name: SARIF file
60+
- name: Check for vulnerabilities in SARIF
61+
id: check
62+
run: |
63+
HAS_VULN=$(jq '[.runs[].results[]] | length > 0' results.sarif)
64+
echo "has_vulnerabilities=$HAS_VULN" >> $GITHUB_OUTPUT
65+
- name: Slack Notification on Vulnerability or Failure
66+
if: ${{ steps.check.outputs.has_vulnerabilities == 'true' || contains(needs.*.result, 'failure') }}
67+
uses: rtCamp/action-slack-notify@e31e87e03dd19038e411e38ae27cbad084a90661 # 2.3.3
68+
env:
69+
SLACK_TITLE: "OSV-Scanner failed or detected vulnerabilities in ${{ github.repository }}"
70+
SLACK_COLOR: "#FF0000"
71+
SLACK_MESSAGE: "OSV-Scanner failed or detected vulnerabilities in ${{ github.repository }}"
72+
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
73+
SLACK_CHANNEL: metal3-github-actions-notify
74+
SLACK_USERNAME: metal3-github-actions-notify

0 commit comments

Comments
 (0)