Repository navigation
417 lines (361 loc) · 12.5 KB
/
Copy pathci.yml
File metadata and controls
417 lines (361 loc) · 12.5 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
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
name: CI
on:
push:
branches:
- main
pull_request:
merge_group:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
jobs:
# Graphite CI optimization: skip redundant CI runs for stacked PRs.
# See https://graphite.com/docs/stacking-and-ci
optimize_ci:
runs-on: ubuntu-latest
continue-on-error: true
outputs:
skip: ${{ steps.check_skip.outputs.skip }}
steps:
- name: Optimize CI
id: check_skip
uses: withgraphite/graphite-ci-action@26bc0dcdeaba101794931d67a464ecbb21a76a8b # v0.0.9 tag (no formal releases)
with:
graphite_token: ${{ secrets.GRAPHITE_CI_OPTIMIZER_TOKEN }}
# Detect which files changed so PRs skip irrelevant jobs. For merge_group and
# push events every filter defaults to 'true', so the merge queue and post-merge
# always run the full suite (a stale generated artifact must never merge because
# its check was skipped, as happened when the library subcommands merged).
detect-changes:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: read
outputs:
go: ${{ github.event_name != 'pull_request' || steps.filter.outputs.go == 'true' || steps.filter.outputs.ci == 'true' }}
scripts: ${{ github.event_name != 'pull_request' || steps.filter.outputs.scripts == 'true' || steps.filter.outputs.ci == 'true' }}
steps:
- name: Checkout (needed for non-PR events)
if: github.event_name != 'pull_request'
uses: actions/checkout@v7
- name: Detect changed files
uses: dorny/paths-filter@v4
id: filter
with:
filters: |
ci:
- '.github/workflows/ci.yml'
- '.github/scripts/**'
go:
- '**/*.go'
- 'go.mod'
- 'go.sum'
- 'Makefile'
- '.goreleaser*.yaml'
- 'resources/**'
- 'package/**'
- 'config/**'
- 'weaver/**'
- 'generator/**/data_library/**'
scripts:
- 'scripts/**'
- 'package/scripts/**'
- '.github/scripts/**'
shellcheck:
name: ShellCheck
runs-on: ubuntu-latest
needs: [optimize_ci, detect-changes]
if: ${{ needs.optimize_ci.outputs.skip != 'true' && needs.detect-changes.outputs.scripts == 'true' }}
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Run ShellCheck (package/scripts)
run: |
find package/scripts -type f -name "*.sh" -exec shellcheck {} +
- name: Run ShellCheck (scripts)
run: |
find scripts -type f -name "*.sh" -exec shellcheck {} +
setup:
name: Setup environment
runs-on: ubuntu-latest
needs: [optimize_ci, detect-changes]
if: ${{ needs.optimize_ci.outputs.skip != 'true' && needs.detect-changes.outputs.go == 'true' }}
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Setup Go
uses: actions/setup-go@v7
with:
go-version-file: go.mod
cache: true
- name: Download dependencies
run: |
go env
bash .github/scripts/retry.sh go mod download
- name: Install tools
run: |
bash .github/scripts/retry.sh make install-tools
test:
name: Test
runs-on: ubuntu-latest
needs: [optimize_ci, detect-changes, setup]
if: ${{ needs.optimize_ci.outputs.skip != 'true' && needs.detect-changes.outputs.go == 'true' }}
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Setup Go
uses: actions/setup-go@v7
with:
go-version-file: go.mod
cache: true
- name: Run tests (race detector)
env:
CGO_ENABLED: "1"
run: |
make test-race
- name: Run embedded-library tests
run: |
make test-embedded
gosec:
name: Gosec
runs-on: ubuntu-latest
needs: [optimize_ci, detect-changes, setup]
if: ${{ needs.optimize_ci.outputs.skip != 'true' && needs.detect-changes.outputs.go == 'true' }}
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Setup Go
uses: actions/setup-go@v7
with:
go-version-file: go.mod
cache: true
- name: Run gosec
run: |
make security
revive:
name: Revive
runs-on: ubuntu-latest
needs: [optimize_ci, detect-changes, setup]
if: ${{ needs.optimize_ci.outputs.skip != 'true' && needs.detect-changes.outputs.go == 'true' }}
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Setup Go
uses: actions/setup-go@v7
with:
go-version-file: go.mod
cache: true
- name: Run revive
run: |
make lint
- name: Check for global-logger usage
run: |
make lint-global-logger
build:
name: Build - ${{ matrix.goos }}/${{ matrix.goarch }}
runs-on: ubuntu-latest
needs: [optimize_ci, detect-changes, setup]
if: ${{ needs.optimize_ci.outputs.skip != 'true' && needs.detect-changes.outputs.go == 'true' }}
strategy:
fail-fast: false
matrix:
include:
- goos: freebsd
goarch: amd64
- goos: freebsd
goarch: arm64
- goos: linux
goarch: amd64
- goos: linux
goarch: arm64
- goos: darwin
goarch: amd64
- goos: darwin
goarch: arm64
- goos: windows
goarch: amd64
- goos: windows
goarch: arm64
steps:
- name: Checkout
uses: actions/checkout@v7
# Only the linux legs build container images (the goreleaser dockers are
# linux/amd64 and linux/arm64), so QEMU/buildx are set up only there. The
# freebsd/darwin/windows legs cross-compile binaries only, so they no
# longer pull from Docker Hub at all, which removes the transient-pull
# failure they used to hit (PIPE-1092). On the linux legs the QEMU and
# buildkit images are pre-pulled with retry and pinned, so a transient
# Docker Hub blip during setup no longer fails the build.
- name: Pre-pull buildx base images (retry transient Docker Hub pulls)
if: matrix.goos == 'linux'
run: |
bash .github/scripts/retry.sh docker pull tonistiigi/binfmt:latest
bash .github/scripts/retry.sh docker pull moby/buildkit:buildx-stable-1
- name: Set up Docker Buildx
if: matrix.goos == 'linux'
id: buildx
uses: docker/setup-buildx-action@v4
with:
driver-opts: image=moby/buildkit:buildx-stable-1
- name: Set up QEMU
if: matrix.goos == 'linux'
uses: docker/setup-qemu-action@v4
with:
image: tonistiigi/binfmt:latest
- name: Setup Go
uses: actions/setup-go@v7
with:
go-version-file: go.mod
cache: true
- name: Set build host platform
run: |
echo "BUILD_HOST_OS=$(go env GOHOSTOS)" >> $GITHUB_ENV
echo "BUILD_HOST_ARCH=$(go env GOHOSTARCH)" >> $GITHUB_ENV
- name: Run GoReleaser (split)
uses: goreleaser/goreleaser-action@v7
with:
distribution: goreleaser-pro
version: "v2.12.5"
args: release --clean --skip=publish --skip=sign --skip=validate --snapshot --split
env:
GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }}
BUILD_HOST_OS: ${{ env.BUILD_HOST_OS }}
BUILD_HOST_ARCH: ${{ env.BUILD_HOST_ARCH }}
GGOOS: ${{ matrix.goos }}
GGOARCH: ${{ matrix.goarch }}
- name: Upload dist artifacts
uses: actions/upload-artifact@v7
with:
name: dist-${{ matrix.goos }}-${{ matrix.goarch }}
path: dist/
retention-days: 1
merge-build:
name: Merge Build
runs-on: ubuntu-latest
needs: [optimize_ci, detect-changes, setup, build]
if: ${{ needs.optimize_ci.outputs.skip != 'true' && needs.detect-changes.outputs.go == 'true' }}
env:
cinc_package: https://packages.cinc.sh/files/stable/cinc-auditor/4.56.58/ubuntu/22.04/cinc-auditor_4.56.58-1_amd64.deb
steps:
- name: Checkout
uses: actions/checkout@v7
# Pre-pull the QEMU/buildkit images with retry so a transient Docker Hub
# blip during buildx/QEMU setup doesn't fail the merge build (PIPE-1092).
# The images are pinned to match what the setup actions request below.
- name: Pre-pull buildx base images (retry transient Docker Hub pulls)
run: |
bash .github/scripts/retry.sh docker pull tonistiigi/binfmt:latest
bash .github/scripts/retry.sh docker pull moby/buildkit:buildx-stable-1
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v4
with:
driver-opts: image=moby/buildkit:buildx-stable-1
- name: Set up QEMU
uses: docker/setup-qemu-action@v4
with:
image: tonistiigi/binfmt:latest
- name: Setup Go
uses: actions/setup-go@v7
with:
go-version-file: go.mod
cache: true
- name: Set build host platform
run: |
echo "BUILD_HOST_OS=$(go env GOHOSTOS)" >> $GITHUB_ENV
echo "BUILD_HOST_ARCH=$(go env GOHOSTARCH)" >> $GITHUB_ENV
- name: Download dist artifacts
uses: actions/download-artifact@v8
with:
pattern: dist-*
merge-multiple: true
path: dist/
- name: Run GoReleaser (merge)
uses: goreleaser/goreleaser-action@v7
with:
distribution: goreleaser-pro
version: "v2.12.5"
args: continue --merge --skip=publish --skip=sign --skip=validate
env:
GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }}
BUILD_HOST_OS: ${{ env.BUILD_HOST_OS }}
BUILD_HOST_ARCH: ${{ env.BUILD_HOST_ARCH }}
- name: Prepare CINC directory
run: mkdir -p /tmp/cinc
- name: Cache CINC package
id: cache-cinc
uses: actions/cache@v6
with:
path: /tmp/cinc/cinc.deb
key: cinc-auditor-4.56.58
- name: Download CINC (Inspec)
if: steps.cache-cinc.outputs.cache-hit != 'true'
run: |
curl -fsSL --retry 3 --retry-delay 5 --retry-connrefused -o /tmp/cinc/cinc.deb "$cinc_package"
- name: Install CINC
run: |
sudo apt-get -o Acquire::Retries=3 update
sudo apt-get -o Acquire::Retries=3 install -y -f /tmp/cinc/cinc.deb
- name: Install package
run: sudo apt-get install -y -f ./dist/linux_amd64/blitz_amd64.deb
- name: Start service
run: sudo systemctl start blitz
- name: Run install tests
run: |
sudo cinc-auditor exec package/inspec/install/package.rb
- name: Uninstall package
run: |
sudo apt-get remove -y blitz
- name: Run uninstall tests
run: |
sudo cinc-auditor exec package/inspec/remove/package.rb
man-check:
name: Man pages
runs-on: ubuntu-latest
needs: [optimize_ci, detect-changes, setup]
if: ${{ needs.optimize_ci.outputs.skip != 'true' && needs.detect-changes.outputs.go == 'true' }}
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Setup Go
uses: actions/setup-go@v7
with:
go-version-file: go.mod
cache: true
- name: Generate and verify man pages
run: |
make man-check
completion-check:
name: Shell completion (bash, zsh)
runs-on: ubuntu-latest
needs: [optimize_ci, detect-changes, setup]
if: ${{ needs.optimize_ci.outputs.skip != 'true' && needs.detect-changes.outputs.go == 'true' }}
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Setup Go
uses: actions/setup-go@v7
with:
go-version-file: go.mod
cache: true
- name: Generate and verify completion scripts
run: |
make completion-check
generate-o11y-check:
name: Generated metrics
runs-on: ubuntu-latest
needs: [optimize_ci, detect-changes, setup]
if: ${{ needs.optimize_ci.outputs.skip != 'true' && needs.detect-changes.outputs.go == 'true' }}
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Setup Go
uses: actions/setup-go@v7
with:
go-version-file: go.mod
cache: true
- name: Generate and verify metric code
run: |
make generate-o11y-check