Skip to content

Commit 770a633

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 770a633

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-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+
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() && github.repository == 'metal3-io/ip-address-manager' }}
54+
steps:
55+
- uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0
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)