From be4c7f1c4e9eb559c27d46d5d0ce49aae846a9c1 Mon Sep 17 00:00:00 2001 From: dahai80 <121743945@qq.com> Date: Sat, 14 Nov 2026 05:42:20 +0800 Subject: [PATCH] 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 --- src/setup-python.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/setup-python.ts b/src/setup-python.ts index 8a3c7e37..178d6157 100644 --- a/src/setup-python.ts +++ b/src/setup-python.ts @@ -94,7 +94,12 @@ function resolveVersionInput() { } 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'; }