diff --git a/.bazelrc b/.bazelrc index fd6ff75beb..603ad46e4b 100644 --- a/.bazelrc +++ b/.bazelrc @@ -124,7 +124,6 @@ build:argument-comment-lint --@rules_rust//rust/toolchain/channel=nightly common:ci-windows --config=ci-bazel common:ci-windows --build_metadata=TAG_os=windows common:ci-windows --repo_contents_cache=D:/a/.cache/bazel-repo-contents-cache -common:ci-windows --repository_cache=D:/a/.cache/bazel-repo-cache # We prefer to run the build actions entirely remotely so we can dial up the concurrency. # We have platform-specific tests, so we want to execute the tests on all platforms using the strongest sandboxing available on each platform. diff --git a/.github/actions/setup-bazel-ci/action.yml b/.github/actions/setup-bazel-ci/action.yml index a1e46d2d04..560fca9503 100644 --- a/.github/actions/setup-bazel-ci/action.yml +++ b/.github/actions/setup-bazel-ci/action.yml @@ -12,6 +12,9 @@ outputs: cache-hit: description: Whether the Bazel repository cache key was restored exactly. value: ${{ steps.cache_bazel_repository_restore.outputs.cache-hit }} + repository-cache-path: + description: Filesystem path used for the Bazel repository cache. + value: ${{ steps.configure_bazel_repository_cache.outputs.repository-cache-path }} runs: using: composite @@ -41,14 +44,26 @@ runs: - name: Set up Bazel uses: bazelbuild/setup-bazelisk@v3 + - name: Configure Bazel repository cache + id: configure_bazel_repository_cache + shell: pwsh + run: | + # Keep the repository cache under HOME on all runners. Windows `D:\a` + # cache paths match `.bazelrc`, but `actions/cache/restore` currently + # returns HTTP 400 for that path in the Windows clippy job. + $repositoryCachePath = Join-Path $HOME '.cache/bazel-repo-cache' + "repository-cache-path=$repositoryCachePath" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append + "BAZEL_REPOSITORY_CACHE=$repositoryCachePath" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + # Restore bazel repository cache so we don't have to redownload all the external dependencies - # on every CI run. + # on every CI run. Keep restore failures non-fatal so transient cache-service + # errors degrade to a cold build instead of failing the job. - name: Restore bazel repository cache id: cache_bazel_repository_restore + continue-on-error: true uses: actions/cache/restore@v5 with: - path: | - ~/.cache/bazel-repo-cache + path: ${{ steps.configure_bazel_repository_cache.outputs.repository-cache-path }} key: bazel-cache-${{ inputs.target }}-${{ hashFiles('MODULE.bazel', 'codex-rs/Cargo.lock', 'codex-rs/Cargo.toml') }} restore-keys: | bazel-cache-${{ inputs.target }} @@ -65,10 +80,6 @@ runs: $repoContentsCache = Join-Path $env:RUNNER_TEMP "bazel-repo-contents-cache-$env:GITHUB_RUN_ID-$env:GITHUB_JOB" "BAZEL_OUTPUT_USER_ROOT=$bazelOutputUserRoot" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append "BAZEL_REPO_CONTENTS_CACHE=$repoContentsCache" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append - if (-not $hasDDrive) { - $repositoryCache = Join-Path $env:USERPROFILE '.cache\bazel-repo-cache' - "BAZEL_REPOSITORY_CACHE=$repositoryCache" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append - } - name: Expose MSVC SDK environment (Windows) if: runner.os == 'Windows' diff --git a/.github/workflows/bazel.yml b/.github/workflows/bazel.yml index 30f0661639..b3145205ce 100644 --- a/.github/workflows/bazel.yml +++ b/.github/workflows/bazel.yml @@ -116,8 +116,7 @@ jobs: continue-on-error: true uses: actions/cache/save@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5 with: - path: | - ~/.cache/bazel-repo-cache + path: ${{ steps.setup_bazel.outputs.repository-cache-path }} key: bazel-cache-${{ matrix.target }}-${{ hashFiles('MODULE.bazel', 'codex-rs/Cargo.lock', 'codex-rs/Cargo.toml') }} clippy: @@ -190,6 +189,5 @@ jobs: continue-on-error: true uses: actions/cache/save@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5 with: - path: | - ~/.cache/bazel-repo-cache + path: ${{ steps.setup_bazel.outputs.repository-cache-path }} key: bazel-cache-${{ matrix.target }}-${{ hashFiles('MODULE.bazel', 'codex-rs/Cargo.lock', 'codex-rs/Cargo.toml') }}