-
Notifications
You must be signed in to change notification settings - Fork 18
334 lines (315 loc) · 13.9 KB
/
build-ultraplot.yml
File metadata and controls
334 lines (315 loc) · 13.9 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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
name: Build and Test
on:
workflow_call:
inputs:
python-version:
required: true
type: string
matplotlib-version:
required: true
type: string
test-mode:
required: false
type: string
default: full
test-nodeids:
required: false
type: string
default: ""
env:
LC_ALL: en_US.UTF-8
LANG: en_US.UTF-8
jobs:
build-ultraplot:
name: Test Python ${{ inputs.python-version }} with MPL ${{ inputs.matplotlib-version }}
runs-on: ubuntu-latest
timeout-minutes: 60
defaults:
run:
shell: bash -el {0}
env:
TEST_MODE: ${{ inputs.test-mode }}
TEST_NODEIDS: ${{ inputs.test-nodeids }}
PYTEST_WORKERS: 4
PYTHONHASHSEED: "0"
steps:
- name: Set up swap space
uses: pierotofy/set-swap-space@master
with:
swap-size-gb: 10
- name: Show system memory
run: |
echo "=== System Memory ==="
free -h
echo ""
echo "=== CPU Info ==="
nproc
cat /proc/cpuinfo | grep "model name" | head -1
- uses: actions/checkout@v6
with:
fetch-depth: 0
- uses: mamba-org/setup-micromamba@v2.0.7
with:
environment-file: ./environment.yml
init-shell: bash
condarc-file: ./.github/micromamba-condarc.yml
post-cleanup: none
create-args: >-
--verbose
python=${{ inputs.python-version }}
matplotlib=${{ inputs.matplotlib-version }}
cache-environment: true
cache-downloads: false
- name: Build Ultraplot
run: |
pip install --no-build-isolation --no-deps .
compare-baseline:
name: Compare baseline Python ${{ inputs.python-version }} with MPL ${{ inputs.matplotlib-version }}
runs-on: ubuntu-latest
continue-on-error: true
env:
IS_PR: ${{ github.event_name == 'pull_request' }}
TEST_MODE: ${{ inputs.test-mode }}
TEST_NODEIDS: ${{ inputs.test-nodeids }}
PYTEST_WORKERS: 4
PYTHONHASHSEED: "0"
defaults:
run:
shell: bash -el {0}
steps:
- name: Set up swap space
uses: pierotofy/set-swap-space@master
with:
swap-size-gb: 10
- name: Show system memory
run: |
echo "=== System Memory ==="
free -h
echo ""
echo "=== CPU Info ==="
nproc
cat /proc/cpuinfo | grep "model name" | head -1
- uses: actions/checkout@v6
- uses: mamba-org/setup-micromamba@v2.0.7
with:
environment-file: ./environment.yml
init-shell: bash
condarc-file: ./.github/micromamba-condarc.yml
post-cleanup: none
create-args: >-
--verbose
python=${{ inputs.python-version }}
matplotlib=${{ inputs.matplotlib-version }}
cache-environment: true
cache-downloads: false
- name: Resolve baseline reference
id: baseline-ref
run: |
if [ "${IS_PR}" = "true" ]; then
BASE_REF="${{ github.event.pull_request.base.ref }}"
git fetch origin "${BASE_REF}"
BASE_SHA="$(git rev-parse "origin/${BASE_REF}")"
else
BASE_REF="${GITHUB_REF_NAME:-main}"
BASE_SHA="${GITHUB_SHA}"
fi
echo "base_ref=${BASE_REF}" >> "${GITHUB_OUTPUT}"
echo "base_sha=${BASE_SHA}" >> "${GITHUB_OUTPUT}"
echo "Resolved baseline ref=${BASE_REF} sha=${BASE_SHA}"
# Cache Baseline Figures (Restore step)
- name: Cache Baseline Figures
id: cache-baseline
uses: actions/cache@v5
if: ${{ env.IS_PR }}
with:
path: ./ultraplot/tests/baseline # The directory to cache
# Key is based on OS, Python/Matplotlib versions, and the base commit SHA
key: ${{ runner.os }}-baseline-base-v5-hs${{ env.PYTHONHASHSEED }}-${{ steps.baseline-ref.outputs.base_sha }}-${{ inputs.python-version }}-${{ inputs.matplotlib-version }}
restore-keys: |
${{ runner.os }}-baseline-base-v5-hs${{ env.PYTHONHASHSEED }}-${{ steps.baseline-ref.outputs.base_sha }}-${{ inputs.python-version }}-${{ inputs.matplotlib-version }}-
# Conditional Baseline Generation (Only runs on cache miss)
- name: Generate baseline from main
# Skip this step if the cache was found (cache-hit is true)
if: steps.cache-baseline.outputs.cache-hit != 'true' || !env.IS_PR
run: |
mkdir -p ultraplot/tests/baseline
echo "TEST_MODE=${TEST_MODE}"
echo "IS_PR=${IS_PR}"
echo "PR_BASE_REF=${{ steps.baseline-ref.outputs.base_ref }}"
echo "PR_BASE_SHA=${{ steps.baseline-ref.outputs.base_sha }}"
echo "TEST_NODEIDS=${TEST_NODEIDS}"
# Save PR-selected nodeids for reuse after checkout (if provided)
if [ "${TEST_MODE}" = "selected" ] && [ -n "${TEST_NODEIDS}" ]; then
python -c 'import json,os; raw=os.environ.get("TEST_NODEIDS","").strip(); parsed=json.loads(raw) if raw and raw!="[]" else []; parsed=[parsed] if isinstance(parsed,str) else parsed; nodeids=[item for item in parsed if isinstance(item,str) and item]; open("/tmp/pr_selected_nodeids.txt","w",encoding="utf-8").write("".join(f"{nodeid}\n" for nodeid in nodeids)); print(f"Selected nodeids parsed: {len(nodeids)}")'
else
: > /tmp/pr_selected_nodeids.txt
fi
# Checkout the resolved base-branch tip for PR baseline generation.
if [ "${IS_PR}" = "true" ]; then
git checkout "${{ steps.baseline-ref.outputs.base_sha }}"
fi
# Install the Ultraplot version from the base branch's code
pip install --no-build-isolation --no-deps .
# Generate the baseline images and hash library
python -c "import ultraplot as plt; plt.config.Configurator()._save_yaml('ultraplot.yml')"
if [ "${TEST_MODE}" = "selected" ] && [ -s /tmp/pr_selected_nodeids.txt ]; then
status=0
FILTERED_NODEIDS=()
while IFS= read -r nodeid; do
if [ -z "$nodeid" ]; then
continue
fi
path="${nodeid%%::*}"
if [ -f "$path" ]; then
FILTERED_NODEIDS+=("$nodeid")
fi
done < /tmp/pr_selected_nodeids.txt
echo "FILTERED_NODEIDS_BASE_COUNT=${#FILTERED_NODEIDS[@]}"
if [ "${#FILTERED_NODEIDS[@]}" -eq 0 ]; then
echo "No valid nodeids found on base; skipping baseline generation."
else
echo "=== Memory before baseline generation ===" && free -h
pytest -n ${PYTEST_WORKERS} --dist loadfile --tb=short --disable-warnings -W ignore \
--mpl-generate-path=./ultraplot/tests/baseline/ \
--mpl-default-style="./ultraplot.yml" \
"${FILTERED_NODEIDS[@]}" || status=$?
echo "=== Memory after baseline generation ===" && free -h
if [ "$status" -eq 4 ] || [ "$status" -eq 5 ]; then
echo "No tests collected from selected nodeids on base; skipping baseline generation."
status=0
fi
fi
# Return to the PR branch before continuing
if [ "${IS_PR}" = "true" ]; then
echo "Checking out PR branch: ${{ github.sha }}"
git checkout ${{ github.sha }} || echo "Warning: git checkout failed, but continuing"
fi
if [ "$status" -ne 0 ]; then
echo "Baseline generation failed with status $status"
exit "$status"
fi
else
echo "=== Memory before baseline generation ===" && free -h
pytest -n ${PYTEST_WORKERS} --dist loadfile --tb=short --disable-warnings -W ignore \
--mpl-generate-path=./ultraplot/tests/baseline/ \
--mpl-default-style="./ultraplot.yml" \
ultraplot/tests
echo "=== Memory after baseline generation ===" && free -h
# Return to the PR branch for the rest of the job
if [ "${IS_PR}" = "true" ]; then
echo "Checking out PR branch: ${{ github.sha }}"
git checkout ${{ github.sha }} || echo "Warning: git checkout failed, but continuing"
fi
fi
# Image Comparison (Uses cached or newly generated baseline)
- name: Image Comparison Ultraplot
run: |
set -uo pipefail
# This workflow runs in a login shell (bash -el), which executes
# ~/.bash_logout on exit. Neutralize that file to prevent runner
# teardown commands (e.g. clear_console) from overriding step status.
if [ -f "${HOME}/.bash_logout" ]; then
cp "${HOME}/.bash_logout" "${HOME}/.bash_logout.bak" || true
: > "${HOME}/.bash_logout" || true
fi
# Re-install the Ultraplot version from the current PR branch
pip install --no-build-isolation --no-deps .
mkdir -p results
python -c "import ultraplot as plt; plt.config.Configurator()._save_yaml('ultraplot.yml')"
echo "TEST_MODE=${TEST_MODE}"
echo "TEST_NODEIDS=${TEST_NODEIDS}"
parse_junit_counts() {
python -c "import sys,xml.etree.ElementTree as ET; root=ET.parse(sys.argv[1]).getroot(); suites=[root] if root.tag=='testsuite' else root.findall('testsuite'); failures=sum(int(s.attrib.get('failures', 0)) for s in suites); errors=sum(int(s.attrib.get('errors', 0)) for s in suites); print(f'{failures} {errors}')" "$1" 2>/dev/null || echo "0 0"
}
if [ "${TEST_MODE}" = "selected" ] && [ -s /tmp/pr_selected_nodeids.txt ]; then
status=0
FILTERED_NODEIDS=()
while IFS= read -r nodeid; do
if [ -z "$nodeid" ]; then
continue
fi
path="${nodeid%%::*}"
if [ -f "$path" ]; then
FILTERED_NODEIDS+=("$nodeid")
fi
done < /tmp/pr_selected_nodeids.txt
echo "FILTERED_NODEIDS_PR_COUNT=${#FILTERED_NODEIDS[@]}"
if [ "${#FILTERED_NODEIDS[@]}" -eq 0 ]; then
echo "No valid nodeids found on PR branch; skipping image comparison."
exit 0
else
status=0
echo "=== Memory before image comparison ===" && free -h
set +e
pytest -n ${PYTEST_WORKERS} --dist loadfile --tb=short --disable-warnings -W ignore \
--mpl \
--mpl-baseline-path=./ultraplot/tests/baseline \
--mpl-results-path=./results/ \
--mpl-generate-summary=html \
--mpl-default-style="./ultraplot.yml" \
--junitxml=./results/junit.xml \
"${FILTERED_NODEIDS[@]}"
status=$?
echo "=== Memory after image comparison ===" && free -h
junit_failures=0
junit_errors=0
if [ -f ./results/junit.xml ]; then
junit_counts="$(parse_junit_counts ./results/junit.xml || echo '0 0')"
junit_failures="${junit_counts%% *}"
junit_errors="${junit_counts##* }"
fi
case "$junit_failures" in ''|*[!0-9]*) junit_failures=0 ;; esac
case "$junit_errors" in ''|*[!0-9]*) junit_errors=0 ;; esac
echo "pytest_status=$status junit_failures=$junit_failures junit_errors=$junit_errors"
if [ "$status" -ne 0 ] && [ "$junit_failures" -eq 0 ] && [ "$junit_errors" -eq 0 ]; then
echo "pytest exited with $status but junit reports no failures/errors; overriding exit status to 0."
status=0
fi
if [ "$status" -eq 4 ] || [ "$status" -eq 5 ]; then
echo "No tests collected from selected nodeids; skipping image comparison."
status=0
fi
fi
exit "$status"
else
status=0
echo "=== Memory before image comparison ===" && free -h
set +e
pytest -n ${PYTEST_WORKERS} --dist loadfile --tb=short --disable-warnings -W ignore \
--mpl \
--mpl-baseline-path=./ultraplot/tests/baseline \
--mpl-results-path=./results/ \
--mpl-generate-summary=html \
--mpl-default-style="./ultraplot.yml" \
--junitxml=./results/junit.xml \
ultraplot/tests
status=$?
echo "=== Memory after image comparison ===" && free -h
junit_failures=0
junit_errors=0
if [ -f ./results/junit.xml ]; then
junit_counts="$(parse_junit_counts ./results/junit.xml || echo '0 0')"
junit_failures="${junit_counts%% *}"
junit_errors="${junit_counts##* }"
fi
case "$junit_failures" in ''|*[!0-9]*) junit_failures=0 ;; esac
case "$junit_errors" in ''|*[!0-9]*) junit_errors=0 ;; esac
echo "pytest_status=$status junit_failures=$junit_failures junit_errors=$junit_errors"
if [ "$status" -ne 0 ] && [ "$junit_failures" -eq 0 ] && [ "$junit_errors" -eq 0 ]; then
echo "pytest exited with $status but junit reports no failures/errors; overriding exit status to 0."
status=0
fi
if [ "$status" -eq 4 ] || [ "$status" -eq 5 ]; then
echo "No tests collected; skipping image comparison."
status=0
fi
exit "$status"
fi
# Return the html output of the comparison even if failed
- name: Upload comparison failures
if: always()
uses: actions/upload-artifact@v7
with:
name: failed-comparisons-${{ inputs.python-version }}-${{ inputs.matplotlib-version }}-${{ github.sha }}
path: results/*
if-no-files-found: ignore