Lint code #37
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Lint check | |
| run-name: Lint code | |
| on: | |
| pull_request: | |
| push: | |
| branches: | |
| - master | |
| concurrency: | |
| # Cancel previous workflow run when a new commit is pushed to a feature branch | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} | |
| env: | |
| PYTHON_VERSION: "3.10" | |
| jobs: | |
| changed-files: | |
| runs-on: ubuntu-latest | |
| name: Get changed files | |
| outputs: | |
| any_docs_changed: ${{ steps.changed-doc-files.outputs.any_changed }} | |
| any_python_changed: ${{ steps.raw-changed-python-files.outputs.any_changed }} | |
| changed_doc_files: ${{ steps.changed-doc-files.outputs.all_changed_files }} | |
| changed_python_files: ${{ steps.changed-python-files.outputs.all_changed_files }} | |
| steps: | |
| - uses: actions/checkout@v5 | |
| - name: Get changed docs files | |
| id: changed-doc-files | |
| uses: tj-actions/changed-files@v46 | |
| with: | |
| files: | | |
| docs/** | |
| - name: Get changed python files | |
| id: raw-changed-python-files | |
| uses: tj-actions/changed-files@v46 | |
| with: | |
| files: | | |
| **.py | |
| uv.lock | |
| - name: Check changed python files | |
| id: changed-python-files | |
| env: | |
| CHANGED_PYTHON_FILES: ${{ steps.raw-changed-python-files.outputs.all_changed_files }} | |
| run: | | |
| if [[ " $CHANGED_PYTHON_FILES " == *" uv.lock "* ]]; then | |
| # if uv.lock is changed, we need to check everything | |
| CHANGED_PYTHON_FILES="." | |
| fi | |
| echo "all_changed_files=$CHANGED_PYTHON_FILES" >> "$GITHUB_OUTPUT" | |
| format: | |
| if: needs.changed-files.outputs.any_python_changed == 'true' | |
| runs-on: ubuntu-latest | |
| name: Check formatting | |
| needs: changed-files | |
| steps: | |
| - uses: actions/checkout@v5 | |
| - name: Setup Python with uv | |
| uses: astral-sh/setup-uv@v7 | |
| with: | |
| python-version: ${{ env.PYTHON_VERSION }} | |
| enable-cache: true | |
| - name: Install dependencies | |
| run: uv sync --locked --group lint | |
| - name: Check code formatting | |
| # the job output will contain colored diffs with what needs adjusting | |
| run: | | |
| source .venv/bin/activate | |
| poe check-format --output-format=github ${{ needs.changed-files.outputs.changed_python_files }} | |
| lint: | |
| if: needs.changed-files.outputs.any_python_changed == 'true' | |
| runs-on: ubuntu-latest | |
| name: Check linting | |
| needs: changed-files | |
| steps: | |
| - uses: actions/checkout@v5 | |
| - name: Setup Python with uv | |
| uses: astral-sh/setup-uv@v7 | |
| with: | |
| python-version: ${{ env.PYTHON_VERSION }} | |
| enable-cache: true | |
| - name: Install dependencies | |
| run: uv sync --locked --group lint | |
| - name: Lint code | |
| run: | | |
| source .venv/bin/activate | |
| poe lint --output-format=github ${{ needs.changed-files.outputs.changed_python_files }} | |
| mypy: | |
| if: needs.changed-files.outputs.any_python_changed == 'true' | |
| runs-on: ubuntu-latest | |
| name: Check types with mypy | |
| needs: changed-files | |
| steps: | |
| - uses: actions/checkout@v5 | |
| - name: Setup Python with uv | |
| uses: astral-sh/setup-uv@v7 | |
| with: | |
| python-version: ${{ env.PYTHON_VERSION }} | |
| enable-cache: true | |
| - name: Install dependencies | |
| run: uv sync --locked --group test | |
| - name: Type check code | |
| uses: liskin/gh-problem-matcher-wrap@v3 | |
| with: | |
| linters: mypy | |
| run: uv run poe check-types --show-column-numbers --no-error-summary . | |
| docs: | |
| if: needs.changed-files.outputs.any_docs_changed == 'true' | |
| runs-on: ubuntu-latest | |
| name: Check docs | |
| needs: changed-files | |
| steps: | |
| - uses: actions/checkout@v5 | |
| - name: Setup Python with uv | |
| uses: astral-sh/setup-uv@v7 | |
| with: | |
| python-version: ${{ env.PYTHON_VERSION }} | |
| enable-cache: true | |
| - name: Install dependencies | |
| run: uv sync --locked --extra docs --group lint | |
| - name: Add Sphinx problem matchers | |
| run: | | |
| echo "::add-matcher::.github/problem-matchers/sphinx-build.json" | |
| echo "::add-matcher::.github/problem-matchers/sphinx-lint.json" | |
| - name: Check docs formatting | |
| run: | | |
| source .venv/bin/activate | |
| poe format-docs --check | |
| - name: Lint docs | |
| run: | | |
| source .venv/bin/activate | |
| poe lint-docs | |
| - name: Build docs | |
| run: | | |
| source .venv/bin/activate | |
| poe docs -- -e 'SPHINXOPTS=--fail-on-warning --keep-going' |