Skip to content

Commit a9ee341

Browse files
committed
feat: allow defining a python version list for GHA action
1 parent aadcbaf commit a9ee341

File tree

4 files changed

+125
-3
lines changed

4 files changed

+125
-3
lines changed

.github/workflows/ci.yml

+20
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,26 @@ jobs:
2929
python -m pip install --disable-pip-version-check .
3030
- name: Run tests on ${{ matrix.os }}
3131
run: nox --non-interactive --error-on-missing-interpreter --session "tests-${{ matrix.python-version }}" -- --full-trace
32+
action-default-tests:
33+
runs-on: ${{ matrix.os }}
34+
strategy:
35+
matrix:
36+
os: [ubuntu-18.04, windows-2019, macos-10.15]
37+
steps:
38+
- uses: actions/checkout@v2
39+
- uses: ./
40+
- run: nox --non-interactive --error-on-missing-interpreter --session github_actions_default_tests
41+
action-all-tests:
42+
runs-on: ${{ matrix.os }}
43+
strategy:
44+
matrix:
45+
os: [ubuntu-18.04, windows-2019, macos-10.15]
46+
steps:
47+
- uses: actions/checkout@v2
48+
- uses: ./
49+
with:
50+
python-versions: "['2.7', '3.5', '3.6', '3.7', '3.8', '3.9', '3.10', '3.11', 'pypy3.7', 'pypy3.8', 'pypy3.9']"
51+
- run: nox --non-interactive --error-on-missing-interpreter --session github_actions_all_tests
3252
lint:
3353
runs-on: ubuntu-20.04
3454
steps:

action.yml

+35-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
name: Setup Nox
2-
description: 'Prepares all python versions for nox'
2+
description: "Prepares all python versions for nox"
3+
inputs:
4+
python-versions:
5+
description: "List of python versions to install"
6+
required: true
7+
default: "['3.7', '3.8', '3.9', '3.10', 'pypy3.7', 'pypy3.8', 'pypy3.9']"
38
branding:
49
icon: package
510
color: blue
@@ -10,26 +15,54 @@ runs:
1015
- uses: actions/setup-python@v3
1116
with:
1217
python-version: "pypy-3.7"
18+
if: ${{ contains(fromJSON(inputs.python-versions), 'pypy3.7') }}
1319
- uses: actions/setup-python@v3
1420
with:
1521
python-version: "pypy-3.8"
22+
if: ${{ contains(fromJSON(inputs.python-versions), 'pypy3.8') }}
1623
- uses: actions/setup-python@v3
1724
with:
1825
python-version: "pypy-3.9"
26+
if: ${{ contains(fromJSON(inputs.python-versions), 'pypy3.9') }}
1927

28+
- uses: actions/setup-python@v3
29+
with:
30+
python-version: "2.7"
31+
if: ${{ contains(fromJSON(inputs.python-versions), '2.7') }}
32+
- uses: actions/setup-python@v3
33+
with:
34+
python-version: "3.5"
35+
if: ${{ contains(fromJSON(inputs.python-versions), '3.5') }}
36+
- uses: actions/setup-python@v3
37+
with:
38+
python-version: "3.6"
39+
if: ${{ contains(fromJSON(inputs.python-versions), '3.6') }}
2040
- uses: actions/setup-python@v3
2141
with:
2242
python-version: "3.7"
43+
if: ${{ contains(fromJSON(inputs.python-versions), '3.7') }}
2344
- uses: actions/setup-python@v3
2445
with:
2546
python-version: "3.8"
47+
if: ${{ contains(fromJSON(inputs.python-versions), '3.8') }}
2648
- uses: actions/setup-python@v3
2749
with:
2850
python-version: "3.9"
51+
if: ${{ contains(fromJSON(inputs.python-versions), '3.9') }}
2952
- uses: actions/setup-python@v3
3053
with:
3154
python-version: "3.10"
55+
# used to install nox
56+
# if: ${{ contains(fromJSON(inputs.python-versions), '3.10') }}
57+
- id: nox-python
58+
run: echo "::set-output name=exe::$(which python)"
59+
shell: bash
60+
61+
- uses: actions/setup-python@v3
62+
with:
63+
python-version: "3.11-dev"
64+
if: ${{ contains(fromJSON(inputs.python-versions), '3.11') }}
3265

3366
- name: "Install nox"
34-
run: pipx install '${{ github.action_path }}'
67+
run: pipx install --python '${{ steps.nox-python.outputs.exe }}' '${{ github.action_path }}'
3568
shell: bash

docs/tutorial.rst

+21-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,27 @@ Either way, Nox is usually installed *globally*, similar to ``tox``, ``pip``, an
2929

3030
If you're interested in running ``nox`` within `docker`_, you can use the `thekevjames/nox images`_ on DockerHub which contain builds for all ``nox`` versions and all supported ``python`` versions. Nox is also supported via ``pipx run nox`` in the `manylinux images`_.
3131

32-
If you want to run ``nox`` within `GitHub Actions`_, you can use the `wntrblm/nox action`_, which installs the latest ``nox`` and makes available all active CPython and PyPY versions provided by the GitHub Actions environment. You can safely combine this with with ``setup-python`` for past end-of-life or development versions of Python, as well.
32+
If you want to run ``nox`` within `GitHub Actions`_, you can use the `wntrblm/nox action`_, which installs the latest ``nox`` and makes available all active CPython and PyPY versions provided by the GitHub Actions environment. You can safely combine this with ``setup-python`` for past end-of-life or development versions of Python, as well:
33+
34+
.. code-block:: yaml
35+
36+
# setup nox with all active CPython and PyPY versions provided by
37+
# the GitHub Actions environment i.e.
38+
# python-versions: "['3.7', '3.8', '3.9', '3.10', 'pypy3.7', 'pypy3.8', 'pypy3.9']"
39+
- uses: wntrblm/nox
40+
41+
# setup nox only for a given list of python versions
42+
# The supported set of versions is the one below,
43+
# you must choose from this subset
44+
- uses: wntrblm/nox
45+
with:
46+
python-versions: "['2.7', '3.5', '3.6', '3.7', '3.8', '3.9', '3.10', '3.11', 'pypy3.7', 'pypy3.8', 'pypy3.9']"
47+
48+
# You can also safely combine this with setup-python
49+
- uses: wntrblm/nox
50+
- uses: actions/setup-python@v3
51+
with:
52+
python-version: "3.11.0-alpha.7"
3353
3454
.. _pip: https://pip.readthedocs.org
3555
.. _user site: https://packaging.python.org/tutorials/installing-packages/#installing-to-the-user-site

noxfile.py

+49
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,52 @@ def docs(session):
108108
sphinx_args.insert(0, "--open-browser")
109109

110110
session.run(sphinx_cmd, *sphinx_args)
111+
112+
113+
# The following sessions are only to be run in CI to check the nox GHA action
114+
def _check_python_version(session):
115+
if session.python.startswith("pypy"):
116+
python_version = session.python[4:]
117+
implementation = "pypy"
118+
else:
119+
python_version = session.python
120+
implementation = "cpython"
121+
session.run(
122+
"python",
123+
"-c",
124+
"import sys; assert '.'.join(str(v) for v in sys.version_info[:2]) =="
125+
f" '{python_version}'",
126+
)
127+
if python_version[:2] != "2.":
128+
session.run(
129+
"python",
130+
"-c",
131+
f"import sys; assert sys.implementation.name == '{implementation}'",
132+
)
133+
134+
135+
@nox.session(python=["3.7", "3.8", "3.9", "3.10", "pypy3.7", "pypy3.8", "pypy3.9"])
136+
def github_actions_default_tests(session):
137+
"""Check default versions installed by the nox GHA Action"""
138+
_check_python_version(session)
139+
140+
141+
# The following sessions are only to be run in CI to check the nox GHA action
142+
@nox.session(
143+
python=[
144+
"2.7",
145+
"3.5",
146+
"3.6",
147+
"3.7",
148+
"3.8",
149+
"3.9",
150+
"3.10",
151+
"3.11",
152+
"pypy3.7",
153+
"pypy3.8",
154+
"pypy3.9",
155+
]
156+
)
157+
def github_actions_all_tests(session):
158+
"""Check all versions installed by the nox GHA Action"""
159+
_check_python_version(session)

0 commit comments

Comments
 (0)