9
9
steps :
10
10
- uses : actions/checkout@v3
11
11
with :
12
- fetch-depth : 0 # To get all history for git diff commands
13
-
12
+ fetch-depth : 0 # To get all history for git diff commands
13
+
14
14
- name : Get changed Python files
15
15
id : changed-files
16
16
run : |
31
31
CHANGED_FILES="$CHANGED_FILES $SETUP_PY_CHANGED"
32
32
fi
33
33
fi
34
-
34
+
35
35
# Check if any Python files were changed and set the output accordingly
36
36
if [ -z "$CHANGED_FILES" ]; then
37
37
echo "No Python files changed"
40
40
else
41
41
echo "Changed Python files: $CHANGED_FILES"
42
42
echo "has_python_changes=true" >> $GITHUB_OUTPUT
43
- echo "files=$CHANGED_FILES" >> $GITHUB_OUTPUT
43
+ # Use proper delimiter formatting for GitHub Actions
44
+ FILES_SINGLE_LINE=$(echo "$CHANGED_FILES" | tr '\n' ' ' | sed 's/[[:space:]]\+/ /g' | sed 's/^[[:space:]]*//' | sed 's/[[:space:]]*$//')
45
+ echo "files=$FILES_SINGLE_LINE" >> $GITHUB_OUTPUT
44
46
fi
45
-
47
+
46
48
- name : PR information
47
49
if : ${{ github.event_name == 'pull_request' }}
48
50
run : |
@@ -68,35 +70,35 @@ jobs:
68
70
echo "No Python files were changed. Skipping linting."
69
71
exit 0
70
72
fi
71
-
73
+
72
74
- uses : actions/checkout@v3
73
75
with :
74
76
fetch-depth : 0
75
-
77
+
76
78
- uses : actions/setup-python@v4
77
79
with :
78
80
python-version : 3.12
79
-
81
+
80
82
- uses : actions/cache@v3
81
83
with :
82
84
path : ~/.cache/pip
83
85
key : ${{ runner.os }}-pip-${{ hashFiles('requirements-dev.txt') }}
84
86
restore-keys : |
85
87
${{ runner.os }}-pip-
86
-
88
+
87
89
- name : Install dependencies
88
90
run : |
89
91
python -m pip install --upgrade pip
90
92
pip install -r requirements-dev.txt
91
-
93
+
92
94
# Flake8 linting
93
95
- name : Lint with flake8
94
96
if : ${{ matrix.tool == 'flake8' }}
95
97
id : flake8
96
98
run : |
97
99
echo "Linting files: ${{ needs.check_changes.outputs.files }}"
98
100
flake8 ${{ needs.check_changes.outputs.files }} --count --show-source --statistics
99
-
101
+
100
102
# Format checking with isort and black
101
103
- name : Format check
102
104
if : ${{ matrix.tool == 'format' }}
@@ -106,27 +108,27 @@ jobs:
106
108
isort --profile black --check ${{ needs.check_changes.outputs.files }}
107
109
echo "Checking format with black for: ${{ needs.check_changes.outputs.files }}"
108
110
black --check ${{ needs.check_changes.outputs.files }}
109
-
111
+
110
112
# Type checking with mypy
111
113
- name : Type check with mypy
112
114
if : ${{ matrix.tool == 'mypy' }}
113
115
id : mypy
114
116
run : |
115
117
echo "Type checking: ${{ needs.check_changes.outputs.files }}"
116
118
mypy --ignore-missing-imports ${{ needs.check_changes.outputs.files }}
117
-
119
+
118
120
# Run tests with pytest
119
121
- name : Run tests with pytest
120
122
if : ${{ matrix.tool == 'pytest' }}
121
123
id : pytest
122
124
run : |
123
125
echo "Running pytest discovery..."
124
126
python -m pytest --collect-only -v
125
-
127
+
126
128
# First run any test files that correspond to changed files
127
129
echo "Running tests for changed files..."
128
130
changed_files="${{ needs.check_changes.outputs.files }}"
129
-
131
+
130
132
# Extract module paths from changed files
131
133
modules=()
132
134
for file in $changed_files; do
@@ -137,13 +139,13 @@ jobs:
137
139
modules+=("$module_path")
138
140
fi
139
141
done
140
-
142
+
141
143
# Run tests for each module
142
144
for module in "${modules[@]}"; do
143
145
echo "Testing module: $module"
144
146
python -m pytest -xvs tests/ -k "$module" || true
145
147
done
146
-
148
+
147
149
# Then run doctests on the changed files
148
150
echo "Running doctests for changed files..."
149
151
for file in $changed_files; do
@@ -152,26 +154,26 @@ jobs:
152
154
python -m pytest --doctest-modules -v $file || true
153
155
fi
154
156
done
155
-
157
+
156
158
# Check Python version compatibility
157
159
- name : Check Python version compatibility
158
160
if : ${{ matrix.tool == 'pyupgrade' }}
159
161
id : pyupgrade
160
162
run : pyupgrade --py312-plus ${{ needs.check_changes.outputs.files }}
161
-
163
+
162
164
# Run tox
163
165
- name : Run tox
164
166
if : ${{ matrix.tool == 'tox' }}
165
167
id : tox
166
168
run : |
167
169
echo "Running tox integration for changed files..."
168
170
changed_files="${{ needs.check_changes.outputs.files }}"
169
-
171
+
170
172
# Create a temporary tox configuration that extends the original one
171
173
echo "[tox]" > tox_pr.ini
172
174
echo "envlist = py312" >> tox_pr.ini
173
175
echo "skip_missing_interpreters = true" >> tox_pr.ini
174
-
176
+
175
177
echo "[testenv]" >> tox_pr.ini
176
178
echo "setenv =" >> tox_pr.ini
177
179
echo " COVERAGE_FILE = .coverage.{envname}" >> tox_pr.ini
@@ -182,24 +184,24 @@ jobs:
182
184
echo " coverage" >> tox_pr.ini
183
185
echo " python" >> tox_pr.ini
184
186
echo "commands =" >> tox_pr.ini
185
-
187
+
186
188
# Check if we have any implementation files that changed
187
189
pattern_files=0
188
190
test_files=0
189
-
191
+
190
192
for file in $changed_files; do
191
193
if [[ $file == patterns/* ]]; then
192
194
pattern_files=1
193
195
elif [[ $file == tests/* ]]; then
194
196
test_files=1
195
197
fi
196
198
done
197
-
199
+
198
200
# Only run targeted tests, no baseline
199
201
echo " # Run specific tests for changed files" >> tox_pr.ini
200
-
202
+
201
203
has_tests=false
202
-
204
+
203
205
# Add coverage-focused test commands
204
206
for file in $changed_files; do
205
207
if [[ $file == *.py ]]; then
@@ -246,18 +248,18 @@ jobs:
246
248
fi
247
249
fi
248
250
done
249
-
251
+
250
252
# If we didn't find any specific tests to run, mention it
251
253
if [ "$has_tests" = false ]; then
252
254
echo " python -c \"print('No specific tests found for changed files. Consider adding tests.')\"" >> tox_pr.ini
253
255
# Add a minimal test to avoid failure, but ensure it generates coverage data
254
256
echo " coverage run -m pytest -xvs --cov=patterns --cov-append -k \"not integration\" --no-header" >> tox_pr.ini
255
257
fi
256
-
258
+
257
259
# Add coverage report command
258
260
echo " coverage combine" >> tox_pr.ini
259
261
echo " coverage report -m" >> tox_pr.ini
260
-
262
+
261
263
# Run tox with the custom configuration
262
264
echo "Running tox with custom PR configuration..."
263
265
echo "======================== TOX CONFIG ========================"
@@ -272,7 +274,7 @@ jobs:
272
274
runs-on : ubuntu-24.04
273
275
steps :
274
276
- uses : actions/checkout@v3
275
-
277
+
276
278
- name : Summarize results
277
279
run : |
278
280
echo "## Pull Request Lint Results" >> $GITHUB_STEP_SUMMARY
0 commit comments