-
Notifications
You must be signed in to change notification settings - Fork 321
165 lines (133 loc) · 5.71 KB
/
python-type-checking.yml
File metadata and controls
165 lines (133 loc) · 5.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
name: Python Type Checking
on:
pull_request:
branches: [main]
paths:
- 'src/Fable.Transforms/Python/**'
- 'src/fable-library-py/**'
- 'tests/Python/**'
- 'pyrightconfig.ci.json'
- 'pyproject.toml'
permissions:
contents: read
pull-requests: write
jobs:
pyright:
runs-on: ubuntu-latest
env:
UV_LINK_MODE: copy
steps:
- uses: actions/checkout@v5
- name: Setup .NET
uses: actions/setup-dotnet@v5
with:
dotnet-version: "10.0.x"
- name: Setup dotnet tools
run: dotnet tool restore
- name: Set up Python 3.12
uses: actions/setup-python@v6
with:
python-version: "3.12"
- name: Install uv
run: |
pipx install uv
pipx install maturin
- name: Build Python (compile only)
run: ./build.sh test python --compile-only
- name: Run Pyright and collect errors
id: pyright
continue-on-error: true
run: |
# Get excluded files from CI config
EXCLUDED_FILES=$(grep '"temp/' pyrightconfig.ci.json | sed 's/.*"\(temp[^"]*\)".*/\1/' | sort)
# Run pyright on all files (without CI excludes) and capture output
PYRIGHT_OUTPUT=$(uv run pyright temp/tests/Python/ temp/fable-library-py/ 2>&1 || true)
# Parse errors per file
ERROR_COUNTS=$(echo "$PYRIGHT_OUTPUT" | grep " - error:" | sed 's/:.*//g' | sed 's|.*/Fable/||' | sort | uniq -c | sort -rn)
# Calculate total errors
TOTAL_ERRORS=$(echo "$ERROR_COUNTS" | awk '{sum += $1} END {print sum+0}')
# Count files with errors
FILE_COUNT=$(echo "$ERROR_COUNTS" | grep -c '[0-9]' || echo "0")
# Check for new files with errors (not in exclude list)
NEW_FILES=""
HAS_NEW_ERRORS=false
while IFS= read -r line; do
if [ -n "$line" ]; then
FILE=$(echo "$line" | awk '{print $2}')
COUNT=$(echo "$line" | awk '{print $1}')
if ! echo "$EXCLUDED_FILES" | grep -q "^${FILE}$"; then
NEW_FILES="${NEW_FILES}| \`${FILE}\` | ${COUNT} | :warning: **NEW** |\n"
HAS_NEW_ERRORS=true
fi
fi
done <<< "$ERROR_COUNTS"
# Build error table for excluded files
EXCLUDED_TABLE=""
while IFS= read -r line; do
if [ -n "$line" ]; then
FILE=$(echo "$line" | awk '{print $2}')
COUNT=$(echo "$line" | awk '{print $1}')
if echo "$EXCLUDED_FILES" | grep -q "^${FILE}$"; then
EXCLUDED_TABLE="${EXCLUDED_TABLE}| \`${FILE}\` | ${COUNT} | Excluded |\n"
fi
fi
done <<< "$ERROR_COUNTS"
# Set outputs
echo "total_errors=$TOTAL_ERRORS" >> $GITHUB_OUTPUT
echo "file_count=$FILE_COUNT" >> $GITHUB_OUTPUT
echo "has_new_errors=$HAS_NEW_ERRORS" >> $GITHUB_OUTPUT
echo "new_files<<EOF" >> $GITHUB_OUTPUT
echo -e "$NEW_FILES" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
echo "excluded_table<<EOF" >> $GITHUB_OUTPUT
echo -e "$EXCLUDED_TABLE" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
# Run pyright with CI config to check if excluded files pass
if uv run pyright --project pyrightconfig.ci.json temp/tests/Python/ temp/fable-library-py/; then
echo "ci_passed=true" >> $GITHUB_OUTPUT
else
echo "ci_passed=false" >> $GITHUB_OUTPUT
fi
- name: Get excluded files count
id: excluded
run: |
COUNT=$(grep -c '"temp/' pyrightconfig.ci.json || echo "0")
echo "count=$COUNT" >> $GITHUB_OUTPUT
- name: Find existing comment
uses: peter-evans/find-comment@v3
id: find-comment
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: Python Type Checking
- name: Create or update PR comment
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ steps.find-comment.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
edit-mode: replace
body: |
## Python Type Checking Results (Pyright)
| Metric | Value |
|--------|-------|
| Total errors | ${{ steps.pyright.outputs.total_errors }} |
| Files with errors | ${{ steps.pyright.outputs.file_count }} |
| Excluded files | ${{ steps.excluded.outputs.count }} |
| New errors | ${{ steps.pyright.outputs.has_new_errors == 'true' && ':x: Yes' || ':white_check_mark: No' }} |
${{ steps.pyright.outputs.has_new_errors == 'true' && '### :warning: New Files with Errors
These files are NOT in the exclude list and must be fixed or added to `pyrightconfig.ci.json`:
| File | Errors | Status |
|------|--------|--------|' || '' }}
${{ steps.pyright.outputs.new_files }}
<details>
<summary>Excluded files with errors (${{ steps.excluded.outputs.count }} files)</summary>
These files have known type errors and are excluded from CI. Remove from `pyrightconfig.ci.json` as errors are fixed.
| File | Errors | Status |
|------|--------|--------|
${{ steps.pyright.outputs.excluded_table }}
</details>
- name: Fail if new errors
if: steps.pyright.outputs.has_new_errors == 'true'
run: |
echo "::error::New files with type errors detected! Either fix the errors or add them to pyrightconfig.ci.json"
exit 1