diff --git a/.github/actions/setup-bazel-ci/action.yml b/.github/actions/setup-bazel-ci/action.yml index a1e46d2d04..0b5f4aeb66 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,33 @@ runs: - name: Set up Bazel uses: bazelbuild/setup-bazelisk@v3 + - name: Configure Bazel repository cache + id: configure_bazel_repository_cache + shell: pwsh + run: | + if ($env:RUNNER_OS -eq 'Windows') { + if (Test-Path 'D:\') { + $repositoryCachePath = 'D:\a\.cache\bazel-repo-cache' + $repositoryCache = 'D:/a/.cache/bazel-repo-cache' + } else { + $repositoryCachePath = Join-Path $env:USERPROFILE '.cache\bazel-repo-cache' + $repositoryCache = $repositoryCachePath + } + } else { + $repositoryCachePath = Join-Path $HOME '.cache/bazel-repo-cache' + $repositoryCache = $repositoryCachePath + } + + "repository-cache-path=$repositoryCachePath" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append + "BAZEL_REPOSITORY_CACHE=$repositoryCache" | 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. - name: Restore bazel repository cache id: cache_bazel_repository_restore 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 +87,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') }}