| 1 |
name: Lint check |
| 2 |
run-name: Lint code |
| 3 |
on: |
| 4 |
pull_request: |
| 5 |
push: |
| 6 |
branches: |
| 7 |
- master |
| 8 |
|
| 9 |
concurrency: |
| 10 |
# Cancel previous workflow run when a new commit is pushed to a feature branch |
| 11 |
group: ${{ github.workflow }}-${{ github.ref }} |
| 12 |
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} |
| 13 |
|
| 14 |
env: |
| 15 |
PYTHON_VERSION: "3.10" |
| 16 |
|
| 17 |
jobs: |
| 18 |
changed-files: |
| 19 |
runs-on: ubuntu-latest |
| 20 |
name: Get changed files |
| 21 |
outputs: |
| 22 |
any_docs_changed: ${{ steps.changed-doc-files.outputs.any_changed }} |
| 23 |
any_python_changed: ${{ steps.raw-changed-python-files.outputs.any_changed }} |
| 24 |
changed_doc_files: ${{ steps.changed-doc-files.outputs.all_changed_files }} |
| 25 |
changed_python_files: ${{ steps.changed-python-files.outputs.all_changed_files }} |
| 26 |
steps: |
| 27 |
- uses: actions/checkout@v5 |
| 28 |
- name: Get changed docs files |
| 29 |
id: changed-doc-files |
| 30 |
uses: tj-actions/changed-files@v46 |
| 31 |
with: |
| 32 |
files: | |
| 33 |
docs/** |
| 34 |
uv.lock |
| 35 |
- name: Get changed python files |
| 36 |
id: raw-changed-python-files |
| 37 |
uses: tj-actions/changed-files@v46 |
| 38 |
with: |
| 39 |
files: | |
| 40 |
**.py |
| 41 |
uv.lock |
| 42 |
|
| 43 |
- name: Check changed python files |
| 44 |
id: changed-python-files |
| 45 |
env: |
| 46 |
CHANGED_PYTHON_FILES: ${{ steps.raw-changed-python-files.outputs.all_changed_files }} |
| 47 |
run: | |
| 48 |
if [[ " $CHANGED_PYTHON_FILES " == *" uv.lock "* ]]; then |
| 49 |
# if uv.lock is changed, we need to check everything |
| 50 |
CHANGED_PYTHON_FILES="." |
| 51 |
fi |
| 52 |
echo "all_changed_files=$CHANGED_PYTHON_FILES" >> "$GITHUB_OUTPUT" |
| 53 |
|
| 54 |
format: |
| 55 |
if: needs.changed-files.outputs.any_python_changed == 'true' |
| 56 |
runs-on: ubuntu-latest |
| 57 |
name: Check formatting |
| 58 |
needs: changed-files |
| 59 |
steps: |
| 60 |
- uses: actions/checkout@v5 |
| 61 |
- name: Install uv |
| 62 |
uses: astral-sh/[email protected] |
| 63 |
with: |
| 64 |
python-version: ${{ env.PYTHON_VERSION }} |
| 65 |
|
| 66 |
- name: Install Python tools |
| 67 |
run: uv tool install "poethepoet>=0.26,<0.47.0" |
| 68 |
|
| 69 |
- name: Install dependencies |
| 70 |
run: poe install --only-group lint |
| 71 |
|
| 72 |
- name: Check code formatting |
| 73 |
# the job output will contain colored diffs with what needs adjusting |
| 74 |
run: poe check-format |
| 75 |
|
| 76 |
lint: |
| 77 |
if: needs.changed-files.outputs.any_python_changed == 'true' |
| 78 |
runs-on: ubuntu-latest |
| 79 |
name: Check linting |
| 80 |
needs: changed-files |
| 81 |
steps: |
| 82 |
- uses: actions/checkout@v5 |
| 83 |
- name: Install uv |
| 84 |
uses: astral-sh/[email protected] |
| 85 |
with: |
| 86 |
python-version: ${{ env.PYTHON_VERSION }} |
| 87 |
|
| 88 |
- name: Install Python tools |
| 89 |
run: uv tool install "poethepoet>=0.26,<0.47.0" |
| 90 |
|
| 91 |
- name: Install dependencies |
| 92 |
run: poe install --only-group lint |
| 93 |
|
| 94 |
- name: Lint code |
| 95 |
run: poe lint --output-format=github ${{ needs.changed-files.outputs.changed_python_files }} |
| 96 |
|
| 97 |
mypy: |
| 98 |
if: needs.changed-files.outputs.any_python_changed == 'true' |
| 99 |
runs-on: ubuntu-latest |
| 100 |
name: Check types with mypy |
| 101 |
needs: changed-files |
| 102 |
steps: |
| 103 |
- uses: actions/checkout@v5 |
| 104 |
- name: Install uv |
| 105 |
uses: astral-sh/[email protected] |
| 106 |
with: |
| 107 |
python-version: ${{ env.PYTHON_VERSION }} |
| 108 |
|
| 109 |
- name: Install Python tools |
| 110 |
run: uv tool install "poethepoet>=0.26,<0.47.0" |
| 111 |
|
| 112 |
- name: Install dependencies |
| 113 |
run: poe install --only-group typing |
| 114 |
|
| 115 |
- name: Type check code |
| 116 |
uses: liskin/gh-problem-matcher-wrap@v3 |
| 117 |
with: |
| 118 |
linters: mypy |
| 119 |
run: poe check-types --show-column-numbers --no-error-summary . |
| 120 |
|
| 121 |
docs: |
| 122 |
if: needs.changed-files.outputs.any_docs_changed == 'true' |
| 123 |
runs-on: ubuntu-latest |
| 124 |
name: Check docs |
| 125 |
needs: changed-files |
| 126 |
steps: |
| 127 |
- uses: actions/checkout@v5 |
| 128 |
with: |
| 129 |
fetch-depth: 0 # needed to get the full git history for the changelog check |
| 130 |
- name: Install uv |
| 131 |
uses: astral-sh/[email protected] |
| 132 |
with: |
| 133 |
python-version: ${{ env.PYTHON_VERSION }} |
| 134 |
|
| 135 |
- name: Install Python tools |
| 136 |
run: uv tool install "poethepoet>=0.26,<0.47.0" |
| 137 |
|
| 138 |
- name: Install dependencies |
| 139 |
run: poe install --group docs |
| 140 |
|
| 141 |
- name: Add Sphinx problem matchers |
| 142 |
run: | |
| 143 |
echo "::add-matcher::.github/problem-matchers/sphinx-build.json" |
| 144 |
echo "::add-matcher::.github/problem-matchers/sphinx-lint.json" |
| 145 |
|
| 146 |
- name: Check docs formatting |
| 147 |
run: poe format-docs --check |
| 148 |
|
| 149 |
- name: Lint docs |
| 150 |
run: poe lint-docs |
| 151 |
|
| 152 |
- name: Check changelog entries are added under Unreleased section |
| 153 |
run: | |
| 154 |
git diff --word-diff=plain -U1000 origin/${{ github.base_ref }} -- docs/changelog.rst | awk ' |
| 155 |
# match the new version header |
| 156 |
/^[0-9]+\.[0-9]+\.[0-9]+ \(/ { past_version=1 } |
| 157 |
# match a line that starts with a new changelog entry |
| 158 |
/^\{\+- / && past_version { |
| 159 |
# NR gives the line number. Subtract 5 to skip the first 5 lines that have git diff headers |
| 160 |
print "docs/changelog.rst:" NR - 5 ": Changelog entry must be added under Unreleased section above. (changelog-unreleased)"; exit 1 |
| 161 |
} |
| 162 |
' |
| 163 |
|
| 164 |
- name: Build docs |
| 165 |
run: poe docs -- -e 'SPHINXOPTS=--fail-on-warning --keep-going' |