unreached-rs: use system Python when it is 3.11 or newer

actions/setup-python has no builds for Debian, so the lint leg fails on
PhotoCraft's artcraft-k8s-main (Trixie) runners. The action only needs
tomllib (3.11+); use the system interpreter when that is already new
enough, and install 3.12 only on older images such as ubuntu-22.04.

Part of #335
This commit is contained in:
FredApps committed 2026-11-23 11:10:23 +07:00
1 parent 2157cf98c4
commit 8830c54c07
2 files changed
+29 -2

No files matched your search

+14 -2
View File
@@ -28,9 +28,21 @@ inputs:
runs:
using: composite
steps:
# tomllib needs Python 3.11; runner images pinned to older ones (ubuntu-22.04) ship 3.10, and this
# step runs before the gate's Setup.
# tomllib needs Python 3.11. ubuntu-22.04 ships 3.10, so install 3.12 there. actions/setup-python
# has no builds for Debian (PhotoCraft's artcraft-k8s-main lint runner is Trixie), where system
# python3 is already 3.11+.
- name: Use system Python when it is 3.11 or newer
id: python
shell: bash
run: |
if python3 -c 'import sys; raise SystemExit(0 if sys.version_info >= (3, 11) else 1)' 2>/dev/null; then
python3 -V
echo "install=false" >> "$GITHUB_OUTPUT"
else
echo "install=true" >> "$GITHUB_OUTPUT"
fi
- name: Python 3.12
if: steps.python.outputs.install == 'true'
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
python-version: "3.12"
+15
View File
@@ -250,5 +250,20 @@ class UnreachedRsTests(unittest.TestCase):
self.assertEqual(run(self.root, "--mode", "diff", "--base", base, "--allow", "tools/**"), (0, []))
class UnreachedRsActionTests(unittest.TestCase):
"""The composite action installs Python 3.12 only when the runner's python3 is older than 3.11."""
def test_setup_python_only_when_system_python_is_old(self):
import yaml
action = yaml.load((ROOT / 'actions/unreached-rs/action.yml').read_text(), Loader=yaml.BaseLoader)
steps = {step['name']: step for step in action['runs']['steps']}
detect = steps['Use system Python when it is 3.11 or newer']
self.assertEqual(detect['id'], 'python')
self.assertIn('sys.version_info >= (3, 11)', detect['run'])
install = steps['Python 3.12']
self.assertEqual(install['if'], "steps.python.outputs.install == 'true'")
self.assertIn('actions/setup-python@', install['uses'])
self.assertEqual(install['with']['python-version'], '3.12')
if __name__ == "__main__":
unittest.main()