Skip to content

Commit 3543211

Browse files
committed
Add check to prevent new errors
1 parent 73e6073 commit 3543211

File tree

2 files changed

+74
-2
lines changed

2 files changed

+74
-2
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: Mypy New Error Check
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
10+
jobs:
11+
mypy-diff:
12+
runs-on: ubuntu-latest
13+
strategy:
14+
matrix:
15+
python-version: ['3.10', '3.11', '3.12', '3.13',]
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 0
21+
22+
- name: Set up Python
23+
uses: actions/setup-python@v5
24+
with:
25+
python-version: ${{ matrix.python-version }}
26+
27+
- name: Install uv
28+
uses: astral-sh/setup-uv@v5
29+
30+
- name: Generate Baseline (Main)
31+
run: |
32+
# Switch to main branch to generate baseline
33+
git checkout origin/main
34+
35+
# Install dependencies for main
36+
uv venv .venv
37+
source .venv/bin/activate
38+
uv sync --all-extras
39+
40+
# Run mypy, filter for errors only, remove line numbers (file:123: -> file::), and sort
41+
# We ignore exit code (|| true) because we expect errors on main
42+
uv run mypy . | grep "error:" | sed 's/:\([0-9]\+\):/::/g' | sort > main_errors.txt || true
43+
44+
echo "Found $(wc -l < main_errors.txt) errors on main."
45+
46+
- name: Check PR Branch
47+
run: |
48+
# Switch back to the PR commit
49+
git checkout ${{ github.sha }}
50+
51+
# Re-sync dependencies in case the PR changed them
52+
source .venv/bin/activate
53+
uv sync --all-extras
54+
55+
# Run mypy on PR code, apply same processing
56+
uv run mypy . | grep "error:" | sed 's/:\([0-9]\+\):/::/g' | sort > pr_errors.txt || true
57+
58+
echo "Found $(wc -l < pr_errors.txt) errors on PR branch."
59+
60+
- name: Compare and Fail on New Errors
61+
run: |
62+
# 'comm -13' suppresses unique lines in file1 (main) and common lines,
63+
# leaving only lines unique to file2 (PR) -> The new errors.
64+
comm -13 main_errors.txt pr_errors.txt > new_errors.txt
65+
66+
if [ -s new_errors.txt ]; then
67+
echo "::error::The following NEW mypy errors were introduced:"
68+
cat new_errors.txt
69+
exit 1
70+
else
71+
echo "Great job! No new mypy errors introduced."
72+
fi

.github/workflows/mypy.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Mypy Static Type Check
1+
name: Mypy Type Check
22

33
on:
44
push:
@@ -11,7 +11,7 @@ jobs:
1111
runs-on: ubuntu-latest
1212
strategy:
1313
matrix:
14-
python-version: ['3.10', '3.11', '3.12', '3.13', '3.14']
14+
python-version: ['3.10', '3.11', '3.12', '3.13',]
1515

1616
steps:
1717
- uses: actions/checkout@v4

0 commit comments

Comments
 (0)