-
Notifications
You must be signed in to change notification settings - Fork 1
100 lines (86 loc) · 3.53 KB
/
Copy pathscan.yml
File metadata and controls
100 lines (86 loc) · 3.53 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
name: Trivy Scan
on:
push:
schedule:
- cron: '0 0 * * 1'
permissions:
contents: read
jobs:
prepare:
name: Prepare list of images to build
runs-on: ubuntu-latest
outputs:
images: ${{ steps.set-matrix.outputs.images }}
steps:
- name: Check out the source code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Set matrix
id: set-matrix
run: echo images="$(jq '."x-build"' images/src/*/.devcontainer.json | jq --slurp -c .)" >> "${GITHUB_OUTPUT}"
scan-image:
needs: prepare
name: 'Build and Scan: ${{ matrix.image.name }}'
runs-on: ubuntu-latest
permissions:
contents: read
packages: read
security-events: write
strategy:
fail-fast: false
matrix:
image: ${{ fromJson(needs.prepare.outputs.images) }}
steps:
- name: Check out the source code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
- name: Check changed files
id: changes
run: |
if [ "${{ github.event_name }}" = "push" ]; then
if [ "${{ github.event.base_ref }}" = "" ]; then
base="HEAD^"
else
base="${{ github.event.before }}"
fi
head="${{ github.event.after }}"
image="images/src/${{ matrix.image.image-name }}"
changes="$(git diff --name-only "${base}" "${head}" -- "${image}" | grep -Fv "${image}/README.md" || true)"
if [ -n "${changes}" ]; then
echo needs_build=true >> "${GITHUB_OUTPUT}"
else
echo needs_build=false >> "${GITHUB_OUTPUT}"
fi
else
echo needs_build=true >> "${GITHUB_OUTPUT}"
fi
- name: Set up QEMU
uses: docker/setup-qemu-action@99012661954931238ded8c8b007157a8430204e1 # v4.4.0
if: steps.changes.outputs.needs_build == 'true'
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1
if: steps.changes.outputs.needs_build == 'true'
- name: Install @devcontainers/cli
run: npm install -g @devcontainers/cli
if: steps.changes.outputs.needs_build == 'true'
- name: Build image
run: devcontainer build --workspace-folder "images/src/${{ matrix.image.image-name }}" --image-name ${{ matrix.image.image-name }}
if: steps.changes.outputs.needs_build == 'true'
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@57a97c7e7821a5776cebc9bb87c984fa69cba8f1 # 0.35.0
if: ${{ steps.changes.outputs.needs_build == 'true' && github.event.sender.login != 'dependabot[bot]' }}
with:
image-ref: '${{ matrix.image.image-name }}:latest'
format: sarif
output: trivy-${{ matrix.image.image-name }}.sarif
- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@2892aa5e19bbd11bc0cff5427e3b750a04d9e3c2 # v4.38.2
if: ${{ steps.changes.outputs.needs_build == 'true' && github.event.sender.login != 'dependabot[bot]' }}
with:
sarif_file: trivy-${{ matrix.image.image-name }}.sarif
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@57a97c7e7821a5776cebc9bb87c984fa69cba8f1 # 0.35.0
if: steps.changes.outputs.needs_build == 'true'
with:
image-ref: '${{ matrix.image.image-name }}:latest'
format: table