-
Notifications
You must be signed in to change notification settings - Fork 3.5k
52 lines (44 loc) · 1.58 KB
/
trivy-pr-comment.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
name: PR Vulnerability Scan
on: pull_request_target
permissions:
pull-requests: write
issues: write
jobs:
trivy:
name: Trivy Scan
runs-on: ubuntu-20.04
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Build Loki Image
run: |
IMAGE_TAG="$(./tools/image-tag)"
make loki-image
echo "IMAGE_TAG=${IMAGE_TAG}" >> $GITHUB_ENV
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
image-ref: "docker.io/grafana/loki:${{ env.IMAGE_TAG }}"
format: "json"
output: "trivy.json"
severity: "CRITICAL,HIGH"
- name: Prepare Trivy Message
run: |
echo "Trivy scan found the following vulnerabilities:" > trivy.txt
- name: Format Trivy Message
uses: sergeysova/jq-action@v2
continue-on-error: true
with:
cmd: jq -r '.Results[] | select(.Vulnerabilities != null) | .Vulnerabilities[] | "* **\(.Severity)** [\(.Title)](\(.PrimaryURL)) in `\(.PkgName)` v\(.InstalledVersion). Fixed in v\(.FixedVersion)"' trivy.json >> trivy.txt
- name: Determine whether to comment
continue-on-error: true
id: should-comment
run: |
if [[ $(wc -l < trivy.txt) -gt 1 ]]; then exit 0; fi
exit 1
- name: Comment on PR with Trivy scan results
uses: mshick/add-pr-comment@v2
if: ${{ steps.should-comment.outcome == 'success' }}
with:
message-id: trivy-${{ github.event.number }}
message-path: trivy.txt