| 1 |
--- |
| 2 |
name: CI |
| 3 |
|
| 4 |
on: |
| 5 |
merge_group: |
| 6 |
push: |
| 7 |
branches: [main] |
| 8 |
tags: ["*"] |
| 9 |
pull_request: |
| 10 |
workflow_dispatch: |
| 11 |
|
| 12 |
env: |
| 13 |
FORCE_COLOR: "1" |
| 14 |
PIP_DISABLE_PIP_VERSION_CHECK: "1" |
| 15 |
PIP_NO_PYTHON_VERSION_WARNING: "1" |
| 16 |
|
| 17 |
permissions: {} |
| 18 |
|
| 19 |
|
| 20 |
jobs: |
| 21 |
build-package: |
| 22 |
name: Build & verify package |
| 23 |
runs-on: ubuntu-latest |
| 24 |
|
| 25 |
steps: |
| 26 |
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 27 |
with: |
| 28 |
fetch-depth: 0 |
| 29 |
persist-credentials: false |
| 30 |
|
| 31 |
- uses: hynek/build-and-inspect-python-package@efb823f52190ad02594531168b7a2d5790e66516 # v2.14.0 |
| 32 |
id: baipp |
| 33 |
|
| 34 |
outputs: |
| 35 |
# Used to define the matrix for tests below. The value is based on |
| 36 |
# packaging metadata (trove classifiers). |
| 37 |
supported-python-versions: ${{ steps.baipp.outputs.supported_python_classifiers_json_array }} |
| 38 |
|
| 39 |
tests: |
| 40 |
name: Tests & Mypy on ${{ matrix.python-version }} |
| 41 |
runs-on: ubuntu-latest |
| 42 |
needs: build-package |
| 43 |
|
| 44 |
strategy: |
| 45 |
fail-fast: false |
| 46 |
matrix: |
| 47 |
# Created by the build-and-inspect-python-package action above. |
| 48 |
python-version: ${{ fromJson(needs.build-package.outputs.supported-python-versions) }} |
| 49 |
|
| 50 |
steps: |
| 51 |
- name: Download pre-built packages |
| 52 |
uses: actions/download-artifact@70fc10c6e5e1ce46ad2ea6f2b72d43f7d47b13c3 # v8.0.0 |
| 53 |
with: |
| 54 |
name: Packages |
| 55 |
path: dist |
| 56 |
- run: tar xf dist/*.tar.gz --strip-components=1 |
| 57 |
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 |
| 58 |
with: |
| 59 |
python-version: ${{ matrix.python-version }} |
| 60 |
allow-prereleases: true |
| 61 |
- uses: hynek/setup-cached-uv@757bedc3f972eb7227a1aa657651f15a8527c817 # v2.3.0 |
| 62 |
|
| 63 |
- name: Prepare tox |
| 64 |
env: |
| 65 |
V: ${{ matrix.python-version }} |
| 66 |
run: | |
| 67 |
DO_MYPY=1 |
| 68 |
|
| 69 |
if [[ "$V" == "3.9" ]]; then |
| 70 |
DO_MYPY=0 |
| 71 |
fi |
| 72 |
|
| 73 |
echo DO_MYPY=$DO_MYPY >>$GITHUB_ENV |
| 74 |
echo TOX_PYTHON=py$(echo $V | tr -d .) >>$GITHUB_ENV |
| 75 |
|
| 76 |
- run: > |
| 77 |
uvx --with=tox-uv |
| 78 |
tox run |
| 79 |
-e $TOX_PYTHON-mypy |
| 80 |
if: env.DO_MYPY == '1' |
| 81 |
|
| 82 |
- name: Remove src to ensure tests run against wheel |
| 83 |
run: rm -rf src |
| 84 |
|
| 85 |
- run: > |
| 86 |
uvx --with=tox-uv |
| 87 |
tox run |
| 88 |
--installpkg dist/*.whl |
| 89 |
-e $TOX_PYTHON-tests |
| 90 |
|
| 91 |
- name: Upload coverage data |
| 92 |
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0 |
| 93 |
with: |
| 94 |
name: coverage-data-${{ matrix.python-version }} |
| 95 |
path: .coverage.* |
| 96 |
include-hidden-files: true |
| 97 |
if-no-files-found: ignore |
| 98 |
|
| 99 |
tests-pypy: |
| 100 |
name: Tests on ${{ matrix.python-version }} |
| 101 |
runs-on: ubuntu-latest |
| 102 |
needs: build-package |
| 103 |
|
| 104 |
strategy: |
| 105 |
fail-fast: false |
| 106 |
matrix: |
| 107 |
python-version: |
| 108 |
- pypy-3.10 |
| 109 |
|
| 110 |
steps: |
| 111 |
- name: Download pre-built packages |
| 112 |
uses: actions/download-artifact@70fc10c6e5e1ce46ad2ea6f2b72d43f7d47b13c3 # v8.0.0 |
| 113 |
with: |
| 114 |
name: Packages |
| 115 |
path: dist |
| 116 |
- run: | |
| 117 |
tar xf dist/*.tar.gz --strip-components=1 |
| 118 |
rm -rf src # ensure tests run against wheel |
| 119 |
- uses: hynek/setup-cached-uv@757bedc3f972eb7227a1aa657651f15a8527c817 # v2.3.0 |
| 120 |
|
| 121 |
- run: > |
| 122 |
uvx --with=tox-uv |
| 123 |
tox run |
| 124 |
--installpkg dist/*.whl |
| 125 |
-e pypy3-tests |
| 126 |
|
| 127 |
coverage: |
| 128 |
name: Combine & check coverage |
| 129 |
runs-on: ubuntu-latest |
| 130 |
needs: tests |
| 131 |
|
| 132 |
steps: |
| 133 |
- name: Download pre-built packages |
| 134 |
uses: actions/download-artifact@70fc10c6e5e1ce46ad2ea6f2b72d43f7d47b13c3 # v8.0.0 |
| 135 |
with: |
| 136 |
name: Packages |
| 137 |
path: dist |
| 138 |
- run: tar xf dist/*.tar.gz --strip-components=1 |
| 139 |
- uses: hynek/setup-cached-uv@757bedc3f972eb7227a1aa657651f15a8527c817 # v2.3.0 |
| 140 |
|
| 141 |
- name: Download coverage data |
| 142 |
uses: actions/download-artifact@70fc10c6e5e1ce46ad2ea6f2b72d43f7d47b13c3 # v8.0.0 |
| 143 |
with: |
| 144 |
pattern: coverage-data-* |
| 145 |
merge-multiple: true |
| 146 |
|
| 147 |
- name: Combine coverage & fail if it's <100%. |
| 148 |
run: | |
| 149 |
uv tool install --python $(cat .python-version-default) coverage |
| 150 |
|
| 151 |
coverage combine |
| 152 |
coverage html --skip-covered --skip-empty |
| 153 |
|
| 154 |
# Report and write to summary. |
| 155 |
coverage report --format=markdown >> $GITHUB_STEP_SUMMARY |
| 156 |
|
| 157 |
# Report again and fail if under 100%. |
| 158 |
coverage report --fail-under=100 |
| 159 |
|
| 160 |
- name: Upload HTML report if check failed. |
| 161 |
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0 |
| 162 |
with: |
| 163 |
name: html-report |
| 164 |
path: htmlcov |
| 165 |
if: ${{ failure() }} |
| 166 |
|
| 167 |
docs: |
| 168 |
name: Run doctests & render changelog |
| 169 |
runs-on: ubuntu-latest |
| 170 |
needs: build-package |
| 171 |
steps: |
| 172 |
- name: Download pre-built packages |
| 173 |
uses: actions/download-artifact@70fc10c6e5e1ce46ad2ea6f2b72d43f7d47b13c3 # v8.0.0 |
| 174 |
with: |
| 175 |
name: Packages |
| 176 |
path: dist |
| 177 |
- run: tar xf dist/*.tar.gz --strip-components=1 |
| 178 |
- uses: hynek/setup-cached-uv@757bedc3f972eb7227a1aa657651f15a8527c817 # v2.3.0 |
| 179 |
|
| 180 |
- run: uvx --with=tox-uv tox run -e docs-doctests,changelog |
| 181 |
|
| 182 |
typing: |
| 183 |
name: Check types using supported type checkers |
| 184 |
runs-on: ubuntu-latest |
| 185 |
steps: |
| 186 |
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 187 |
with: |
| 188 |
persist-credentials: false |
| 189 |
- uses: hynek/setup-cached-uv@757bedc3f972eb7227a1aa657651f15a8527c817 # v2.3.0 |
| 190 |
|
| 191 |
- run: > |
| 192 |
uvx --with=tox-uv |
| 193 |
--python $(cat .python-version-default) |
| 194 |
tox run -f typing |
| 195 |
|
| 196 |
install-dev: |
| 197 |
name: Verify dev env |
| 198 |
runs-on: ubuntu-latest |
| 199 |
|
| 200 |
steps: |
| 201 |
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 202 |
with: |
| 203 |
persist-credentials: false |
| 204 |
- uses: hynek/setup-cached-uv@757bedc3f972eb7227a1aa657651f15a8527c817 # v2.3.0 |
| 205 |
|
| 206 |
- run: uv sync --python $(cat .python-version-default) |
| 207 |
|
| 208 |
- name: Ensure we can import attr and attrs packages |
| 209 |
run: | |
| 210 |
source .venv/bin/activate |
| 211 |
|
| 212 |
python -Ic 'import attr; print(attr.__version__)' |
| 213 |
python -Ic 'import attrs; print(attrs.__version__)' |
| 214 |
|
| 215 |
# Ensure everything required is passing for branch protection. |
| 216 |
required-checks-pass: |
| 217 |
if: always() |
| 218 |
|
| 219 |
needs: |
| 220 |
- coverage |
| 221 |
- tests-pypy |
| 222 |
- docs |
| 223 |
- install-dev |
| 224 |
- typing |
| 225 |
|
| 226 |
runs-on: ubuntu-latest |
| 227 |
|
| 228 |
steps: |
| 229 |
- name: Decide whether the needed jobs succeeded or failed |
| 230 |
uses: re-actors/alls-green@05ac9388f0aebcb5727afa17fcccfecd6f8ec5fe # v1.2.2 |
| 231 |
with: |
| 232 |
jobs: ${{ toJSON(needs) }} |