|
| 1 | +name: "Test" |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - "main" |
| 8 | + - "releases" |
| 9 | + |
| 10 | +jobs: |
| 11 | + build: |
| 12 | + name: "Build wheel" |
| 13 | + runs-on: "ubuntu-latest" |
| 14 | + outputs: |
| 15 | + wheel-filename: "${{ steps.get-filename.outputs.wheel-filename }}" |
| 16 | + steps: |
| 17 | + - name: "Checkout branch" |
| 18 | + uses: "actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11" # v4.1.1 |
| 19 | + |
| 20 | + - name: "Setup Python" |
| 21 | + id: "setup-python" |
| 22 | + uses: "actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c" # v5.0.0 |
| 23 | + with: |
| 24 | + python-version: "3.12" |
| 25 | + |
| 26 | + - name: "Build the project" |
| 27 | + run: "pip wheel ." |
| 28 | + |
| 29 | + - name: "Identify the wheel filename" |
| 30 | + id: "get-filename" |
| 31 | + run: | |
| 32 | + echo "wheel-filename=$(find listparser-*.whl | head -n 1)" >> "$GITHUB_OUTPUT" |
| 33 | +
|
| 34 | + - name: "Upload the build artifact" |
| 35 | + uses: "actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3" # v4.3.1 |
| 36 | + with: |
| 37 | + name: "listparser-${{ github.sha }}.whl" |
| 38 | + path: "${{ steps.get-filename.outputs.wheel-filename }}" |
| 39 | + retention-days: 1 |
| 40 | + |
| 41 | + test: |
| 42 | + name: "Test on ${{ matrix.run.os.name }}" |
| 43 | + runs-on: "${{ matrix.run.os.id }}" |
| 44 | + needs: "build" |
| 45 | + |
| 46 | + strategy: |
| 47 | + matrix: |
| 48 | + run: |
| 49 | + - os: |
| 50 | + id: "ubuntu-latest" |
| 51 | + name: "Ubuntu" |
| 52 | + pythons: | |
| 53 | + pypy3.9 |
| 54 | + 3.8 |
| 55 | + 3.9 |
| 56 | + 3.10 |
| 57 | + 3.11 |
| 58 | + 3.12 |
| 59 | + tox-environments: |
| 60 | + - "py312-http-lxml" |
| 61 | + - "py311-http-lxml" |
| 62 | + - "py310-http-lxml" |
| 63 | + - "py39-http-lxml" |
| 64 | + - "py38-http-lxml" |
| 65 | + - "pypy39" |
| 66 | + |
| 67 | + # Test lowest and highest versions on Windows. |
| 68 | + - os: |
| 69 | + id: "windows-latest" |
| 70 | + name: "Windows" |
| 71 | + pythons: | |
| 72 | + 3.8 |
| 73 | + 3.11 |
| 74 | + tox-environments: |
| 75 | + - "py38" |
| 76 | + - "py311" |
| 77 | + |
| 78 | + # Test lowest and highest versions on Mac. |
| 79 | + - os: |
| 80 | + name: "MacOS" |
| 81 | + id: "macos-latest" |
| 82 | + pythons: | |
| 83 | + 3.8 |
| 84 | + 3.11 |
| 85 | + tox-environments: |
| 86 | + - "py38" |
| 87 | + - "py311" |
| 88 | + |
| 89 | + steps: |
| 90 | + # The week number is used for cache-busting. |
| 91 | + - name: "Identify week number" |
| 92 | + shell: "bash" |
| 93 | + run: "date +'%V' > week-number.txt" |
| 94 | + |
| 95 | + - name: "Checkout branch" |
| 96 | + uses: "actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11" # v4.1.1 |
| 97 | + |
| 98 | + - name: "Setup Pythons" |
| 99 | + id: "setup-python" |
| 100 | + uses: "actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c" # v5.0.0 |
| 101 | + with: |
| 102 | + python-version: "${{ matrix.run.pythons }}" |
| 103 | + allow-prereleases: true |
| 104 | + |
| 105 | + - name: "Restore cache" |
| 106 | + id: "restore-cache" |
| 107 | + uses: "actions/cache@ab5e6d0c87105b4c9c2047343972218f562e4319" # v4.0.1 |
| 108 | + with: |
| 109 | + path: | |
| 110 | + .tox/ |
| 111 | + .venv/ |
| 112 | + key: "test-os=${{ matrix.run.os.id }}-hash=${{ hashFiles('.github/workflows/test.yaml', 'pyproject.toml', 'tox.ini', 'week-number.txt', 'requirements/*/*.txt') }}" |
| 113 | + |
| 114 | + - name: "Identify venv path" |
| 115 | + shell: "bash" |
| 116 | + run: | |
| 117 | + echo 'venv-path=${{ runner.os == 'Windows' && '.venv/Scripts' || '.venv/bin' }}' >> "$GITHUB_ENV" |
| 118 | +
|
| 119 | + - name: "Create a virtual environment" |
| 120 | + if: "steps.restore-cache.outputs.cache-hit == false" |
| 121 | + run: | |
| 122 | + python -m venv .venv |
| 123 | + ${{ env.venv-path }}/python -m pip install --upgrade pip setuptools wheel |
| 124 | + ${{ env.venv-path }}/pip install tox |
| 125 | +
|
| 126 | + - name: "Download the build artifact" |
| 127 | + uses: "actions/download-artifact@87c55149d96e628cc2ef7e6fc2aab372015aec85" # v4.1.3 |
| 128 | + with: |
| 129 | + name: "listparser-${{ github.sha }}.whl" |
| 130 | + |
| 131 | + - name: "Test" |
| 132 | + run: > |
| 133 | + ${{ env.venv-path }}/tox run |
| 134 | + --installpkg "${{ needs.build.outputs.wheel-filename }}" |
| 135 | + -e ${{ join(matrix.run.tox-environments, ',') }} |
| 136 | +
|
| 137 | + - name: "Upload coverage data files" |
| 138 | + uses: "actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3" # v4.3.1 |
| 139 | + with: |
| 140 | + name: "coverage-data-files-${{ matrix.run.os.id }}" |
| 141 | + path: ".coverage.*" |
| 142 | + retention-days: 1 |
| 143 | + |
| 144 | + coverage: |
| 145 | + name: "Calculate code coverage" |
| 146 | + needs: "test" |
| 147 | + runs-on: "ubuntu-latest" |
| 148 | + steps: |
| 149 | + - name: "Checkout branch" |
| 150 | + uses: "actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11" # v4.1.1 |
| 151 | + |
| 152 | + - name: "Setup Pythons" |
| 153 | + id: "setup-python" |
| 154 | + uses: "actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c" # v5.0.0 |
| 155 | + with: |
| 156 | + python-version: "3.12" |
| 157 | + |
| 158 | + - name: "Restore cache" |
| 159 | + id: "restore-cache" |
| 160 | + uses: "actions/cache@ab5e6d0c87105b4c9c2047343972218f562e4319" # v4.0.1 |
| 161 | + with: |
| 162 | + path: ".venv/" |
| 163 | + key: "coverage-hash=${{ hashFiles('.github/workflows/test.yaml', 'pyproject.toml', 'week-number.txt', 'requirements/*/*.txt') }}" |
| 164 | + |
| 165 | + - name: "Create a virtual environment" |
| 166 | + if: "steps.restore-cache.outputs.cache-hit == false" |
| 167 | + run: | |
| 168 | + python -m venv .venv |
| 169 | + .venv/bin/python -m pip install --upgrade pip setuptools wheel |
| 170 | + .venv/bin/python -m pip install coverage[toml] |
| 171 | +
|
| 172 | + - name: "Download coverage data files" |
| 173 | + uses: "actions/download-artifact@87c55149d96e628cc2ef7e6fc2aab372015aec85" # v4.1.3 |
| 174 | + with: |
| 175 | + pattern: "coverage-data-files-*" |
| 176 | + merge-multiple: true |
| 177 | + |
| 178 | + - name: "Calculate coverage" |
| 179 | + run: | |
| 180 | + .venv/bin/coverage combine |
| 181 | + .venv/bin/coverage report |
| 182 | +
|
| 183 | + quality: |
| 184 | + name: "Quality" |
| 185 | + runs-on: "ubuntu-latest" |
| 186 | + needs: "build" |
| 187 | + steps: |
| 188 | + # The week number is used for cache-busting. |
| 189 | + - name: "Identify week number" |
| 190 | + run: "date +'%V' > week-number.txt" |
| 191 | + |
| 192 | + - name: "Checkout branch" |
| 193 | + uses: "actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11" # v4.1.1 |
| 194 | + |
| 195 | + - name: "Setup Pythons" |
| 196 | + id: "setup-python" |
| 197 | + uses: "actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c" # v5.0.0 |
| 198 | + with: |
| 199 | + python-version: "3.12" |
| 200 | + |
| 201 | + - name: "Restore cache" |
| 202 | + id: "restore-cache" |
| 203 | + uses: "actions/cache@ab5e6d0c87105b4c9c2047343972218f562e4319" # v4.0.1 |
| 204 | + with: |
| 205 | + path: | |
| 206 | + .mypy_cache/ |
| 207 | + .tox/ |
| 208 | + .venv/ |
| 209 | + key: "lint-hash=${{ hashFiles('.github/workflows/test.yaml', 'pyproject.toml', 'tox.ini', 'week-number.txt', 'requirements/*/*.txt') }}" |
| 210 | + |
| 211 | + - name: "Create a virtual environment" |
| 212 | + if: "steps.restore-cache.outputs.cache-hit == false" |
| 213 | + run: | |
| 214 | + python -m venv .venv |
| 215 | + .venv/bin/python -m pip install --upgrade pip setuptools wheel |
| 216 | + .venv/bin/pip install tox |
| 217 | +
|
| 218 | + - name: "Download the build artifact" |
| 219 | + uses: "actions/download-artifact@87c55149d96e628cc2ef7e6fc2aab372015aec85" # v4.1.3 |
| 220 | + with: |
| 221 | + name: "listparser-${{ github.sha }}.whl" |
| 222 | + |
| 223 | + - name: "Lint type annotations" |
| 224 | + run: > |
| 225 | + .venv/bin/tox run |
| 226 | + --installpkg "${{ needs.build.outputs.wheel-filename }}" |
| 227 | + -e mypy |
| 228 | +
|
| 229 | + - name: "Lint documentation" |
| 230 | + run: ".venv/bin/tox run -e docs" |
0 commit comments