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 30, 2022
1 parent 099cf99 commit 62015f1
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 8 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ jobs:
- 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, ubuntu-20.04, windows-2019, windows-2022, macos-10.15, macos-11, macos-12]
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
38 changes: 35 additions & 3 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,27 +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"
# --python "$(which python)" => always use the last setup-python version to install nox.
run: pipx install --python "$(which python)" '${{ github.action_path }}'
run: pipx install --python '${{ steps.nox-python.outputs.exe }}' '${{ github.action_path }}'
shell: bash
14 changes: 9 additions & 5 deletions docs/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,21 @@ If you want to run ``nox`` within `GitHub Actions`_, you can use the ``wntrblm/n
# setup nox with all active CPython and PyPY versions provided by
# the GitHub Actions environment i.e.
# CPython 3.7 -> 3.10, PyPy 3.7 -> 3.9
# python-versions: "['3.7', '3.8', '3.9', '3.10', 'pypy3.7', 'pypy3.8', 'pypy3.9']"
- uses: wntrblm/nox
# You can also safely combine this with setup-python
# 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
- uses: actions/setup-python@v3
with:
python-version: "2.7"
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-dev"
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
21 changes: 21 additions & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,24 @@ def _check_python_version(session):
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 62015f1

Please sign in to comment.