Skip to content

Commit aeaf047

Browse files
authored
chore(ci): cache Go modules and build artifacts in CI workflows (#5262)
chore(ci): add Go module and build caching to CI workflows Cache ~/go/pkg/mod and the Go build cache across PR and daily test workflows using actions/[email protected]. Keys include go.mod hash so caches are busted on Go toolchain upgrades, and an environment discriminator (alpine vs graas) to prevent Alpine container jobs and GRAAS AMI jobs from overwriting each other's entries. Also install the zstd package in Alpine deps, which actions/cache relies on for archive compression on Linux.
1 parent 8d4e789 commit aeaf047

File tree

3 files changed

+83
-1
lines changed

3 files changed

+83
-1
lines changed

.github/workflows/pr.yaml

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,15 @@ jobs:
138138
- name: Setup Tracee
139139
uses: ./.github/actions/setup-tracee-alpine
140140

141+
- name: Cache Go modules
142+
uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
143+
with:
144+
path: |
145+
~/go/pkg/mod
146+
~/.cache/go-build
147+
key: ${{ runner.os }}-${{ runner.arch }}-go-alpine-${{ hashFiles('**/go.mod') }}-${{ hashFiles('**/go.sum') }}
148+
restore-keys: ${{ runner.os }}-${{ runner.arch }}-go-alpine-${{ hashFiles('**/go.mod') }}-
149+
141150
- name: Lint
142151
run: |
143152
if test -z "$(gofmt -l .)"; then
@@ -196,6 +205,15 @@ jobs:
196205
- name: Setup Tracee
197206
uses: ./.github/actions/setup-tracee-alpine
198207

208+
- name: Cache Go modules
209+
uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
210+
with:
211+
path: |
212+
~/go/pkg/mod
213+
~/.cache/go-build
214+
key: ${{ runner.os }}-${{ runner.arch }}-go-alpine-${{ hashFiles('**/go.mod') }}-${{ hashFiles('**/go.sum') }}
215+
restore-keys: ${{ runner.os }}-${{ runner.arch }}-go-alpine-${{ hashFiles('**/go.mod') }}-
216+
199217
- name: Build Tracee Benchmark Tool
200218
run: |
201219
make clean
@@ -225,6 +243,15 @@ jobs:
225243
- name: Setup Tracee
226244
uses: ./.github/actions/setup-tracee-alpine
227245

246+
- name: Cache Go modules
247+
uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
248+
with:
249+
path: |
250+
~/go/pkg/mod
251+
~/.cache/go-build
252+
key: ${{ runner.os }}-${{ runner.arch }}-go-alpine-${{ hashFiles('**/go.mod') }}-${{ hashFiles('**/go.sum') }}
253+
restore-keys: ${{ runner.os }}-${{ runner.arch }}-go-alpine-${{ hashFiles('**/go.mod') }}-
254+
228255
- name: Run Unit Tests
229256
uses: ./.github/actions/run-unit-tests
230257

@@ -239,7 +266,7 @@ jobs:
239266
image: alpine/git:2.49.1@sha256:bd54f921f6d803dfa3a4fe14b7defe36df1b71349a3e416547e333aa960f86e3
240267
volumes:
241268
- /opt:/opt:rw,rshared
242-
# The following volume mounts are a workaround for GitHub Actions runner limitations.
269+
# The following volume mounts are a workaround for GitHub Actions runner limitations.
243270
# Some GitHub-hosted runners expect Node.js to be available at /__e/node20 or /__e/node24, which is not present in the base container.
244271
# This mapping provides Node.js from the host's /opt directory to the expected location in the container.
245272
# WARNING: This creates a fragile dependency on the runner's internal filesystem layout.
@@ -265,6 +292,15 @@ jobs:
265292
- name: Setup Tracee
266293
uses: ./.github/actions/setup-tracee-alpine
267294

295+
- name: Cache Go modules
296+
uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
297+
with:
298+
path: |
299+
~/go/pkg/mod
300+
~/.cache/go-build
301+
key: ${{ runner.os }}-${{ runner.arch }}-go-alpine-${{ hashFiles('**/go.mod') }}-${{ hashFiles('**/go.sum') }}
302+
restore-keys: ${{ runner.os }}-${{ runner.arch }}-go-alpine-${{ hashFiles('**/go.mod') }}-
303+
268304
- name: Run Unit Tests
269305
uses: ./.github/actions/run-unit-tests
270306

@@ -321,6 +357,15 @@ jobs:
321357
# - name: Setup Tracee
322358
# uses: ./.github/actions/setup-tracee-ubuntu
323359

360+
- name: Cache Go modules
361+
uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
362+
with:
363+
path: |
364+
${{ env.GOPATH }}/pkg/mod
365+
${{ env.GOCACHE }}
366+
key: ${{ runner.os }}-${{ runner.arch }}-go-graas-${{ hashFiles('**/go.mod') }}-${{ hashFiles('**/go.sum') }}
367+
restore-keys: ${{ runner.os }}-${{ runner.arch }}-go-graas-${{ hashFiles('**/go.mod') }}-
368+
324369
- name: Pull test images
325370
uses: ./.github/actions/pull-test-images
326371

@@ -376,6 +421,15 @@ jobs:
376421
# - name: Setup Tracee
377422
# uses: ./.github/actions/setup-tracee-ubuntu
378423

424+
- name: Cache Go modules
425+
uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
426+
with:
427+
path: |
428+
${{ env.GOPATH }}/pkg/mod
429+
${{ env.GOCACHE }}
430+
key: ${{ runner.os }}-${{ runner.arch }}-go-graas-${{ hashFiles('**/go.mod') }}-${{ hashFiles('**/go.sum') }}
431+
restore-keys: ${{ runner.os }}-${{ runner.arch }}-go-graas-${{ hashFiles('**/go.mod') }}-
432+
379433
- name: Pull test images
380434
uses: ./.github/actions/pull-test-images
381435

@@ -406,6 +460,15 @@ jobs:
406460
- name: Setup Tracee
407461
uses: ./.github/actions/setup-tracee-alpine
408462

463+
- name: Cache Go modules
464+
uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
465+
with:
466+
path: |
467+
~/go/pkg/mod
468+
~/.cache/go-build
469+
key: ${{ runner.os }}-${{ runner.arch }}-go-alpine-${{ hashFiles('**/go.mod') }}-${{ hashFiles('**/go.sum') }}
470+
restore-keys: ${{ runner.os }}-${{ runner.arch }}-go-alpine-${{ hashFiles('**/go.mod') }}-
471+
409472
- name: Run Performance Tests
410473
run: |
411474
make test-performance
@@ -461,6 +524,15 @@ jobs:
461524
submodules: true
462525
ref: ${{ env.TRACEE_REF }}
463526

527+
- name: Cache Go modules
528+
uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
529+
with:
530+
path: |
531+
${{ env.GOPATH }}/pkg/mod
532+
${{ env.GOCACHE }}
533+
key: ${{ runner.os }}-${{ runner.arch }}-go-graas-${{ hashFiles('**/go.mod') }}-${{ hashFiles('**/go.sum') }}
534+
restore-keys: ${{ runner.os }}-${{ runner.arch }}-go-graas-${{ hashFiles('**/go.mod') }}-
535+
464536
- name: "System Info"
465537
run: ./scripts/system-info.sh --all
466538

.github/workflows/test-upstream-libbpfgo.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@ jobs:
3333
- name: Setup Tracee
3434
uses: ./.github/actions/setup-tracee-alpine
3535

36+
- name: Cache Go modules
37+
uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
38+
with:
39+
path: |
40+
~/go/pkg/mod
41+
~/.cache/go-build
42+
key: ${{ runner.os }}-${{ runner.arch }}-go-alpine-${{ hashFiles('**/go.mod') }}-${{ hashFiles('**/go.sum') }}
43+
restore-keys: ${{ runner.os }}-${{ runner.arch }}-go-alpine-${{ hashFiles('**/go.mod') }}-
44+
3645
- name: Compile Tracee
3746
run: make test-upstream-libbpfgo
3847
shell: sh

scripts/installation/install-deps-alpine.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ install_base_packages() {
3333
elfutils-dev \
3434
libelf-static \
3535
zlib-static \
36+
zstd \
3637
zstd-static \
3738
libc6-compat \
3839
tar \

0 commit comments

Comments
 (0)