Skip to content

Commit 810fcec

Browse files
committed
[Python] improve type checking in CI
1 parent ba03f4a commit 810fcec

File tree

1 file changed

+81
-22
lines changed

1 file changed

+81
-22
lines changed

.github/workflows/python-type-checking.yml

Lines changed: 81 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -44,27 +44,76 @@ jobs:
4444
- name: Build Python (compile only)
4545
run: ./build.sh test python --compile-only
4646

47-
- name: Run Pyright (standard mode)
47+
- name: Run Pyright and collect errors
4848
id: pyright
4949
continue-on-error: true
5050
run: |
51+
# Get excluded files from CI config
52+
EXCLUDED_FILES=$(grep '"temp/' pyrightconfig.ci.json | sed 's/.*"\(temp[^"]*\)".*/\1/' | sort)
53+
54+
# Run pyright on all files (without CI excludes) and capture output
55+
PYRIGHT_OUTPUT=$(uv run pyright temp/tests/Python/ temp/fable-library-py/ 2>&1 || true)
56+
57+
# Parse errors per file
58+
ERROR_COUNTS=$(echo "$PYRIGHT_OUTPUT" | grep " - error:" | sed 's/:.*//g' | sed 's|.*/Fable/||' | sort | uniq -c | sort -rn)
59+
60+
# Calculate total errors
61+
TOTAL_ERRORS=$(echo "$ERROR_COUNTS" | awk '{sum += $1} END {print sum+0}')
62+
63+
# Count files with errors
64+
FILE_COUNT=$(echo "$ERROR_COUNTS" | grep -c '[0-9]' || echo "0")
65+
66+
# Check for new files with errors (not in exclude list)
67+
NEW_FILES=""
68+
HAS_NEW_ERRORS=false
69+
while IFS= read -r line; do
70+
if [ -n "$line" ]; then
71+
FILE=$(echo "$line" | awk '{print $2}')
72+
COUNT=$(echo "$line" | awk '{print $1}')
73+
if ! echo "$EXCLUDED_FILES" | grep -q "^${FILE}$"; then
74+
NEW_FILES="${NEW_FILES}| \`${FILE}\` | ${COUNT} | :warning: **NEW** |\n"
75+
HAS_NEW_ERRORS=true
76+
fi
77+
fi
78+
done <<< "$ERROR_COUNTS"
79+
80+
# Build error table for excluded files
81+
EXCLUDED_TABLE=""
82+
while IFS= read -r line; do
83+
if [ -n "$line" ]; then
84+
FILE=$(echo "$line" | awk '{print $2}')
85+
COUNT=$(echo "$line" | awk '{print $1}')
86+
if echo "$EXCLUDED_FILES" | grep -q "^${FILE}$"; then
87+
EXCLUDED_TABLE="${EXCLUDED_TABLE}| \`${FILE}\` | ${COUNT} | Excluded |\n"
88+
fi
89+
fi
90+
done <<< "$ERROR_COUNTS"
91+
92+
# Set outputs
93+
echo "total_errors=$TOTAL_ERRORS" >> $GITHUB_OUTPUT
94+
echo "file_count=$FILE_COUNT" >> $GITHUB_OUTPUT
95+
echo "has_new_errors=$HAS_NEW_ERRORS" >> $GITHUB_OUTPUT
96+
97+
echo "new_files<<EOF" >> $GITHUB_OUTPUT
98+
echo -e "$NEW_FILES" >> $GITHUB_OUTPUT
99+
echo "EOF" >> $GITHUB_OUTPUT
100+
101+
echo "excluded_table<<EOF" >> $GITHUB_OUTPUT
102+
echo -e "$EXCLUDED_TABLE" >> $GITHUB_OUTPUT
103+
echo "EOF" >> $GITHUB_OUTPUT
104+
105+
# Run pyright with CI config to check if excluded files pass
51106
if uv run pyright --project pyrightconfig.ci.json temp/tests/Python/ temp/fable-library-py/; then
52-
echo "result=:white_check_mark: All non-excluded files pass" >> $GITHUB_OUTPUT
53-
echo "passed=true" >> $GITHUB_OUTPUT
107+
echo "ci_passed=true" >> $GITHUB_OUTPUT
54108
else
55-
echo "result=:x: Type errors found in non-excluded files" >> $GITHUB_OUTPUT
56-
echo "passed=false" >> $GITHUB_OUTPUT
109+
echo "ci_passed=false" >> $GITHUB_OUTPUT
57110
fi
58111
59-
- name: Get excluded files
112+
- name: Get excluded files count
60113
id: excluded
61114
run: |
62115
COUNT=$(grep -c '"temp/' pyrightconfig.ci.json || echo "0")
63116
echo "count=$COUNT" >> $GITHUB_OUTPUT
64-
FILES=$(grep '"temp/' pyrightconfig.ci.json | sed 's/.*"temp/temp/' | sed 's/".*//' | sort)
65-
echo "files<<EOF" >> $GITHUB_OUTPUT
66-
echo "$FILES" >> $GITHUB_OUTPUT
67-
echo "EOF" >> $GITHUB_OUTPUT
68117
69118
- name: Find existing comment
70119
uses: peter-evans/find-comment@v3
@@ -83,24 +132,34 @@ jobs:
83132
body: |
84133
## Python Type Checking Results (Pyright)
85134
86-
${{ steps.pyright.outputs.result }}
87-
88-
| Metric | Value |
89-
| -------------- | ----------------------------------- |
135+
| Metric | Value |
136+
|--------|-------|
137+
| Total errors | ${{ steps.pyright.outputs.total_errors }} |
138+
| Files with errors | ${{ steps.pyright.outputs.file_count }} |
90139
| Excluded files | ${{ steps.excluded.outputs.count }} |
140+
| New errors | ${{ steps.pyright.outputs.has_new_errors == 'true' && ':x: Yes' || ':white_check_mark: No' }} |
141+
142+
${{ steps.pyright.outputs.has_new_errors == 'true' && '### :warning: New Files with Errors
143+
144+
These files are NOT in the exclude list and must be fixed or added to `pyrightconfig.ci.json`:
145+
146+
| File | Errors | Status |
147+
|------|--------|--------|' || '' }}
148+
${{ steps.pyright.outputs.new_files }}
91149
92150
<details>
93-
<summary>Files excluded from type checking</summary>
151+
<summary>Excluded files with errors (${{ steps.excluded.outputs.count }} files)</summary>
94152
95153
These files have known type errors and are excluded from CI. Remove from `pyrightconfig.ci.json` as errors are fixed.
96154
97-
```
98-
${{ steps.excluded.outputs.files }}
99-
```
155+
| File | Errors | Status |
156+
|------|--------|--------|
157+
${{ steps.pyright.outputs.excluded_table }}
100158
101159
</details>
102160
103-
- name: Fail if type errors
104-
if: false # Temporarily disabled
105-
# if: steps.pyright.outputs.passed == 'false'
106-
run: exit 1
161+
- name: Fail if new errors
162+
if: steps.pyright.outputs.has_new_errors == 'true'
163+
run: |
164+
echo "::error::New files with type errors detected! Either fix the errors or add them to pyrightconfig.ci.json"
165+
exit 1

0 commit comments

Comments
 (0)