12

I am new to tox and GitHub actions, and I am looking for a simple way to make them work together. I wrote this simple workflow:

name: Python package

on: [push]

jobs:
  build:

    runs-on: ubuntu-latest
    strategy:
      max-parallel: 4
      matrix:
        python-version: [3.7]

    steps:
    - uses: actions/checkout@v1
    - name: Install tox
      run: pip install tox
    - name: Run tox
      run: tox

which just installs tox and then runs it. But when I run this workflow, the tox installation works fine, but the run command returns an error:

tox: command not found

What is the correct way to run tox from a GitHub action?

riQQ
  • 9,878
  • 7
  • 49
  • 66
Erel Segal-Halevi
  • 33,955
  • 36
  • 114
  • 183
  • tox dev seem to have created [something for this](https://github.com/tox-dev/gh-action-tox), but it's poorly documented and hasn't been edited in a year – joel Jul 27 '20 at 21:09

2 Answers2

13

You can also use tox-gh-actions.

In your workflow file:

 steps:
  - uses: actions/checkout@v1
  - name: Set up Python ${{ matrix.python-version }}
    uses: actions/setup-python@v2
    with:
      python-version: ${{ matrix.python-version }}
  - name: Install dependencies
    run: |
      python -m pip install --upgrade pip
      pip install tox tox-gh-actions
  - name: Test with tox
    run: tox

In your tox.ini (other config formats work too):

[gh-actions]
python = 
  3.8: py38
tobhai
  • 412
  • 6
  • 13
  • 7
    I think it's valuable to learn about tox-gh-actions, but this answer could elaborate on what problem that tool solves. E.g. Not so much about running tox, but about mapping the GA version matrix to tox envs. – antonagestam Apr 17 '21 at 09:25
  • 1
    The "Test with tox" section of the workflow file in the example accurately portrays how to actually run the testing using Tox in GitHub Actions. So it's rather complete! – Nitin Khanna Oct 25 '21 at 19:24
5

(Extend from the comment:)

Github Actions docs use actions/setup-python@v2:

- name: Setup Python
  uses: actions/setup-python@v2
  with:
    python-version: ${{ matrix.python }}

Also you can try python -m tox.

phd
  • 82,685
  • 13
  • 120
  • 165