Repository navigation
Fix(workflow): Stop the job env choosing Python - #197
ModeSevenIndustrialSolutions merged 1 commit into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Python constraint parsing misses valid TOML forms, allowing fallback to an unsupported interpreter and risking dependency resolution failures; a TOML-aware reader and regression tests are needed.
1 open issue
What changed in this PR
This PR hardens interpreter selection in the Sonatype Lifecycle Python lane, addressing #196 by installing managed Python in an isolated environment and passing its absolute path to dependency resolution.
Changes:
- Disables setup-uv’s interpreter lookup and adds an isolated Python installation step.
- Passes the selected interpreter to
uv venvanduv export, and documents the 3.13 fallback. - Adds stub-based regression checks and runs them in workflow CI.
| File | Description |
|---|---|
tests/uv-interpreter-steps.sh |
Adds checks for interpreter isolation, selection, and argument forwarding. |
examples/sonatype-lifecycle/github.yaml |
Updates the example comment to describe the Python 3.13 fallback. |
.github/workflows/workflow-tests.yaml |
Runs the new interpreter step tests. |
.github/workflows/sonatype-lifecycle.yaml |
Adds isolated Python installation and explicit interpreter selection for dependency resolution. |
Review effort: Balanced
|
Revision requested (maintainer). Copilot's thread is right: the Replace the request="$(yq -p toml -oy '.project["requires-python"] // ""' "${pyproject}")" || {
echo "::error::could not parse ${PATH_PREFIX:+${PATH_PREFIX}/}pyproject.toml as TOML"
exit 1
}Checked locally with yq v4.54.1: Add regression cases to |
setup-uv runs the interpreter 'uv python find' returns, and 'uv venv' without an absolute --python picks one from PATH, UV_PYTHON and similar variables. Any earlier step of the scan job can set those through GITHUB_ENV or GITHUB_PATH, so the job's environment, not the lane, chose the Python that resolves a project's dependencies. Setup uv now disables its own lookup with an invalid UV_PYTHON_PREFERENCE, clears UV_PYTHON_ARCH, pins UV_PYTHON_INSTALL_DIR and tool-bin-dir under runner.temp, and keeps the cache off. A new 'Install Python' step installs the requested Python with uv under 'env -i' from runner.temp: python_version, else the project's requires-python, else 3.13. It outputs the absolute path, which 'uv venv' and 'uv export' now take as --python, the latter also with --no-config. requires-python is read with mikefarah yq's TOML parser, which runs nothing from the project, so every valid TOML form counts: multi-line strings, quoted keys and dotted keys. A missing file or key falls back to 3.13; a file that is not valid TOML, or a yq that is not mikefarah v4, fails the step rather than falling back silently. tests/uv-interpreter-steps.sh pins the settings and step order and runs both steps with a stub uv, including each requires-python form and the failure cases. It is a separate file because tests/workflow-steps.sh is executable and left unchanged. Review round 1: Copilot (thread on the requires-python reader) and a maintainer found that the awk reader missed valid TOML forms and so fell back to 3.13 outside the project's range; replaced it with yq and added regression cases. Fixes: lfreleng-actions#196 Co-authored-by: Copilot <[email protected]> Signed-off-by: lf-releng-code-monkey-bot[bot] <332050256+lf-releng-code-monkey-bot[bot]@users.noreply.github.com>
0653119 to
9e6eeb0
Compare
840ad62
into
lfreleng-actions:main

Closes #196
Authored by an AI agent; human review required
claude-opus-5.5via GitHub Copilot CLI529c54315546e01a0e9328bb4fad4b812f14d67ebash tests/uv-interpreter-steps.shbash tests/workflow-steps.shprek run --files .github/workflows/sonatype-lifecycle.yaml tests/uv-interpreter-steps.sh .github/workflows/workflow-tests.yaml examples/sonatype-lifecycle/github.yamluvx zizmor --persona auditor --offline .github/workflows/sonatype-lifecycle.yaml .github/workflows/workflow-tests.yamlaislop scan --base 529c54315546e01a0e9328bb4fad4b812f14d67e --jsonprek run gitlint --hook-stage commit-msg --commit-msg-filename <commit message>git log --raw --format=%h 529c54315546e01a0e9328bb4fad4b812f14d67e..HEADThe
github-code-monkey-botworkflow opened this pull request.Nobody has merged it; a maintainer must review it first.
Review findings on this pull request are answered by a later revision round of this workflow, up to ten rounds; a maintainer must act on any finding that remains after that, and reviews every round before merge.
Round 1 of revision, on its base.
Hardens interpreter selection in the Sonatype Lifecycle Python lane (#196): nothing in the scan job's environment or the checkout can choose the Python uv runs.
What it does
UV_PYTHON_PREFERENCE: lookup-disabled), clearsUV_PYTHON_ARCH, pinsUV_PYTHON_INSTALL_DIRandtool-bin-dirunderrunner.temp, and keeps the cache off.UV_SYSTEM_PYTHONstays (pinned bytests/workflow-steps.sh) and is inert.runner.temp) installs the requested Python with uv underenv -i:python_version, else the project'srequires-python, else3.13. It outputs the absolute interpreter path.--pythontouv venvanduv export(the latter now also--no-config).tests/uv-interpreter-steps.sh(new, regular file, run withbash) pins the settings and step order and runs both steps with a stub uv;workflow-tests.yamlruns it.tests/workflow-steps.shis unchanged.This round
Copilot and a maintainer found the
awkreader forrequires-pythonmissed valid TOML ("""…"""strings, quoted keys, dotted keys) and fell back to 3.13 outside the project's range. It now uses mikefarahyq -p toml, which runs no project code. A missing file or key falls back to 3.13; invalid TOML or a non-mikefarah-v4yqfails the step. Regression cases cover each form and both failures.Checks run
bash tests/uv-interpreter-steps.sh: 54 cases passbash tests/workflow-steps.sh: 119 cases passprek run --files <changed files>(yamllint, shellcheck, actionlint, zizmor, reuse and more): passzizmor --persona auditor: no findingsFor the reviewer
The step relies on
yqfromubuntu-latest(the scan job's fixed runner), and fails clearly when it is missing or the wrong flavour.