ci: compute Windows Bazel PATH in setup action

This commit is contained in:
Michael Bolin
2026-04-23 11:31:35 -07:00
parent 64a018b986
commit ead134ec0c
3 changed files with 76 additions and 40 deletions

View File

@@ -323,46 +323,15 @@ if [[ "${RUNNER_OS:-}" == "Windows" ]]; then
fi
done
# The GitHub Windows image puts many unrelated versioned tools on PATH. Those
# entries are still part of Bazel action/test keys when PATH is forwarded, so
# image churn such as Maven minor-version updates can invalidate otherwise
# reusable cache entries. Keep only the PATH segments Bazel actions/tests need.
windows_cache_stable_path_entries=()
if [[ -n "${PATH:-}" ]]; then
windows_path="${PATH}"
if command -v cygpath >/dev/null 2>&1; then
windows_path="$(cygpath -w -p "${PATH}")"
fi
IFS=';' read -r -a windows_path_entries <<< "${windows_path}"
for path_entry in "${windows_path_entries[@]}"; do
case "${path_entry}" in
*'Microsoft Visual Studio'* | \
*'Windows Kits'* | \
*'Microsoft SDKs'* | \
'C:\Program Files\Git\'* | \
'C:\Program Files\PowerShell\'* | \
'C:\Users\runneradmin\AppData\Local\Microsoft\WindowsApps' | \
'C:\hostedtoolcache\windows\node\'* | \
'C:\Windows' | \
'C:\Windows\'* | \
'D:\a\_temp\install-dotslash\bin')
windows_cache_stable_path_entries+=("${path_entry}")
;;
esac
done
fi
if (( ${#windows_cache_stable_path_entries[@]} == 0 )); then
echo "Failed to derive cache-stable Windows PATH from runner PATH." >&2
if [[ -z "${CODEX_BAZEL_WINDOWS_PATH:-}" ]]; then
echo "CODEX_BAZEL_WINDOWS_PATH must be set for Windows Bazel CI." >&2
exit 1
fi
stable_windows_path="$(IFS=';'; printf '%s' "${windows_cache_stable_path_entries[*]}")"
post_config_bazel_args+=(
"--action_env=PATH=${stable_windows_path}"
"--host_action_env=PATH=${stable_windows_path}"
"--test_env=PATH=${stable_windows_path}"
"--action_env=PATH=${CODEX_BAZEL_WINDOWS_PATH}"
"--host_action_env=PATH=${CODEX_BAZEL_WINDOWS_PATH}"
"--test_env=PATH=${CODEX_BAZEL_WINDOWS_PATH}"
)
fi