|
1 | | -# This workflow will install Python dependencies, run tests and lint with a variety of Python versions |
2 | | -# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions |
| 1 | +--- |
3 | 2 | name: Tests |
4 | 3 |
|
5 | 4 | on: |
6 | | - push: |
7 | | - branches: [ master ] |
8 | | - pull_request: |
9 | | - branches: [ master ] |
| 5 | + - push |
| 6 | + - pull_request |
10 | 7 |
|
11 | 8 | jobs: |
12 | | - build: |
13 | | - |
| 9 | + tests: |
| 10 | + name: ${{ matrix.session }} ${{ matrix.python }} / ${{ matrix.os }} |
| 11 | + runs-on: ${{ matrix.os }} |
14 | 12 | strategy: |
| 13 | + fail-fast: false |
15 | 14 | matrix: |
16 | | - platform: [ubuntu-latest, macos-latest, windows-latest] |
17 | | - python-version: ["3.7", "3.8", "3.9", "3.10"] |
18 | | - runs-on: ${{ matrix.platform }} |
| 15 | + include: |
| 16 | + - { python: "3.10", os: "ubuntu-latest", session: "pre-commit" } |
| 17 | + - { python: "3.10", os: "ubuntu-latest", session: "tests" } |
| 18 | + - { python: "3.9", os: "ubuntu-latest", session: "tests" } |
| 19 | + - { python: "3.8", os: "ubuntu-latest", session: "tests" } |
| 20 | + - { python: "3.7", os: "ubuntu-latest", session: "tests" } |
| 21 | + - { python: "3.10", os: "windows-latest", session: "tests" } |
| 22 | + - { python: "3.10", os: "macos-latest", session: "tests" } |
| 23 | + |
| 24 | + env: |
| 25 | + NOXSESSION: ${{ matrix.session }} |
| 26 | + FORCE_COLOR: "1" |
| 27 | + PRE_COMMIT_COLOR: "always" |
19 | 28 |
|
20 | 29 | steps: |
21 | | - - uses: actions/checkout@v2.4.0 |
22 | | - - name: Set up Python ${{ matrix.python-version }} |
23 | | - uses: actions/setup-python@v2.3.1 |
24 | | - with: |
25 | | - python-version: ${{ matrix.python-version }} |
26 | | - - name: Install dependencies |
27 | | - run: | |
28 | | - python -m pip install --upgrade pip |
29 | | - python -m pip install -r requirements-dev.txt |
30 | | - - name: Lint with flake8 |
31 | | - run: | |
32 | | - # stop the build if there are Python syntax errors or undefined names |
33 | | - flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics |
34 | | - # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide |
35 | | - flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics |
36 | | - - name: Test with pytest |
37 | | - run: | |
38 | | - pytest |
| 30 | + - name: Check out the repository |
| 31 | + uses: actions/checkout@v2.4.0 |
| 32 | + |
| 33 | + - name: Set up Python ${{ matrix.python }} |
| 34 | + uses: actions/setup-python@v2.3.1 |
| 35 | + with: |
| 36 | + python-version: ${{ matrix.python }} |
| 37 | + |
| 38 | + - name: Upgrade pip |
| 39 | + run: | |
| 40 | + pip install --constraint=.github/workflows/constraints.txt pip |
| 41 | + pip --version |
| 42 | +
|
| 43 | + - name: Upgrade pip in virtual environments |
| 44 | + shell: python |
| 45 | + run: | |
| 46 | + import os |
| 47 | + import pip |
| 48 | + with open(os.environ["GITHUB_ENV"], mode="a") as io: |
| 49 | + print(f"VIRTUALENV_PIP={pip.__version__}", file=io) |
| 50 | +
|
| 51 | + - name: Install Poetry |
| 52 | + run: | |
| 53 | + pipx install --pip-args=--constraint=.github/workflows/constraints.txt poetry |
| 54 | + poetry --version |
| 55 | +
|
| 56 | + - name: Install Nox |
| 57 | + run: | |
| 58 | + pipx install --pip-args=--constraint=.github/workflows/constraints.txt nox |
| 59 | + pipx inject --pip-args=--constraint=.github/workflows/constraints.txt nox nox-poetry |
| 60 | + nox --version |
| 61 | +
|
| 62 | + - name: Compute pre-commit cache key |
| 63 | + if: matrix.session == 'pre-commit' |
| 64 | + id: pre-commit-cache |
| 65 | + shell: python |
| 66 | + run: | |
| 67 | + import hashlib |
| 68 | + import sys |
| 69 | + python = "py{}.{}".format(*sys.version_info[:2]) |
| 70 | + payload = sys.version.encode() + sys.executable.encode() |
| 71 | + digest = hashlib.sha256(payload).hexdigest() |
| 72 | + result = "${{ runner.os }}-{}-{}-pre-commit".format(python, digest[:8]) |
| 73 | + print("::set-output name=result::{}".format(result)) |
| 74 | +
|
| 75 | + - name: Restore pre-commit cache |
| 76 | + uses: actions/cache@v2.1.7 |
| 77 | + if: matrix.session == 'pre-commit' |
| 78 | + with: |
| 79 | + path: ~/.cache/pre-commit |
| 80 | + key: ${{ steps.pre-commit-cache.outputs.result }}-${{ hashFiles('.pre-commit-config.yaml') }} |
| 81 | + restore-keys: | |
| 82 | + ${{ steps.pre-commit-cache.outputs.result }}- |
| 83 | +
|
| 84 | + - name: Run Nox |
| 85 | + run: | |
| 86 | + nox --force-color --python=${{ matrix.python }} |
| 87 | +
|
| 88 | + - name: Upload coverage data |
| 89 | + if: always() && matrix.session == 'tests' |
| 90 | + uses: "actions/upload-artifact@v2.3.1" |
| 91 | + with: |
| 92 | + name: coverage-data |
| 93 | + path: ".coverage.*" |
| 94 | + |
| 95 | + coverage: |
| 96 | + runs-on: ubuntu-latest |
| 97 | + needs: tests |
| 98 | + steps: |
| 99 | + - name: Check out the repository |
| 100 | + uses: actions/checkout@v2.4.0 |
| 101 | + |
| 102 | + - name: Set up Python |
| 103 | + uses: actions/setup-python@v2.3.1 |
| 104 | + with: |
| 105 | + python-version: "3.10" |
| 106 | + |
| 107 | + - name: Upgrade pip |
| 108 | + run: | |
| 109 | + pip install --constraint=.github/workflows/constraints.txt pip |
| 110 | + pip --version |
| 111 | +
|
| 112 | + - name: Install Poetry |
| 113 | + run: | |
| 114 | + pipx install --pip-args=--constraint=.github/workflows/constraints.txt poetry |
| 115 | + poetry --version |
| 116 | +
|
| 117 | + - name: Install Nox |
| 118 | + run: | |
| 119 | + pipx install --pip-args=--constraint=.github/workflows/constraints.txt nox |
| 120 | + pipx inject --pip-args=--constraint=.github/workflows/constraints.txt nox nox-poetry |
| 121 | + nox --version |
| 122 | +
|
| 123 | + - name: Download coverage data |
| 124 | + uses: actions/download-artifact@v2.1.0 |
| 125 | + with: |
| 126 | + name: coverage-data |
| 127 | + |
| 128 | + - name: Combine coverage data and display human readable report |
| 129 | + run: | |
| 130 | + nox --force-color --session=coverage |
| 131 | +
|
| 132 | + - name: Create coverage report |
| 133 | + run: | |
| 134 | + nox --force-color --session=coverage -- xml |
| 135 | +
|
| 136 | + - name: Upload coverage report |
| 137 | + uses: codecov/codecov-action@v2.1.0 |
0 commit comments