Debian Codegraph @

.github/workflows/lint.yaml

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