Bazel Cache for GitHub Actions #3016
Replies: 5 comments 2 replies
-
Option comparison
Legend: ✅ supported · fetch all: |
Beta Was this translation helpful? Give feedback.
-
|
Meeting with @lurtz @AlexanderLanin @nradakovic Problem:
Discussion:
|
Beta Was this translation helpful? Give feedback.
-
flowchart TD
%% Dark-mode friendly styling
classDef trigger fill:#102a43,stroke:#63b3ed,color:#e6f6ff,stroke-width:2px
classDef action fill:#3a2a00,stroke:#f6ad55,color:#fff7e6,stroke-width:2px
classDef cache fill:#123524,stroke:#68d391,color:#e6fffa,stroke-width:2px
classDef ci fill:#271a45,stroke:#b794f4,color:#f5f0ff,stroke-width:2px
classDef event fill:#1f2933,stroke:#cbd5e1,color:#f8fafc,stroke-dasharray: 5 5
subgraph Repository Cache
A["<trigger><br>Push to main<br/>on file *.bazel*, .*bazelrc*, .bazelversion, **/*.bzl etc"]
A --> B["Rebuild repository cache<br/><br/>bazel fetch //... --config=linux<br/>bazel fetch //... --config=qnx<br/>..."]
B --> C["Upload and replace<br/>repository cache"]
C --> D[("GitHub Actions Cache<br/>Repository Cache")]
end
subgraph Disk Cache
M["<trigger><br>Scheduled maintenance<br/>nightly"]
M --> N["Delete disk cache<br/><br/>reduce disk cache size"]
N --> O["Rebuild disk cache"]
O --> OO["Upload and replace<br/>disk cache"]
OO --> DC[("GitHub Actions Cache<br/>Disk Cache")]
end
D --> P{{"Pull Request CI"}}
DC --> P
P --> UD["Build / test<br/>upload growing disk cache"]
UD --> DC
UD --> MM(["Merge to main"])
MM -.-> A
MM -.-> M
class A,M trigger
class B,C,N,O,OO,UD action
class D,DC cache
class P ci
class MM event
|
Beta Was this translation helpful? Give feedback.
-
|
I start to wonder about https://github.com/bazel-contrib/setup-bazel#repository-cache The description sounds like it behaves as we want it to if we give the the right files to calculate the hash sum if the default is not sufficient. Now I wonder why the repository cache grew so big in the past. |
Beta Was this translation helpful? Give feedback.
-
|
I branched off @castler The behavior of setup-bazel is now as follows:
I now have a working workflow: https://github.com/lurtz/inc_someip_gateway/actions/workflows/cache_maintenance.yml This combined with the modified As such there are still some rough edges:
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
What a Bazel Cache Solution for GitHub Actions Must Achieve
Before discussing implementation details, we should agree on the problems the solution needs to solve.
A successful solution should:
1. Cover all relevant Bazel caches
Caching only part of Bazel's data is insufficient. The solution must support both the disk cache and the repository cache.
2. Work with parallel CI execution
Our CI executes multiple jobs in parallel. The solution must ensure that cache data produced by different jobs can be reused effectively and that repository cache contents are not lost simply because they were overwritten by another job.
3. Stay within GitHub cache limits
GitHub cache storage is a limited resource. The solution must operate within the current 50 GB limit and should ideally target roughly 10 GB per repository.
4. Avoid wasting CI time
Caching should reduce CI execution time. Uploading and downloading cache data should not cost more time than the cache saves. Unnecessary cache re-uploads should be avoided.
5. Prioritize important branches
Long-lived branches such as
mainandrelease/*branches should benefit from stable caches. Short-lived branches and pull requests must not reduce cache availability for important branches. It is acceptable not to cache pull requests at all.Note: only relevant if we ever develop multiple versions at the same time.
6. Require no manual maintenance
Once configured, the solution should run fully automatically. Repository maintainers should not need to manually clean caches, rotate cache keys, or perform other routine maintenance tasks.
7. Be simple to adopt
The solution should be easy to understand and easy to use. Repository maintainers should not need deep Bazel or GitHub Actions cache expertise to benefit from it.
Beta Was this translation helpful? Give feedback.
All reactions