Skip to content

Fix(workflow): Stop the job env choosing Python - #197

Merged
ModeSevenIndustrialSolutions merged 1 commit into
lfreleng-actions:mainfrom
lfreleng-bot-forks:code-monkey/issue-196
Nov 5, 2026
Merged

ModeSevenIndustrialSolutions merged 1 commit into
lfreleng-actions:mainfrom
lfreleng-bot-forks:code-monkey/issue-196

Conversation

@lf-releng-code-monkey-bot

@lf-releng-code-monkey-bot lf-releng-code-monkey-bot Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Closes #196

Authored by an AI agent; human review required
Command Exit
bash tests/uv-interpreter-steps.sh 0
bash tests/workflow-steps.sh 0
prek run --files .github/workflows/sonatype-lifecycle.yaml tests/uv-interpreter-steps.sh .github/workflows/workflow-tests.yaml examples/sonatype-lifecycle/github.yaml 0
uvx zizmor --persona auditor --offline .github/workflows/sonatype-lifecycle.yaml .github/workflows/workflow-tests.yaml 0
aislop scan --base 529c54315546e01a0e9328bb4fad4b812f14d67e --json 0
prek run gitlint --hook-stage commit-msg --commit-msg-filename <commit message> 0
git log --raw --format=%h 529c54315546e01a0e9328bb4fad4b812f14d67e..HEAD 0

The github-code-monkey-bot workflow 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

  • Setup uv disables its own interpreter lookup (UV_PYTHON_PREFERENCE: lookup-disabled), clears UV_PYTHON_ARCH, pins UV_PYTHON_INSTALL_DIR and tool-bin-dir under runner.temp, and keeps the cache off. UV_SYSTEM_PYTHON stays (pinned by tests/workflow-steps.sh) and is inert.
  • Install Python (new, in runner.temp) installs the requested Python with uv under env -i: python_version, else the project's requires-python, else 3.13. It outputs the absolute interpreter path.
  • Resolve Python dependencies passes that path as --python to uv venv and uv export (the latter now also --no-config).
  • tests/uv-interpreter-steps.sh (new, regular file, run with bash) pins the settings and step order and runs both steps with a stub uv; workflow-tests.yaml runs it. tests/workflow-steps.sh is unchanged.

This round

Copilot and a maintainer found the awk reader for requires-python missed valid TOML ("""…""" strings, quoted keys, dotted keys) and fell back to 3.13 outside the project's range. It now uses mikefarah yq -p toml, which runs no project code. A missing file or key falls back to 3.13; invalid TOML or a non-mikefarah-v4 yq fails the step. Regression cases cover each form and both failures.

Checks run

  • bash tests/uv-interpreter-steps.sh: 54 cases pass
  • bash tests/workflow-steps.sh: 119 cases pass
  • prek run --files <changed files> (yamllint, shellcheck, actionlint, zizmor, reuse and more): pass
  • zizmor --persona auditor: no findings
  • aislop scan against the base: no diagnostics
  • gitlint on the commit message: pass

For the reviewer

The step relies on yq from ubuntu-latest (the scan job's fixed runner), and fails clearly when it is missing or the wrong flavour.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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 venv and uv 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

@ModeSevenIndustrialSolutions

Copy link
Copy Markdown
Member

Revision requested (maintainer). Copilot's thread is right: the awk reader for requires-python handles only a one-line quoted string under a literal [project] header, so valid TOML (a """…""" string, a quoted key "requires-python", a dotted key project.requires-python = …) reads as absent and silently falls back to 3.13, outside the project's declared range.

Replace the awk block with mikefarah yq's TOML parser, which reads the file without executing project code. ubuntu-latest ships it (v4.54.1), and this repository's harness already depends on it. Use the interpreter-free form:

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: """>=3.10,<3.13""" → >=3.10,<3.13; "requires-python" = ">=3.11" → >=3.11; single-quoted '>=3.9' → >=3.9; project.requires-python = ">=3.12" → >=3.12; a key only under [tool.x] → empty (falls back, correct); no key → empty; a malformed file exits 1 (fail the step; do not fall back silently). Keep the existing fallback to 3.13 only for a missing file or a missing key, and the yq version check the harness already does (fail clearly if yq is not mikefarah v4).

Add regression cases to tests/uv-interpreter-steps.sh for each of those inputs, including the malformed-file failure. Keep tests/workflow-steps.sh unchanged, as the issue requires. Reply on the thread, resolve it, keep the single-commit shape (amend), and keep the checks green.

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>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues remain for the Python interpreter-selection hardening change.

No open issues 🎉

Review effort: Balanced

@ModeSevenIndustrialSolutions
ModeSevenIndustrialSolutions merged commit 840ad62 into lfreleng-actions:main Nov 5, 2026
16 checks passed
@ModeSevenIndustrialSolutions
ModeSevenIndustrialSolutions deleted the code-monkey/issue-196 branch November 5, 2026 16:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix(workflow): Stop the job env choosing Python

2 participants