diff --git a/.github/workflows/test-setup-bazel-cache.yml b/.github/workflows/test-setup-bazel-cache.yml index 40cefce..a39552b 100644 --- a/.github/workflows/test-setup-bazel-cache.yml +++ b/.github/workflows/test-setup-bazel-cache.yml @@ -50,6 +50,13 @@ jobs: with: unique-cache-name: ${{ github.workflow }}-${{ github.job }} + - name: Print ~/.bazelrc + shell: bash + run: | + set -euo pipefail + echo "~/.bazelrc contents:" + cat "${HOME}/.bazelrc" + - name: Verify ~/.bazelrc was written by action with cache configuration shell: bash run: | @@ -70,8 +77,20 @@ jobs: exit 1 fi - echo "~/.bazelrc contents:" - cat "${HOME}/.bazelrc" + if ! grep -Fq -- "--experimental_disk_cache_gc_max_age=" "${HOME}/.bazelrc"; then + echo "ERROR: ~/.bazelrc does not contain experimental_disk_cache_gc_max_age configuration" + exit 1 + fi + + if ! grep -Fq -- "--experimental_disk_cache_gc_max_size=" "${HOME}/.bazelrc"; then + echo "ERROR: ~/.bazelrc does not contain experimental_disk_cache_gc_max_size configuration" + exit 1 + fi + + if ! grep -Fq -- "--experimental_disk_cache_gc_idle_delay=" "${HOME}/.bazelrc"; then + echo "ERROR: ~/.bazelrc does not contain experimental_disk_cache_gc_idle_delay configuration" + exit 1 + fi - name: Run bazel info to verify workspace and cache configuration are valid shell: bash diff --git a/setup-bazel-cache/README.md b/setup-bazel-cache/README.md index d3e55c8..58c5095 100644 --- a/setup-bazel-cache/README.md +++ b/setup-bazel-cache/README.md @@ -8,10 +8,20 @@ Bazel builds can be slow. Caching helps — but only if the cache is set up corr steps: - uses: eclipse-score/cicd-actions/setup-bazel-cache@ with: - unique-cache-name: ${{ github.workflow }}-${{ github.job }} [-matrix-uid] + unique-cache-name: [${{ github.workflow }}-]${{ github.job }}[-] + # Optional parameters with default values: + main-branch: main + disk_cache_gc_max_size: 5G ``` -Using `github.workflow` and `github.job` together gives each job its own cache automatically. Append a matrix identifier if the same job runs with different configurations that produce different build outputs. +Parameters: + +- unique-cache-name: A unique name for the cache. This is required to avoid conflicts between different jobs and workflows. + Using `github.workflow` and `github.job` together gives each job its own cache automatically. + Append a matrix identifier if the same job runs with different configurations that produce different build outputs. + Omit `github.workflow` if you use `workflow_call` triggers and want to avoid nesting caches under the caller's workflow name. +- main-branch: The branch that is allowed to save the cache. Override if your default branch has a different name. +- disk_cache_gc_max_size: Maximum size of the Bazel disk cache. Set to 0 for unlimited. ## Required permissions diff --git a/setup-bazel-cache/action.yml b/setup-bazel-cache/action.yml index 3c3ec0e..e541da8 100644 --- a/setup-bazel-cache/action.yml +++ b/setup-bazel-cache/action.yml @@ -24,6 +24,11 @@ inputs: required: false default: "main" + disk_cache_gc_max_size: + description: Maximum size of the Bazel disk cache. Set to 0 for unlimited. Default is 5G, which is big enough for a standard build of communication (uses 3.6GB). + required: false + default: "5G" + # Non stable API, subject to change without deprecation. Not intended for public use. _bazelisk_cache: description: For debugging purposes only. @@ -60,3 +65,12 @@ runs: repository-cache: ${{ inputs._repository_cache }} # true cache-optimized: ${{ inputs._cache_optimized }} # true external-cache: ${{ inputs._external_cache }} # false + + - name: Setup Bazel Cache + shell: bash + run: | + echo "Bazel Cache: Configuring Bazel disk cache retention time (60 days)..." + echo "common --experimental_disk_cache_gc_max_age=60d" >> ~/.bazelrc + echo "Bazel Cache: Configuring Bazel disk cache max size (${{ inputs.disk_cache_gc_max_size }})..." + echo "common --experimental_disk_cache_gc_max_size=${{ inputs.disk_cache_gc_max_size }}" >> ~/.bazelrc + echo "common --experimental_disk_cache_gc_idle_delay=0m" >> ~/.bazelrc