Skip to content

Commit 74f8572

Browse files
authored
chore: fix github bazel cache (#445)
GitHub's actions cache appears to be empty, even with recent pushes to main. This config has been working well in Google's github.com/GoogleCloudPlatform/service-extensions repo, which should be building all the same things as this repo. Using --disk_cache avoids putting a bunch of junk in the cache that the previous xdg cache dir entry had to manually strip out. Signed-off-by: Matt Leon <mattleon@google.com>
1 parent 1000bc2 commit 74f8572

File tree

2 files changed

+80
-97
lines changed

2 files changed

+80
-97
lines changed

‎.github/workflows/format.yml

Lines changed: 27 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -125,49 +125,40 @@ jobs:
125125
- name: Install dependencies (Linux)
126126
run: sudo apt update -y && sudo apt install -y clang-tidy-18 lld-18 && sudo ln -sf /usr/bin/lld-18 /usr/bin/lld
127127

128-
- name: Bazel cache
129-
uses: PiotrSikora/cache@v2.1.7-with-skip-cache
128+
- name: set cache name
129+
id: vars
130+
# The cache tag consists of the following parts:
131+
# * clang-tidy- prefix
132+
# * matrix.name, which separates the cache for each build type.
133+
# * hash of WORKSPACE, .bazelrc, and .bazelversion, which is
134+
# purely to differentiate caches for substantial changes in bazel.
135+
# * github.sha, which is the commit hash of the commit used to generate
136+
# the cache entry.
137+
run: echo "CACHE_TAG=clang-tidy-${{ matrix.name }}-${{ hashFiles('WORKSPACE', '.bazelrc', '.bazelversion') }}" >> "$GITHUB_OUTPUT"
138+
139+
- name: bazel cache
140+
uses: actions/cache/restore@v3
130141
with:
131-
path: |
132-
~/.cache/bazel
133-
key: clang_tidy-${{ hashFiles('WORKSPACE', '.bazelrc', '.bazelversion', 'bazel/dependencies.bzl', 'bazel/repositories.bzl', 'bazel/cargo/wasmsign/remote/crates.bzl') }}
142+
path: /tmp/bazel/cache
143+
key: ${{ steps.vars.outputs.CACHE_TAG }}-${{ github.sha }}
144+
restore-keys: |
145+
${{ steps.vars.outputs.CACHE_TAG }}-${{ github.sha }}
146+
${{ steps.vars.outputs.CACHE_TAG }}-
147+
clang-tidy-${{ matrix.name }}-
148+
clang-tidy-
134149
135150
- name: Bazel build
136151
run: >
137152
bazel build
138153
--config clang-tidy
139154
--define engine=multi
155+
--disk_cache /tmp/bazel/cache
140156
--copt=-DPROXY_WASM_VERIFY_WITH_ED25519_PUBKEY=\"$(xxd -p -c 256 test/test_data/signature_key1.pub | cut -b9-)\"
141157
//...
142158
143-
- name: Skip Bazel cache update
144-
if: ${{ github.ref != 'refs/heads/main' }}
145-
run: echo "CACHE_SKIP_SAVE=true" >> $GITHUB_ENV
146-
147-
- name: Cleanup Bazel cache
148-
if: ${{ github.ref == 'refs/heads/main' }}
149-
run: |
150-
export OUTPUT=$(${{ matrix.run_under }} bazel info output_base)
151-
echo "===== BEFORE ====="
152-
du -s ${OUTPUT}/external/* $(dirname ${OUTPUT})/* | sort -rn | head -20
153-
# BoringSSL's test data (90 MiB).
154-
rm -rf ${OUTPUT}/external/boringssl/crypto_test_data.cc
155-
rm -rf ${OUTPUT}/external/boringssl/src/crypto/*/test/
156-
rm -rf ${OUTPUT}/external/boringssl/src/third_party/wycheproof_testvectors/
157-
# LLVM's tests (500 MiB).
158-
rm -rf ${OUTPUT}/external/llvm*/test/
159-
# V8's tests (100 MiB).
160-
if [ -d "${OUTPUT}/external/v8/test/torque" ]; then
161-
mv ${OUTPUT}/external/v8/test/torque ${OUTPUT}/external/v8/test_torque
162-
rm -rf ${OUTPUT}/external/v8/test/*
163-
mv ${OUTPUT}/external/v8/test_torque ${OUTPUT}/external/v8/test/torque
164-
fi
165-
# Unnecessary CMake tools (65 MiB).
166-
rm -rf ${OUTPUT}/external/cmake-*/bin/{ccmake,cmake-gui,cpack,ctest}
167-
# Distfiles for Rust toolchains (350 MiB).
168-
rm -rf ${OUTPUT}/external/rust_*/*.tar.gz
169-
# Bazel's repository cache (650-800 MiB) and install base (155 MiB).
170-
rm -rf ${OUTPUT}/../cache
171-
rm -rf ${OUTPUT}/../install
172-
echo "===== AFTER ====="
173-
du -s ${OUTPUT}/external/* $(dirname ${OUTPUT})/* | sort -rn | head -20
159+
- name: save bazel cache
160+
uses: actions/cache/save@v3
161+
if: always()
162+
with:
163+
path: /tmp/bazel/cache
164+
key: ${{ steps.vars.outputs.CACHE_TAG }}-${{ github.sha }}

‎.github/workflows/test.yml

Lines changed: 53 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,34 @@ jobs:
4848
steps:
4949
- uses: actions/checkout@v2
5050

51-
- name: Bazel cache
52-
uses: PiotrSikora/cache@v2.1.7-with-skip-cache
51+
- name: set cache name
52+
id: vars
53+
# The cache tag consists of the following parts:
54+
# * test-deps-bazel-cache- prefix
55+
# * hash of WORKSPACE, .bazelrc, and .bazelversion, which is
56+
# purely to differentiate caches for substantial changes in bazel.
57+
# * github.sha, which is the commit hash of the commit used to generate
58+
# the cache entry.
59+
run: echo "CACHE_TAG=test-deps-bazel-cache-${{ hashFiles('WORKSPACE', '.bazelrc', '.bazelversion') }}" >> "$GITHUB_OUTPUT"
60+
61+
- name: bazel cache
62+
uses: actions/cache/restore@v3
5363
with:
54-
path: |
55-
~/.cache/bazel
56-
key: test_data-${{ hashFiles('WORKSPACE', '.bazelrc', '.bazelversion', 'bazel/dependencies.bzl', 'bazel/repositories.bzl', 'bazel/cargo/wasmsign/crates.bzl') }}
64+
path: /tmp/bazel/cache
65+
key: ${{ steps.vars.outputs.CACHE_TAG }}-${{ github.sha }}
66+
restore-keys: |
67+
${{ steps.vars.outputs.CACHE_TAG }}-${{ github.sha }}
68+
${{ steps.vars.outputs.CACHE_TAG }}-
69+
test-deps-bazel-cache-${{ matrix.name }}-
70+
test-deps-bazel-cache-
5771
5872
- name: Bazel build
5973
run: >
6074
bazel build
6175
--verbose_failures
6276
--test_output=errors
6377
--config=clang
78+
--disk_cache /tmp/bazel/cache
6479
-c opt
6580
$(bazel query 'kind(was.*_rust_binary, //test/test_data/...)')
6681
$(bazel query 'kind(_optimized_wasm_cc_binary, //test/test_data/...)')
@@ -84,19 +99,12 @@ jobs:
8499
if-no-files-found: error
85100
retention-days: 3
86101

87-
- name: Skip Bazel cache update
88-
if: ${{ github.ref != 'refs/heads/main' }}
89-
run: echo "CACHE_SKIP_SAVE=true" >> $GITHUB_ENV
90-
91-
- name: Cleanup Bazel cache
92-
if: ${{ github.ref == 'refs/heads/main' }}
93-
run: |
94-
export OUTPUT=$(bazel info output_base)
95-
# Distfiles for Rust toolchains (350 MiB).
96-
rm -rf ${OUTPUT}/external/rust_*/*.tar.gz
97-
# Bazel's repository cache (650-800 MiB) and install base (155 MiB).
98-
rm -rf $(bazel info repository_cache)
99-
rm -rf $(bazel info install_base)
102+
- name: save bazel cache
103+
uses: actions/cache/save@v3
104+
if: always()
105+
with:
106+
path: /tmp/bazel/cache
107+
key: ${{ steps.vars.outputs.CACHE_TAG }}-${{ github.sha }}
100108

101109
build:
102110
name: ${{ matrix.action }} with ${{ matrix.name }}
@@ -282,21 +290,27 @@ jobs:
282290
if: startsWith(matrix.run_under, 'docker')
283291
run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
284292

285-
- name: Set cache key
286-
if: ${{ matrix.cache }}
287-
run: echo "::set-output name=uniq::$(bazel query --output build //external:${{ matrix.repo }} | grep -E 'sha256|commit' | cut -d\" -f2)-$(echo ${{ matrix.flags }} | sha256sum)"
288-
id: cache-key
289-
290-
- name: Bazel cache
291-
if: ${{ matrix.cache }}
292-
uses: PiotrSikora/cache@v2.1.7-with-skip-cache
293+
- name: set cache name
294+
id: vars
295+
# The cache tag consists of the following parts:
296+
# * bazel-cache- prefix
297+
# * matrix.name, which separates the cache for each build type.
298+
# * hash of WORKSPACE, .bazelrc, and .bazelversion, which is
299+
# purely to differentiate caches for substantial changes in bazel.
300+
# * github.sha, which is the commit hash of the commit used to generate
301+
# the cache entry.
302+
run: echo "CACHE_TAG=bazel-cache-${{ matrix.name }}-${{ hashFiles('WORKSPACE', '.bazelrc', '.bazelversion') }}" >> "$GITHUB_OUTPUT"
303+
304+
- name: bazel cache
305+
uses: actions/cache/restore@v3
293306
with:
294-
path: |
295-
~/.cache/bazel
296-
/private/var/tmp/_bazel_runner/
297-
key: ${{ matrix.arch }}-${{ matrix.os }}-${{ matrix.engine }}-${{ steps.cache-key.outputs.uniq }}-${{ hashFiles('WORKSPACE', '.bazelrc', '.bazelversion', 'bazel/dependencies.bzl', 'bazel/repositories.bzl') }}
307+
path: /tmp/bazel/cache
308+
key: ${{ steps.vars.outputs.CACHE_TAG }}-${{ github.sha }}
298309
restore-keys: |
299-
${{ matrix.arch }}-${{ matrix.os }}-${{ matrix.engine }}-${{ steps.cache-key.outputs.uniq }}-
310+
${{ steps.vars.outputs.CACHE_TAG }}-${{ github.sha }}
311+
${{ steps.vars.outputs.CACHE_TAG }}-
312+
bazel-cache-${{ matrix.name }}-
313+
bazel-cache-
300314
301315
- name: Download test data
302316
uses: actions/download-artifact@v4
@@ -321,6 +335,7 @@ jobs:
321335
--verbose_failures
322336
--test_output=errors
323337
--define engine=${{ matrix.engine }}
338+
--disk_cache /tmp/bazel/cache
324339
${{ matrix.flags }}
325340
-- //test/... ${{ matrix.targets }}
326341
@@ -332,38 +347,15 @@ jobs:
332347
--verbose_failures
333348
--test_output=errors
334349
--define engine=${{ matrix.engine }}
350+
--disk_cache /tmp/bazel/cache
335351
${{ matrix.flags }}
336352
--per_file_copt=src/signature_util.cc,test/signature_util_test.cc@-DPROXY_WASM_VERIFY_WITH_ED25519_PUBKEY=\"$(xxd -p -c 256 test/test_data/signature_key1.pub | cut -b9-)\"
337353
//test:signature_util_test
338354
339-
- name: Skip Bazel cache update
340-
if: ${{ matrix.cache && github.ref != 'refs/heads/main' }}
341-
run: echo "CACHE_SKIP_SAVE=true" >> $GITHUB_ENV
355+
- name: save bazel cache
356+
uses: actions/cache/save@v3
357+
if: always()
358+
with:
359+
path: /tmp/bazel/cache
360+
key: ${{ steps.vars.outputs.CACHE_TAG }}-${{ github.sha }}
342361

343-
- name: Cleanup Bazel cache
344-
if: ${{ matrix.cache && github.ref == 'refs/heads/main' }}
345-
run: |
346-
export OUTPUT=$(${{ matrix.run_under }} bazel info output_base)
347-
echo "===== BEFORE ====="
348-
du -s ${OUTPUT}/external/* $(dirname ${OUTPUT})/* | sort -rn | head -20
349-
# BoringSSL's test data (90 MiB).
350-
rm -rf ${OUTPUT}/external/boringssl/crypto_test_data.cc
351-
rm -rf ${OUTPUT}/external/boringssl/src/crypto/*/test/
352-
rm -rf ${OUTPUT}/external/boringssl/src/third_party/wycheproof_testvectors/
353-
# LLVM's tests (500 MiB).
354-
rm -rf ${OUTPUT}/external/llvm*/test/
355-
# V8's tests (100 MiB).
356-
if [ -d "${OUTPUT}/external/v8/test/torque" ]; then
357-
mv ${OUTPUT}/external/v8/test/torque ${OUTPUT}/external/v8/test_torque
358-
rm -rf ${OUTPUT}/external/v8/test/*
359-
mv ${OUTPUT}/external/v8/test_torque ${OUTPUT}/external/v8/test/torque
360-
fi
361-
# Unnecessary CMake tools (65 MiB).
362-
rm -rf ${OUTPUT}/external/cmake-*/bin/{ccmake,cmake-gui,cpack,ctest}
363-
# Distfiles for Rust toolchains (350 MiB).
364-
rm -rf ${OUTPUT}/external/rust_*/*.tar.gz
365-
# Bazel's repository cache (650-800 MiB) and install base (155 MiB).
366-
rm -rf ${OUTPUT}/../cache
367-
rm -rf ${OUTPUT}/../install
368-
echo "===== AFTER ====="
369-
du -s ${OUTPUT}/external/* $(dirname ${OUTPUT})/* | sort -rn | head -20

0 commit comments

Comments
 (0)