Repository navigation
fix(action): start setup-python's interpreter outside GitHub's tool cache - #99
Merged
Merged
Conversation
…ache
setup-python's Linux builds find libpython through an RPATH fixed at build
time to /opt/hostedtoolcache. In any other tool cache, as on a self-hosted
runner, the interpreter starts only with its lib folder on LD_LIBRARY_PATH,
which setup-python exports only with update-environment, and the action turns
that off to leave the job's python alone. So `python -m venv` failed with
exit 127 ("error while loading shared libraries").
The install step moves to action/install.sh: where the interpreter does not
start as it is, it puts the build's lib folder (absolute, no empty element)
on LD_LIBRARY_PATH for the install and in the km command alone. On GitHub's
runners nothing changes. -P, PYTHONSAFEPATH and the PyYAML pin stay.
tests/action_smoke.sh covers both cases offline with stand-in interpreters;
a CI job runs the action with setup-python installing into another tool cache.
pasrom
force-pushed
the
fix/action-self-hosted-python
branch
from
November 18, 2026 09:32
8a07938 to
1a25d3d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On a self-hosted Linux runner the km action fails at its first command:
Cause, from the sources at the commits the action pins:
--enable-sharedandLDFLAGS=-Wl,--rpath=<tool cache>/Python/<version>/<arch>/lib, the tool cache being GitHub's/opt/hostedtoolcache(builders/ubuntu-python-builder.psm1,Configure()). In any other tool cache the interpreter does not findlibpython.setup.shwithLD_LIBRARY_PATH=<install dir>/lib(src/install-python.ts,installPython()), so the install succeeds, and it exportsLD_LIBRARY_PATHfor the job, but only withupdate-environment: true(src/find-python.ts, lines 151-172 at 6d4fd22).update-environment: false, to leave the job's own python alone, so the next command,python -m venv, has noLD_LIBRARY_PATH.setup-python's docs ("Using setup-python with a self-hosted runner", docs/advanced-usage.md) call the macOS builds non-relocatable and say to install them in
/Users/runner/hostedtoolcache; for Ubuntu they describeAGENT_TOOLSDIRECTORY. The fix that docs path implies,AGENT_TOOLSDIRECTORY=/opt/hostedtoolcache, needs a root-writable/opt, so sudo or an image change.Fix
The install step moves into
action/install.sh(same commands, same-P,PYTHONSAFEPATHandpyyaml==6.0.3). Beforevenv, it starts the interpreter with the job'sLD_LIBRARY_PATHremoved. If that fails, the script puts the build'slibfolder (absolute, with no empty element, which the loader would read as the working directory) onLD_LIBRARY_PATHfor the install, and writes it into the generatedkmcommand. On GitHub's runners the interpreter starts as it is, so nothing changes there. A runner needs no sudo, noAGENT_TOOLSDIRECTORY, no system Python and nopython3-venv.Options weighed:
python3+ venv: Ubuntu 24.04 has nopython3-venvby default, so pip would have to be fetched some other way, and it does not help a runner without Python.LD_LIBRARY_PATHscoped to km: chosen. It restores what setup-python itself does, needs no new download, and changes nothing where it is not needed.README "Running on your own runners" says what the runner needs.
Tests
tests/action_smoke.sh(new, offline, in the smoke job) uses stand-in interpreters: one that starts, and one that exits 127 unless itslibfolder is onLD_LIBRARY_PATH. It checks:LD_LIBRARY_PATHwith the job's unset and with it set,LD_LIBRARY_PATHdoes not decide the probe,Mutation check: each of these mutations fails at least one case:
New CI job
action-tool-cache(x64, GitHub's image) moves/opt/hostedtoolcacheaside and has setup-python install into/tmp/km-tool-cache. A guard step asserts that the venv's interpreter is the one in that cache and that it does not start on its own, so the job cannot pass vacuously. Its log shows the reported error (libpython3.11.so.1.0 => not found, exit 127). Thenkm --versionandkm validaterun with noLD_LIBRARY_PATHin the job.Plain
ubuntu:24.04containers, x64 and arm64. Each stages python-versions' 3.11.18 build in/home/runner/actions-runner/_work/_toolwith its ownsetup.sh, as setup-python does. Both variants behave the same:install.shkm --version,km validatepython33.12 withoutpython3-venv(no ensurepip)All smoke tests pass locally.
Review: /simplify and /code-review were run before opening. Skipped findings:
printf %qfor the paths in the launcher: this was already the case before this change.pwdpaths: the action never supported Windows runners, since the venv has nobin/there.