|
1 | 1 | name: Type Check |
2 | 2 |
|
3 | 3 | on: |
4 | | - # Trigger the workflow on push or pull request, but only for the main branch. |
5 | | - # Don't use pull_request.paths filter since this workflow is required for |
6 | | - # all pull requests on main irrespective of file type or location. |
| 4 | + # Don't use `paths` or `paths-ignore` filter since this workflow is required |
| 5 | + # for all pull requests on main irrespective of file type or location |
| 6 | + # Use `changed-src-files` step to determine if source code was changed |
7 | 7 | pull_request: |
8 | 8 | branches: |
9 | 9 | - main |
10 | 10 | push: |
11 | 11 | branches: |
12 | 12 | - main |
13 | | - paths: |
14 | | - - '**/*.py' |
15 | | - - '.github/workflows/type_check.yaml' |
16 | | - - 'tools/type_check.sh' |
17 | | - - 'pyproject.toml' |
18 | 13 |
|
19 | 14 | jobs: |
20 | 15 | type-check: |
21 | 16 | runs-on: ubuntu-latest |
22 | 17 | strategy: |
23 | 18 | matrix: |
24 | | - python-version: ["3.9", "3.10", "3.11", "3.12"] |
| 19 | + python-version: ["3.10", "3.11", "3.12"] |
25 | 20 | steps: |
26 | | - - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
27 | | - - name: Set up Python ${{ matrix.python-version }} |
28 | | - uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0 |
| 21 | + - name: "Checkout" |
| 22 | + uses: actions/checkout@v4 |
| 23 | + |
| 24 | + - name: "Get changed source files" |
| 25 | + id: changed-src-files |
| 26 | + uses: tj-actions/changed-files@v46 |
| 27 | + with: # Avoid using single or double quotes for multiline patterns |
| 28 | + files: | |
| 29 | + .github/workflows/type_check.yaml |
| 30 | + tools/type_check.sh |
| 31 | + pyproject.toml |
| 32 | + **.py |
| 33 | +
|
| 34 | + - name: "Set up Python ${{ matrix.python-version }}" |
| 35 | + if: steps.changed-src-files.outputs.any_changed == 'true' |
| 36 | + uses: astral-sh/setup-uv@v5 |
29 | 37 | with: |
30 | 38 | python-version: ${{ matrix.python-version }} |
31 | | - - name: Install dependencies |
32 | | - run: | |
33 | | - # TODO: use `uv` |
34 | | - python -m pip install --upgrade pip |
35 | | - pip install mypy==1.11.1 |
36 | | - pip install types-setuptools |
37 | | - pip install types-PyYAML |
38 | | - pip install types-requests |
39 | | - pip install types-setuptools |
40 | | - - name: Mypy |
| 39 | + enable-cache: true |
| 40 | + ignore-nothing-to-cache: true |
| 41 | + cache-dependency-glob: | |
| 42 | + pyproject.toml |
| 43 | +
|
| 44 | + - name: "Install dependencies" |
| 45 | + if: steps.changed-src-files.outputs.any_changed == 'true' |
| 46 | + run: uv sync --frozen --only-group lint |
| 47 | + |
| 48 | + - name: "Run mypy" |
| 49 | + if: steps.changed-src-files.outputs.any_changed == 'true' |
41 | 50 | run: | |
42 | 51 | echo "::add-matcher::.github/workflows/matchers/mypy.json" |
43 | 52 | tools/type_check.sh 1 ${{ matrix.python-version }} |
0 commit comments