Skip to content

Commit

Permalink
feat: allow defining a python version list for GHA action
Browse files Browse the repository at this point in the history
  • Loading branch information
mayeut committed Apr 28, 2022
1 parent a2fd497 commit f9617e3
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 3 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,26 @@ jobs:
python -m pip install --disable-pip-version-check .
- name: Run tests on ${{ matrix.os }}
run: nox --non-interactive --error-on-missing-interpreter --session "tests-${{ matrix.python-version }}" -- --full-trace
action-default-tests:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-18.04, windows-2019, macos-10.15]
steps:
- uses: actions/checkout@v2
- uses: ./
- run: nox --non-interactive --error-on-missing-interpreter --session github_actions_default_tests
action-all-tests:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-18.04, windows-2019, macos-10.15]
steps:
- uses: actions/checkout@v2
- uses: ./
with:
python-versions: "['2.7', '3.5', '3.6', '3.7', '3.8', '3.9', '3.10', '3.11', 'pypy3.7', 'pypy3.8', 'pypy3.9']"
- run: nox --non-interactive --error-on-missing-interpreter --session github_actions_all_tests
lint:
runs-on: ubuntu-20.04
steps:
Expand Down
37 changes: 35 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
name: Setup Nox
description: 'Prepares all python versions for nox'
description: "Prepares all python versions for nox"
inputs:
python-versions:
description: "List of python versions to install"
required: true
default: "['3.7', '3.8', '3.9', '3.10', 'pypy3.7', 'pypy3.8', 'pypy3.9']"
branding:
icon: package
color: blue
Expand All @@ -10,26 +15,54 @@ runs:
- uses: actions/setup-python@v3
with:
python-version: "pypy-3.7"
if: ${{ contains(fromJSON(inputs.python-versions), 'pypy3.7') }}
- uses: actions/setup-python@v3
with:
python-version: "pypy-3.8"
if: ${{ contains(fromJSON(inputs.python-versions), 'pypy3.8') }}
- uses: actions/setup-python@v3
with:
python-version: "pypy-3.9"
if: ${{ contains(fromJSON(inputs.python-versions), 'pypy3.9') }}

- uses: actions/setup-python@v3
with:
python-version: "2.7"
if: ${{ contains(fromJSON(inputs.python-versions), '2.7') }}
- uses: actions/setup-python@v3
with:
python-version: "3.5"
if: ${{ contains(fromJSON(inputs.python-versions), '3.5') }}
- uses: actions/setup-python@v3
with:
python-version: "3.6"
if: ${{ contains(fromJSON(inputs.python-versions), '3.6') }}
- uses: actions/setup-python@v3
with:
python-version: "3.7"
if: ${{ contains(fromJSON(inputs.python-versions), '3.7') }}
- uses: actions/setup-python@v3
with:
python-version: "3.8"
if: ${{ contains(fromJSON(inputs.python-versions), '3.8') }}
- uses: actions/setup-python@v3
with:
python-version: "3.9"
if: ${{ contains(fromJSON(inputs.python-versions), '3.9') }}
- uses: actions/setup-python@v3
with:
python-version: "3.10"
# used to install nox
# if: ${{ contains(fromJSON(inputs.python-versions), '3.10') }}
- id: nox-python
run: echo "::set-output name=exe::$(which python)"
shell: bash

- uses: actions/setup-python@v3
with:
python-version: "3.11-dev"
if: ${{ contains(fromJSON(inputs.python-versions), '3.11') }}

- name: "Install nox"
run: pipx install '${{ github.action_path }}'
run: pipx install --python '${{ steps.nox-python.outputs.exe }}' '${{ github.action_path }}'
shell: bash
22 changes: 21 additions & 1 deletion docs/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,27 @@ Either way, Nox is usually installed *globally*, similar to ``tox``, ``pip``, an

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`_.

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.
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:

.. code-block:: yaml
# setup nox with all active CPython and PyPY versions provided by
# the GitHub Actions environment i.e.
# python-versions: "['3.7', '3.8', '3.9', '3.10', 'pypy3.7', 'pypy3.8', 'pypy3.9']"
- uses: wntrblm/nox
# setup nox only for a given list of python versions
# The supported set of versions is the one below,
# you must choose from this subset
- uses: wntrblm/nox
with:
python-versions: "['2.7', '3.5', '3.6', '3.7', '3.8', '3.9', '3.10', '3.11', 'pypy3.7', 'pypy3.8', 'pypy3.9']"
# You can also safely combine this with setup-python
- uses: wntrblm/nox
- uses: actions/setup-python@v3
with:
python-version: "3.11.0-alpha.7"
.. _pip: https://pip.readthedocs.org
.. _user site: https://packaging.python.org/tutorials/installing-packages/#installing-to-the-user-site
Expand Down
49 changes: 49 additions & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,52 @@ def docs(session):
sphinx_args.insert(0, "--open-browser")

session.run(sphinx_cmd, *sphinx_args)


# The following sessions are only to be run in CI to check the nox GHA action
def _check_python_version(session):
if session.python.startswith("pypy"):
python_version = session.python[4:]
implementation = "pypy"
else:
python_version = session.python
implementation = "cpython"
session.run(
"python",
"-c",
"import sys; assert '.'.join(str(v) for v in sys.version_info[:2]) =="
f" '{python_version}'",
)
if python_version[:2] != "2.":
session.run(
"python",
"-c",
f"import sys; assert sys.implementation.name == '{implementation}'",
)


@nox.session(python=["3.7", "3.8", "3.9", "3.10", "pypy3.7", "pypy3.8", "pypy3.9"])
def github_actions_default_tests(session):
"""Check default versions installed by the nox GHA Action"""
_check_python_version(session)


# The following sessions are only to be run in CI to check the nox GHA action
@nox.session(
python=[
"2.7",
"3.5",
"3.6",
"3.7",
"3.8",
"3.9",
"3.10",
"3.11",
"pypy3.7",
"pypy3.8",
"pypy3.9",
]
)
def github_actions_all_tests(session):
"""Check all versions installed by the nox GHA Action"""
_check_python_version(session)

0 comments on commit f9617e3

Please sign in to comment.