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