-
Notifications
You must be signed in to change notification settings - Fork 0
241 lines (203 loc) · 8.36 KB
/
ci-plottest.yml
File metadata and controls
241 lines (203 loc) · 8.36 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
name: "CI: Plot Tests"
run-name: "Plot Tests: ${{ github.head_ref }}"
on:
pull_request:
types: [ opened, synchronize, reopened ]
paths:
- 'plots/**/*.py'
- 'specs/**/*.md'
jobs:
test-plots:
name: Test Plots on Python ${{ matrix.python-version }}
runs-on: ubuntu-latest
permissions:
contents: read
strategy:
matrix:
python-version: [ '3.12', '3.13' ]
fail-fast: false
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
- name: Install uv
uses: astral-sh/setup-uv@v7
- name: Find changed plot files and detect libraries
id: detect_libs
run: |
# Get list of changed Python files in plots/
CHANGED_FILES=$(git diff --name-only origin/${{ github.base_ref }}...HEAD -- 'plots/**/*.py' || echo "")
if [ -z "$CHANGED_FILES" ]; then
echo "No plot files changed"
echo "has_plots=false" >> $GITHUB_OUTPUT
exit 0
fi
echo "has_plots=true" >> $GITHUB_OUTPUT
echo "files<<EOF" >> $GITHUB_OUTPUT
echo "$CHANGED_FILES" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
# Extract unique libraries from changed files (plots/{library}/...)
LIBRARIES=$(echo "$CHANGED_FILES" | sed -n 's|^plots/\([^/]*\)/.*|\1|p' | sort -u | tr '\n' ' ')
echo "libraries=$LIBRARIES" >> $GITHUB_OUTPUT
echo "Changed libraries: $LIBRARIES"
- name: Install library-specific dependencies
if: steps.detect_libs.outputs.has_plots == 'true'
run: |
# Build list of extras for all changed libraries
EXTRAS=""
for LIB in ${{ steps.detect_libs.outputs.libraries }}; do
EXTRAS="$EXTRAS --extra lib-${LIB}"
done
echo "📦 Installing: uv sync $EXTRAS"
uv sync $EXTRAS
- name: Setup Chrome for Selenium-based libraries
if: steps.detect_libs.outputs.has_plots == 'true' && (contains(steps.detect_libs.outputs.libraries, 'highcharts') || contains(steps.detect_libs.outputs.libraries, 'bokeh'))
uses: browser-actions/setup-chrome@v1
with:
chrome-version: stable
- name: Test plot execution
id: test_execution
if: steps.detect_libs.outputs.has_plots == 'true'
# Only Python 3.13 is required to pass - older versions are compatibility tests
continue-on-error: ${{ matrix.python-version != '3.13' }}
run: |
source .venv/bin/activate
echo "🧪 Testing plot files on Python ${{ matrix.python-version }}"
echo "📚 Libraries detected: ${{ steps.detect_libs.outputs.libraries }}"
FAILED=0
PASSED=0
while IFS= read -r file; do
if [ -z "$file" ]; then continue; fi
# Extract library from file path
LIB=$(echo "$file" | sed -n 's|^plots/\([^/]*\)/.*|\1|p')
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "📊 Testing: $file ($LIB)"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
# Run with non-interactive backend
if MPLBACKEND=Agg python "$file" 2>&1; then
echo "✅ PASSED: $file"
PASSED=$((PASSED + 1))
else
echo "❌ FAILED: $file"
FAILED=$((FAILED + 1))
fi
done <<< "${{ steps.detect_libs.outputs.files }}"
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "📋 Summary: $PASSED passed, $FAILED failed"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
# Save results for later aggregation
echo "passed=$PASSED" >> $GITHUB_OUTPUT
echo "failed=$FAILED" >> $GITHUB_OUTPUT
if [ $FAILED -gt 0 ]; then
echo "::error::$FAILED plot(s) failed execution on Python ${{ matrix.python-version }}"
exit 1
fi
- name: Skip message
if: steps.detect_libs.outputs.has_plots != 'true'
run: |
echo "ℹ️ No plot files changed in this PR - skipping tests"
- name: Save test results
if: always()
run: |
mkdir -p test-results
echo "${{ matrix.python-version }},${{ steps.test_execution.outcome || 'skipped' }}" > test-results/result-${{ matrix.python-version }}.txt
- name: Upload test results
if: always()
uses: actions/upload-artifact@v5
with:
name: test-results-${{ matrix.python-version }}
path: test-results/
retention-days: 30
# Summary job: post compact PR comment with test results
summary:
name: Post Test Summary
needs: test-plots
if: always()
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Download all test results
uses: actions/download-artifact@v6
with:
pattern: test-results-*
merge-multiple: true
- name: Build summary comment
id: summary
run: |
# Parse results
PY312_RESULT=$(cat result-3.12.txt 2>/dev/null | cut -d',' -f2 || echo "skipped")
PY313_RESULT=$(cat result-3.13.txt 2>/dev/null | cut -d',' -f2 || echo "skipped")
# Helper function for badge
badge() {
local version=$1
local result=$2
if [ "$result" == "success" ]; then
echo ""
elif [ "$result" == "failure" ]; then
echo ""
else
echo ""
fi
}
# Build comment - only 3.13 determines pass/fail status
if [ "$PY313_RESULT" == "success" ]; then
HEADER="## ✅ Plot Tests Passed"
MAIN_STATUS="**Python 3.13 (required):** passed"
elif [ "$PY313_RESULT" == "failure" ]; then
HEADER="## ❌ Plot Tests Failed"
MAIN_STATUS="**Python 3.13 (required):** failed"
else
HEADER="## ⏭️ Plot Tests Skipped"
MAIN_STATUS="No plot files changed"
fi
# Build badges
B312=$(badge "3.12" "$PY312_RESULT")
B313=$(badge "3.13" "$PY313_RESULT")
cat > /tmp/comment.md << EOF
${HEADER}
${MAIN_STATUS}
**Compatibility:** ${B312} ${B313}
_Note: Only Python 3.13 is required to pass. Python 3.12 is tested for compatibility._
EOF
cat /tmp/comment.md
echo "has_comment=true" >> $GITHUB_OUTPUT
- name: Post PR comment
if: steps.summary.outputs.has_comment == 'true'
uses: actions/github-script@v8
with:
script: |
const fs = require('fs');
const comment = fs.readFileSync('/tmp/comment.md', 'utf8');
// Find existing bot comment
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number
});
const botComment = comments.find(c =>
c.user.type === 'Bot' &&
c.body.includes('Plot Tests')
);
if (botComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: comment
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: comment
});
}