|
| 1 | +--- |
| 2 | +name: CI |
| 3 | + |
| 4 | +on: |
| 5 | + push: |
| 6 | + branches: [master] |
| 7 | + pull_request: |
| 8 | + branches: [master] |
| 9 | + release: |
| 10 | + types: [published] |
| 11 | + |
| 12 | +jobs: |
| 13 | + lint-python: |
| 14 | + name: Lint Python |
| 15 | + runs-on: ubuntu-latest |
| 16 | + permissions: |
| 17 | + contents: read |
| 18 | + steps: |
| 19 | + - uses: actions/checkout@v4 |
| 20 | + - name: Set up Python 3.x |
| 21 | + uses: actions/setup-python@v5 |
| 22 | + with: |
| 23 | + python-version: "3.x" |
| 24 | + cache: "pip" |
| 25 | + - name: Install Hatch |
| 26 | + run: | |
| 27 | + pip3 --quiet install --upgrade hatch uv |
| 28 | + hatch --version |
| 29 | + uv --version |
| 30 | + - name: Run formatter |
| 31 | + run: hatch run lint:format-check || true |
| 32 | + - name: Run linter |
| 33 | + run: hatch run lint:check || true |
| 34 | + # TODO: Remove '|| true' when linting issues are resolved in future PR |
| 35 | + |
| 36 | + test-python: |
| 37 | + name: Python ${{ matrix.python-version }} |
| 38 | + runs-on: ubuntu-latest |
| 39 | + needs: |
| 40 | + - lint-python |
| 41 | + |
| 42 | + strategy: |
| 43 | + matrix: |
| 44 | + python-version: |
| 45 | + ["3.9", "3.10", "3.11", "3.12", "3.13"] |
| 46 | + |
| 47 | + steps: |
| 48 | + - uses: actions/checkout@v4 |
| 49 | + |
| 50 | + - uses: actions/setup-python@v5 |
| 51 | + with: |
| 52 | + python-version: ${{ matrix.python-version }} |
| 53 | + allow-prereleases: true |
| 54 | + cache: pip |
| 55 | + |
| 56 | + - name: Install dependencies |
| 57 | + run: python -m pip install --upgrade pip hatch uv |
| 58 | + |
| 59 | + - name: Show environment |
| 60 | + run: hatch test --show --python ${{ matrix.python-version }} |
| 61 | + |
| 62 | + - name: Run tests |
| 63 | + run: | |
| 64 | + hatch test --cover --python ${{ matrix.python-version }} |
| 65 | + mv .coverage ".coverage.py${{ matrix.python-version }}" |
| 66 | +
|
| 67 | + - name: Upload coverage data |
| 68 | + uses: actions/upload-artifact@v4 |
| 69 | + with: |
| 70 | + name: "coverage-data-py${{ matrix.python-version }}" |
| 71 | + path: ".coverage.py${{ matrix.python-version }}" |
| 72 | + if-no-files-found: error |
| 73 | + include-hidden-files: true |
| 74 | + retention-days: 7 |
| 75 | + |
| 76 | + test-functional: |
| 77 | + name: Functional Tests |
| 78 | + runs-on: ubuntu-latest |
| 79 | + needs: |
| 80 | + - lint-python |
| 81 | + |
| 82 | + steps: |
| 83 | + - uses: actions/checkout@v4 |
| 84 | + |
| 85 | + - uses: actions/setup-python@v5 |
| 86 | + with: |
| 87 | + python-version: "3.12" |
| 88 | + cache: pip |
| 89 | + |
| 90 | + - name: Install dependencies |
| 91 | + run: python -m pip install --upgrade pip hatch uv |
| 92 | + |
| 93 | + - name: Run functional tests |
| 94 | + run: hatch run functional:test |
| 95 | + |
| 96 | + build-python: |
| 97 | + name: Build Python |
| 98 | + runs-on: ubuntu-latest |
| 99 | + permissions: |
| 100 | + contents: read |
| 101 | + needs: |
| 102 | + - lint-python |
| 103 | + steps: |
| 104 | + - uses: actions/checkout@v4 |
| 105 | + - name: Set up Python 3.x |
| 106 | + uses: actions/setup-python@v5 |
| 107 | + with: |
| 108 | + python-version: "3.x" |
| 109 | + cache: "pip" |
| 110 | + - name: Install Hatch |
| 111 | + run: | |
| 112 | + pip3 --quiet install --upgrade hatch uv |
| 113 | + hatch --version |
| 114 | + uv --version |
| 115 | + - name: Build release files |
| 116 | + run: hatch build --clean |
| 117 | + - uses: actions/upload-artifact@v4 |
| 118 | + with: |
| 119 | + name: artifacts |
| 120 | + path: dist/* |
| 121 | + if-no-files-found: error |
| 122 | + retention-days: 7 |
| 123 | + |
| 124 | + coverage-python: |
| 125 | + name: Check Python Coverage |
| 126 | + runs-on: ubuntu-latest |
| 127 | + needs: |
| 128 | + - test-python |
| 129 | + steps: |
| 130 | + - uses: actions/checkout@v4 |
| 131 | + |
| 132 | + - uses: actions/setup-python@v5 |
| 133 | + with: |
| 134 | + python-version: "3.x" |
| 135 | + cache: pip |
| 136 | + |
| 137 | + - name: Install dependencies |
| 138 | + run: python -m pip install --upgrade coverage[toml] |
| 139 | + |
| 140 | + - name: Download data |
| 141 | + uses: actions/download-artifact@v4 |
| 142 | + with: |
| 143 | + merge-multiple: true |
| 144 | + |
| 145 | + - name: Combine coverage and fail if it's <80% |
| 146 | + run: | |
| 147 | + python -m coverage combine |
| 148 | + python -m coverage html --skip-covered --skip-empty |
| 149 | + python -m coverage report --fail-under=80 |
| 150 | +
|
| 151 | + - name: Upload HTML report |
| 152 | + uses: actions/upload-artifact@v4 |
| 153 | + with: |
| 154 | + name: coverage-report |
| 155 | + path: htmlcov |
| 156 | + |
| 157 | + # This workflow relies on the user manually creating a "stub release" on GitHub with the correct version number in the tag. |
| 158 | + publish-github: |
| 159 | + name: Publish GitHub Release |
| 160 | + runs-on: ubuntu-latest |
| 161 | + if: startsWith(github.ref, 'refs/tags/') |
| 162 | + permissions: |
| 163 | + contents: write |
| 164 | + concurrency: |
| 165 | + group: publish-github |
| 166 | + needs: |
| 167 | + - build-python |
| 168 | + - coverage-python |
| 169 | + - test-functional |
| 170 | + steps: |
| 171 | + - uses: actions/checkout@v4 |
| 172 | + with: |
| 173 | + fetch-depth: 0 |
| 174 | + - uses: actions/download-artifact@v4 |
| 175 | + with: |
| 176 | + name: artifacts |
| 177 | + path: dist |
| 178 | + - name: Get latest release info |
| 179 | + id: query-release-info |
| 180 | + uses: release-flow/keep-a-changelog-action@v3 |
| 181 | + with: |
| 182 | + command: query |
| 183 | + version: ${{ github.ref_name }} |
| 184 | + - name: Display release info |
| 185 | + run: | |
| 186 | + echo "Version: ${{ steps.query-release-info.outputs.version }}" |
| 187 | + echo "Date: ${{ steps.query-release-info.outputs.release-date }}" |
| 188 | + echo "${{ steps.query-release-info.outputs.release-notes }}" |
| 189 | + - uses: ncipollo/release-action@v1 |
| 190 | + with: |
| 191 | + artifacts: "dist/*.tar.gz,dist/*.whl" |
| 192 | + body: ${{ steps.query-release-info.outputs.release-notes }} |
| 193 | + allowUpdates: true |
| 194 | + |
| 195 | + publish-pypi: |
| 196 | + name: Publish PyPi Package |
| 197 | + runs-on: ubuntu-latest |
| 198 | + if: startsWith(github.ref, 'refs/tags/') |
| 199 | + permissions: |
| 200 | + id-token: write # IMPORTANT: this permission is mandatory for trusted publishing |
| 201 | + concurrency: |
| 202 | + group: publish-pypi |
| 203 | + needs: |
| 204 | + - publish-github |
| 205 | + steps: |
| 206 | + - uses: actions/download-artifact@v4 |
| 207 | + with: |
| 208 | + name: artifacts |
| 209 | + path: dist |
| 210 | + - name: Publish build to PyPI |
| 211 | + uses: pypa/gh-action-pypi-publish@release/v1 |
0 commit comments