|
| 1 | +name: Tests |
| 2 | + |
| 3 | +on: |
| 4 | + - push |
| 5 | + - pull_request |
| 6 | + |
| 7 | +jobs: |
| 8 | + tests: |
| 9 | + name: ${{ matrix.session }} ${{ matrix.python }} / ${{ matrix.os }} |
| 10 | + runs-on: ${{ matrix.os }} |
| 11 | + strategy: |
| 12 | + fail-fast: false |
| 13 | + matrix: |
| 14 | + include: |
| 15 | + - { python: "3.10", os: "ubuntu-latest", session: "pre-commit" } |
| 16 | + - { python: "3.10", os: "ubuntu-latest", session: "safety" } |
| 17 | + # - { python: "3.10", os: "ubuntu-latest", session: "mypy" } |
| 18 | + # - { python: "3.9", os: "ubuntu-latest", session: "mypy" } |
| 19 | + # - { python: "3.8", os: "ubuntu-latest", session: "mypy" } |
| 20 | + - { python: "3.10", os: "ubuntu-latest", session: "tests" } |
| 21 | + - { python: "3.9", os: "ubuntu-latest", session: "tests" } |
| 22 | + - { python: "3.8", os: "ubuntu-latest", session: "tests" } |
| 23 | + - { python: "3.10", os: "windows-latest", session: "tests" } |
| 24 | + - { python: "3.10", os: "macos-latest", session: "tests" } |
| 25 | + # - { python: "3.10", os: "ubuntu-latest", session: "typeguard" } |
| 26 | + # - { python: "3.10", os: "ubuntu-latest", session: "xdoctest" } |
| 27 | + - { python: "3.10", os: "ubuntu-latest", session: "docs-build" } |
| 28 | + |
| 29 | + env: |
| 30 | + NOXSESSION: ${{ matrix.session }} |
| 31 | + FORCE_COLOR: "1" |
| 32 | + PRE_COMMIT_COLOR: "always" |
| 33 | + |
| 34 | + steps: |
| 35 | + - name: Check out the repository |
| 36 | + uses: actions/checkout@v3 |
| 37 | + |
| 38 | + - name: Set up Python ${{ matrix.python }} |
| 39 | + uses: actions/setup-python@v3 |
| 40 | + with: |
| 41 | + python-version: ${{ matrix.python }} |
| 42 | + |
| 43 | + - name: Upgrade pip |
| 44 | + run: | |
| 45 | + pip install --constraint=.github/workflows/constraints.txt pip |
| 46 | + pip --version |
| 47 | +
|
| 48 | + - name: Upgrade pip in virtual environments |
| 49 | + shell: python |
| 50 | + run: | |
| 51 | + import os |
| 52 | + import pip |
| 53 | +
|
| 54 | + with open(os.environ["GITHUB_ENV"], mode="a") as io: |
| 55 | + print(f"VIRTUALENV_PIP={pip.__version__}", file=io) |
| 56 | +
|
| 57 | + - name: Install Poetry |
| 58 | + run: | |
| 59 | + pipx install --pip-args=--constraint=.github/workflows/constraints.txt poetry |
| 60 | + poetry --version |
| 61 | +
|
| 62 | + - name: Install Nox |
| 63 | + run: | |
| 64 | + pipx install --pip-args=--constraint=.github/workflows/constraints.txt nox |
| 65 | + pipx inject --pip-args=--constraint=.github/workflows/constraints.txt nox nox-poetry |
| 66 | + nox --version |
| 67 | +
|
| 68 | + - name: Compute pre-commit cache key |
| 69 | + if: matrix.session == 'pre-commit' |
| 70 | + id: pre-commit-cache |
| 71 | + shell: python |
| 72 | + run: | |
| 73 | + import hashlib |
| 74 | + import sys |
| 75 | +
|
| 76 | + python = "py{}.{}".format(*sys.version_info[:2]) |
| 77 | + payload = sys.version.encode() + sys.executable.encode() |
| 78 | + digest = hashlib.sha256(payload).hexdigest() |
| 79 | + result = "${{ runner.os }}-{}-{}-pre-commit".format(python, digest[:8]) |
| 80 | +
|
| 81 | + print("::set-output name=result::{}".format(result)) |
| 82 | +
|
| 83 | + - name: Restore pre-commit cache |
| 84 | + uses: actions/cache@v3 |
| 85 | + if: matrix.session == 'pre-commit' |
| 86 | + with: |
| 87 | + path: ~/.cache/pre-commit |
| 88 | + key: ${{ steps.pre-commit-cache.outputs.result }}-${{ hashFiles('.pre-commit-config.yaml') }} |
| 89 | + restore-keys: | |
| 90 | + ${{ steps.pre-commit-cache.outputs.result }}- |
| 91 | +
|
| 92 | + - name: Run Nox |
| 93 | + run: | |
| 94 | + nox --python=${{ matrix.python }} |
| 95 | +
|
| 96 | + - name: Upload coverage data |
| 97 | + if: always() && matrix.session == 'tests' |
| 98 | + uses: "actions/upload-artifact@v3" |
| 99 | + with: |
| 100 | + name: coverage-data |
| 101 | + path: ".coverage.*" |
| 102 | + |
| 103 | + - name: Upload documentation |
| 104 | + if: matrix.session == 'docs-build' |
| 105 | + uses: actions/upload-artifact@v3 |
| 106 | + with: |
| 107 | + name: docs |
| 108 | + path: docs/_build |
| 109 | + |
| 110 | + coverage: |
| 111 | + runs-on: ubuntu-latest |
| 112 | + needs: tests |
| 113 | + steps: |
| 114 | + - name: Check out the repository |
| 115 | + uses: actions/checkout@v3 |
| 116 | + |
| 117 | + - name: Set up Python |
| 118 | + uses: actions/setup-python@v3 |
| 119 | + with: |
| 120 | + python-version: "3.10" |
| 121 | + |
| 122 | + - name: Upgrade pip |
| 123 | + run: | |
| 124 | + pip install --constraint=.github/workflows/constraints.txt pip |
| 125 | + pip --version |
| 126 | +
|
| 127 | + - name: Install Poetry |
| 128 | + run: | |
| 129 | + pipx install --pip-args=--constraint=.github/workflows/constraints.txt poetry |
| 130 | + poetry --version |
| 131 | +
|
| 132 | + - name: Install Nox |
| 133 | + run: | |
| 134 | + pipx install --pip-args=--constraint=.github/workflows/constraints.txt nox |
| 135 | + pipx inject --pip-args=--constraint=.github/workflows/constraints.txt nox nox-poetry |
| 136 | + nox --version |
| 137 | +
|
| 138 | + - name: Download coverage data |
| 139 | + uses: actions/download-artifact@v3 |
| 140 | + with: |
| 141 | + name: coverage-data |
| 142 | + |
| 143 | + - name: Combine coverage data and display human readable report |
| 144 | + run: | |
| 145 | + nox --session=coverage |
| 146 | +
|
| 147 | + - name: Create coverage report |
| 148 | + run: | |
| 149 | + nox --session=coverage -- xml |
| 150 | +
|
| 151 | + - name: Upload coverage report |
| 152 | + |
0 commit comments