Erel Segal-Halevi
Erel Segal-Halevi

Reputation: 36793

How to run tox from github actions

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?

Upvotes: 13

Views: 7954

Answers (2)

phd
phd

Reputation: 94676

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

Upvotes: 7

tobhai
tobhai

Reputation: 462

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

Upvotes: 13

Related Questions