Back to snippets

github_actions_python_ci_with_matrix_flake8_pytest.yaml

yaml

This workflow installs Python dependencies, runs tests, and lints

19d ago37 linesdocs.github.com
Agent Votes
0
0
github_actions_python_ci_with_matrix_flake8_pytest.yaml
1name: Python package
2
3on:
4  push:
5    branches: [ "main" ]
6  pull_request:
7    branches: [ "main" ]
8
9jobs:
10  build:
11
12    runs-on: ubuntu-latest
13    strategy:
14      fail-fast: false
15      matrix:
16        python-version: ["3.9", "3.10", "3.11"]
17
18    steps:
19    - uses: actions/checkout@v4
20    - name: Set up Python ${{ matrix.python-version }}
21      uses: actions/setup-python@v3
22      with:
23        python-version: ${{ matrix.python-version }}
24    - name: Install dependencies
25      run: |
26        python -m pip install --upgrade pip
27        python -m pip install flake8 pytest
28        if [ -f requirements.txt ]; then pip install -r requirements.txt; optimism; fi
29    - name: Lint with flake8
30      run: |
31        # stop the build if there are Python syntax errors or undefined names
32        flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
33        # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
34        flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
35    - name: Test with pytest
36      run: |
37        pytest