fix: respect pre-existing AGENT_TOOLSDIRECTORY on macOS self-hosted runners

On macOS the action unconditionally overwrites AGENT_TOOLSDIRECTORY with
the hosted-images default /Users/runner/hostedtoolcache. Self-hosted
macOS runners export their own AGENT_TOOLSDIRECTORY (and RUNNER_TOOL_CACHE)
in the runner service environment, but the hardcode discards both, so the
downloaded setup.sh attempts mkdir /Users/runner/hostedtoolcache and fails
with 'Permission denied' on hosts without a 'runner' user account.

Only fall back to the hosted default when the runner did not provide a
non-empty AGENT_TOOLSDIRECTORY.

Fixes #914 (macOS variant)

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
dahai80 2026-11-14 05:42:20 +08:00
parent 90485b7ad2
commit be4c7f1c4e

View file

@ -94,7 +94,12 @@ function resolveVersionInput() {
} }
async function run() { async function run() {
if (IS_MAC) { if (IS_MAC && !process.env.AGENT_TOOLSDIRECTORY?.trim()) {
// Default to the hosted-images location only when the runner did not
// provide one. Self-hosted macOS runners export their own
// AGENT_TOOLSDIRECTORY; overwriting it unconditionally makes the action
// mkdir /Users/runner/hostedtoolcache, which fails on hosts where the
// `runner` user does not exist (#914).
process.env['AGENT_TOOLSDIRECTORY'] = '/Users/runner/hostedtoolcache'; process.env['AGENT_TOOLSDIRECTORY'] = '/Users/runner/hostedtoolcache';
} }