-
Notifications
You must be signed in to change notification settings - Fork 30
251 lines (229 loc) · 8.49 KB
/
Copy pathmain.yml
File metadata and controls
251 lines (229 loc) · 8.49 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
name: Matrix Test
on:
push:
branches: [main, devel]
pull_request:
branches: [main, devel]
jobs:
run-if-changes:
runs-on: ubuntu-latest
outputs:
run: ${{ github.event_name == 'push' && 'true' || steps.filter.outputs.python }}
steps:
- uses: actions/checkout@v7
- uses: dorny/paths-filter@v4
id: filter
with:
filters: |
python:
- 'ultraplot/**'
- 'pyproject.toml'
- 'environment.yml'
- '.github/workflows/**'
- 'tools/ci/**'
select-tests:
runs-on: ubuntu-latest
needs:
- run-if-changes
if: always() && needs.run-if-changes.outputs.run == 'true'
outputs:
mode: ${{ steps.select.outputs.mode }}
tests: ${{ steps.select.outputs.tests }}
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Prepare workspace
run: mkdir -p .ci
- name: Restore test map cache
id: restore-map
uses: actions/cache/restore@v6
with:
path: .ci/test-map.json
key: test-map-${{ github.event.pull_request.base.sha }}
restore-keys: |
test-map-
- name: Build test map on cache miss
if: steps.restore-map.outputs.cache-hit != 'true'
uses: mamba-org/setup-micromamba@v3.2.1
with:
environment-file: ./environment.yml
init-shell: bash
create-args: >-
--verbose
python=3.10
matplotlib=3.9
cache-environment: true
cache-downloads: false
- name: Generate test map on cache miss
if: steps.restore-map.outputs.cache-hit != 'true'
shell: bash -el {0}
run: |
echo "Test map cache miss; generating map from tests."
pip install --no-build-isolation --no-deps .
mkdir -p .ci
pytest -q --tb=short --disable-warnings -n auto -p pytest_cov \
--cov=ultraplot --cov-branch --cov-context=test --cov-report= \
ultraplot/tests
python tools/ci/build_test_map.py --coverage-file .coverage --output .ci/test-map.json --root .
- name: Select impacted tests
id: select
run: |
if [ "${{ github.event_name }}" != "pull_request" ]; then
echo "mode=full" >> $GITHUB_OUTPUT
echo "tests=[]" >> $GITHUB_OUTPUT
exit 0
fi
git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} > .ci/changed.txt
echo "Changed files:"
cat .ci/changed.txt || true
echo "Test map exists:"
if [ -f .ci/test-map.json ]; then
echo "yes (size=$(wc -c < .ci/test-map.json))"
else
echo "no"
fi
python tools/ci/select_tests.py \
--map .ci/test-map.json \
--changed-files .ci/changed.txt \
--output .ci/selection.json \
--always-full 'pyproject.toml' \
--always-full 'environment.yml' \
--always-full 'ultraplot/__init__.py' \
--ignore 'docs/**' \
--ignore 'README.rst'
echo "Selection output:"
cat .ci/selection.json || true
python - <<'PY' > .ci/selection.out
import json
data = json.load(open(".ci/selection.json", "r", encoding="utf-8"))
print(f"mode={data['mode']}")
print("tests=" + json.dumps(data.get("tests", []), separators=(",", ":")))
PY
cat .ci/selection.out >> $GITHUB_OUTPUT
get-versions:
runs-on: ubuntu-latest
needs:
- run-if-changes
if: always() && needs.run-if-changes.outputs.run == 'true'
outputs:
python-versions: ${{ steps.set-versions.outputs.python-versions }}
matplotlib-versions: ${{ steps.set-versions.outputs.matplotlib-versions }}
test-matrix: ${{ steps.set-versions.outputs.test-matrix }}
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
- uses: actions/setup-python@v7
with:
python-version: "3.11"
- id: set-versions
run: |
OUTPUT=$(python tools/ci/version_support.py)
echo "Detected Python versions: $(echo "$OUTPUT" | jq -c '.python_versions')"
echo "Detected Matplotlib versions: $(echo "$OUTPUT" | jq -c '.matplotlib_versions')"
echo "Detected test matrix: $(echo "$OUTPUT" | jq -c '.test_matrix')"
python tools/ci/version_support.py --format github-output >> $GITHUB_OUTPUT
coverage:
name: Coverage Python ${{ matrix.python-version }} / MPL ${{ matrix.matplotlib-version }}
runs-on: ubuntu-latest
needs:
- run-if-changes
- get-versions
if: always() && needs.run-if-changes.outputs.run == 'true' && needs.get-versions.result == 'success' && github.event_name == 'pull_request'
strategy:
fail-fast: false
matrix:
include: ${{ fromJson(needs.get-versions.outputs.test-matrix) }}
defaults:
run:
shell: bash -el {0}
steps:
- name: Set up swap space
uses: pierotofy/set-swap-space@master
with:
swap-size-gb: 10
- uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Prepare compatible coverage environment
run: >-
python3 tools/ci/version_support.py
--matplotlib-version '${{ matrix.matplotlib-version }}'
--environment-output '${{ runner.temp }}/ultraplot-environment.yml'
- uses: mamba-org/setup-micromamba@v3.2.1
with:
environment-file: ${{ runner.temp }}/ultraplot-environment.yml
init-shell: bash
condarc-file: ./.github/micromamba-condarc.yml
post-cleanup: none
create-args: >-
--verbose
python=${{ matrix.python-version }}
matplotlib=${{ matrix.matplotlib-version }}
cache-environment: true
cache-downloads: false
- name: Build Ultraplot
run: |
pip install --no-build-isolation ".[mcp]"
- name: Run full coverage suite
run: |
python - <<'PY'
import sys
from importlib.metadata import version
import matplotlib, mpltern, pycirclize
assert sys.version_info[:2] == tuple(map(int, '${{ matrix.python-version }}'.split('.')))
assert matplotlib.__version__.startswith('${{ matrix.matplotlib-version }}.')
print('Python executable:', sys.executable)
for package in ('matplotlib', 'mpltern', 'pycirclize', 'cartopy'):
print(f'{package}: {version(package)}')
PY
pytest -q --tb=short --disable-warnings -n auto -p pytest_cov \
--cov=ultraplot --cov-branch --cov-context=test \
--cov-report=xml:coverage.xml --cov-report= \
ultraplot/tests
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v7
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage.xml
name: codecov-pr-python${{ matrix.python-version }}-mpl${{ matrix.matplotlib-version }}
build:
needs:
- get-versions
- run-if-changes
- select-tests
if: always() && needs.run-if-changes.outputs.run == 'true' && needs.get-versions.result == 'success' && needs.select-tests.result == 'success'
strategy:
matrix:
include: ${{ fromJson(needs.get-versions.outputs.test-matrix) }}
fail-fast: false
max-parallel: 4
uses: ./.github/workflows/build-ultraplot.yml
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ matrix.python-version }}-${{ matrix.matplotlib-version }}
cancel-in-progress: false
with:
python-version: ${{ matrix.python-version }}
matplotlib-version: ${{ matrix.matplotlib-version }}
test-mode: ${{ needs.select-tests.outputs.mode }}
test-nodeids: ${{ needs.select-tests.outputs.tests }}
build-success:
needs:
- build
- coverage
- run-if-changes
if: always()
runs-on: ubuntu-latest
steps:
- run: |
if [[ '${{ needs.run-if-changes.outputs.run }}' == 'false' ]]; then
echo "No changes detected, tests skipped."
else
if [[ '${{ needs.build.result }}' == 'success' && ( '${{ needs.coverage.result }}' == 'success' || '${{ needs.coverage.result }}' == 'skipped' ) ]]; then
echo "All tests passed successfully!"
else
echo "Tests failed!"
exit 1
fi
fi