Skip to content

armgit / codex

Public Imported from GitHub
0

Lightweight coding agent that runs in your terminal

Rust

Preserve bazel repository cache in github actions (#14495)

Siggi Simonarsonc264c6eef975
diff --git a/.github/workflows/bazel.yml b/.github/workflows/bazel.yml
index b2ef107ca7..0497cd54ea 100644
--- a/.github/workflows/bazel.yml
+++ b/.github/workflows/bazel.yml
@@ -78,30 +78,17 @@ jobs:
shell: bash
run: ./scripts/check-module-bazel-lock.sh
- # TODO(mbolin): Bring this back once we have caching working. Currently,
- # we never seem to get a cache hit but we still end up paying the cost of
- # uploading at the end of the build, which takes over a minute!
- #
- # Cache build and external artifacts so that the next ci build is incremental.
- # Because github action caches cannot be updated after a build, we need to
- # store the contents of each build in a unique cache key, then fall back to loading
- # it on the next ci run. We use hashFiles(...) in the key and restore-keys- with
- # the prefix to load the most recent cache for the branch on a cache miss. You
- # should customize the contents of hashFiles to capture any bazel input sources,
- # although this doesn't need to be perfect. If none of the input sources change
- # then a cache hit will load an existing cache and bazel won't have to do any work.
- # In the case of a cache miss, you want the fallback cache to contain most of the
- # previously built artifacts to minimize build time. The more precise you are with
- # hashFiles sources the less work bazel will have to do.
- # - name: Mount bazel caches
- # uses: actions/cache@v5
- # with:
- # path: |
- # ~/.cache/bazel-repo-cache
- # ~/.cache/bazel-repo-contents-cache
- # key: bazel-cache-${{ matrix.os }}-${{ hashFiles('**/BUILD.bazel', '**/*.bzl', 'MODULE.bazel') }}
- # restore-keys: |
- # bazel-cache-${{ matrix.os }}
+ # Restore bazel repository cache so we don't have to redownload all the external dependencies
+ # on every CI run.
+ - name: Restore bazel repository cache
+ id: cache_bazel_repository_restore
+ uses: actions/cache/restore@v5
+ with:
+ path: |
+ ~/.cache/bazel-repo-cache
+ key: bazel-cache-${{ matrix.os }}-${{ hashFiles('MODULE.bazel', 'codex-rs/Cargo.lock', 'codex-rs/Cargo.toml') }}
+ restore-keys: |
+ bazel-cache-${{ matrix.os }}
- name: Configure Bazel startup args (Windows)
if: runner.os == 'Windows'
@@ -229,3 +216,14 @@ jobs:
print_failed_bazel_test_logs "$bazel_console_log"
exit "$bazel_status"
fi
+
+ # Save bazel repository cache explicitly; make non-fatal so cache uploading
+ # never fails the overall job. Only save when key wasn't hit.
+ - name: Save bazel repository cache
+ if: always() && !cancelled() && steps.cache_bazel_repository_restore.outputs.cache-hit != 'true'
+ continue-on-error: true
+ uses: actions/cache/save@v5
+ with:
+ path: |
+ ~/.cache/bazel-repo-cache
+ key: bazel-cache-${{ matrix.os }}-${{ hashFiles('MODULE.bazel', 'codex-rs/Cargo.lock', 'codex-rs/Cargo.toml') }}