-
Notifications
You must be signed in to change notification settings - Fork 0
213 lines (179 loc) · 6.2 KB
/
ci.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
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# SPDX-License-Identifier: MIT
name: CI
on:
push:
branches:
- main
- feature/**
paths-ignore:
- '**.md'
- '.gitignore'
pull_request:
branches:
- main
env:
GORELEASER_VERSION: 1.24.0
TASK_VERSION: 3.x
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
local-build:
name: Local build
runs-on: ubuntu-22.04
permissions: {}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: './go.mod'
- name: Setup Task
uses: arduino/setup-task@v2
with:
version: ${{ env.TASK_VERSION }}
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup GoReleaser
uses: goreleaser/goreleaser-action@v5
with:
install-only: true
- name: Setup container-structure-test
run: |
set -euo pipefail
curl -fsSLo /usr/local/bin/container-structure-test https://storage.googleapis.com/container-structure-test/latest/container-structure-test-linux-amd64
chmod +x /usr/local/bin/container-structure-test
container-structure-test version
- name: Check release config
run: |
task goreleaser:check
- name: Build with GoReleaser
run: |
task goreleaser:build
- name: Create snapshot release
run: |
task goreleaser:snapshot
- name: Build
run: |
task build
- name: Test
run: |
task test
release-dry-run:
name: GoReleaser release (dry run)
runs-on: ubuntu-22.04
permissions:
actions: read
checks: write
contents: read
security-events: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: './go.mod'
- name: Set environment variables
run: |
set -euo pipefail
echo "SNAPSHOT_VERSION=$(./scripts/version)" >>"${GITHUB_ENV}"
IMAGE_BASE_NAME_DISTROLESS="$(sed -n "s/^FROM \(.*\)/\1/p" build/package/Dockerfile | tail -n 1)"
echo "IMAGE_BASE_NAME_DISTROLESS=${IMAGE_BASE_NAME_DISTROLESS}" >>"${GITHUB_ENV}"
echo "IMAGE_BASE_DIGEST_DISTROLESS=$(docker pull "${IMAGE_BASE_NAME_DISTROLESS}" | sed -n "s/^Digest: \(.*\)$/\1/p")" >>"${GITHUB_ENV}"
IMAGE_BASE_NAME_ALPINE="$(sed -n "s/^FROM \(.*\)/\1/p" build/package/Dockerfile.alpine | tail -n 1)"
echo "IMAGE_BASE_NAME_ALPINE=${IMAGE_BASE_NAME_ALPINE}" >>"${GITHUB_ENV}"
echo "IMAGE_BASE_DIGEST_ALPINE=$(docker pull "${IMAGE_BASE_NAME_ALPINE}" | sed -n "s/^Digest: \(.*\)$/\1/p")" >>"${GITHUB_ENV}"
cat "${GITHUB_ENV}"
- name: Check release config
uses: goreleaser/goreleaser-action@v5
with:
version: v${{ env.GORELEASER_VERSION }}
args: check --config build/package/.goreleaser.yaml
- name: Create snapshot release
uses: goreleaser/goreleaser-action@v5
with:
version: v${{ env.GORELEASER_VERSION }}
args: release --config build/package/.goreleaser.yaml --snapshot --skip-publish --clean
- name: Container structure test (scratch)
uses: docker://gcr.io/gcp-runtimes/container-structure-test:latest
with:
args: 'test --image ghcr.io/ffurrer2/semver:latest --config test/semver_container_test.yml'
- name: Container structure test (alpine)
uses: docker://gcr.io/gcp-runtimes/container-structure-test:latest
with:
args: 'test --image ghcr.io/ffurrer2/semver:alpine --config test/semver_alpine_container_test.yml'
- name: Run Trivy vulnerability scanner (scratch)
uses: aquasecurity/trivy-action@master
with:
image-ref: 'ghcr.io/ffurrer2/semver:latest'
exit-code: '1'
vuln-type: 'os,library'
severity: 'HIGH,CRITICAL'
format: 'sarif'
output: 'trivy-results-scratch.sarif'
github-pat: '${{ secrets.GITHUB_TOKEN }}'
- name: Inspect Trivy SARIF report (scratch)
run: |
cat trivy-results-scratch.sarif
- name: Upload Trivy scan results to GitHub Security tab (scratch)
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: 'trivy-results-scratch.sarif'
category: trivy-results-scratch
if: always()
- name: Run Trivy vulnerability scanner (alpine)
uses: aquasecurity/trivy-action@master
with:
image-ref: 'ghcr.io/ffurrer2/semver:alpine'
exit-code: '1'
vuln-type: 'os,library'
severity: 'HIGH,CRITICAL'
format: 'sarif'
output: 'trivy-results-alpine.sarif'
github-pat: '${{ secrets.GITHUB_TOKEN }}'
- name: Inspect Trivy SARIF report (alpine)
run: |
cat trivy-results-alpine.sarif
- name: Upload Trivy scan results to GitHub Security tab (alpine)
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: 'trivy-results-alpine.sarif'
category: trivy-results-alpine
if: always()
- name: Run Anchore image scanner (scratch)
uses: anchore/scan-action@v3
id: anchore-scratch
with:
image: 'ghcr.io/ffurrer2/semver:latest'
fail-build: true
severity-cutoff: high
- name: Inspect Anchore SARIF report (scratch)
run: |
cat ${{ steps.anchore-scratch.outputs.sarif }}
- name: Upload Anchore scan results to GitHub Security tab (scratch)
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: ${{ steps.anchore-scratch.outputs.sarif }}
category: anchore-results-scratch
if: always()
- name: Run Anchore image scanner (alpine)
uses: anchore/scan-action@v3
id: anchore-alpine
with:
image: 'ghcr.io/ffurrer2/semver:alpine'
fail-build: true
severity-cutoff: high
- name: Inspect Anchore SARIF report (alpine)
run: |
cat ${{ steps.anchore-alpine.outputs.sarif }}
- name: Upload Anchore scan results to GitHub Security tab (alpine)
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: ${{ steps.anchore-alpine.outputs.sarif }}
category: anchore-results-alpine
if: always()