forked from gramps-project/addons-source
-
Notifications
You must be signed in to change notification settings - Fork 0
388 lines (364 loc) · 13.7 KB
/
Copy pathci.yml
File metadata and controls
388 lines (364 loc) · 13.7 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
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
name: CI
on:
push:
branches: [maintenance/gramps**]
pull_request:
branches: [maintenance/gramps**]
jobs:
# -----------------------------------------------------------------
# Setup — derive the branch suffix (gramps60 / gramps61 / …) from
# the ref. On push events github.ref_name is the branch being
# pushed; on pull_request events github.base_ref is the target
# branch. Either way the suffix is what follows "maintenance/".
# -----------------------------------------------------------------
setup:
name: Setup
runs-on: ubuntu-latest
outputs:
branch_suffix: ${{ steps.compute.outputs.branch_suffix }}
ci_image: ${{ steps.compute.outputs.ci_image }}
steps:
- id: compute
shell: bash
run: |
ref="${{ github.base_ref || github.ref_name }}"
suffix="${ref#maintenance/}"
case "$suffix" in
gramps[0-9][0-9]) ;;
*) echo "::error::unexpected ref '$ref' (suffix '$suffix')"; exit 1 ;;
esac
echo "branch_suffix=$suffix" >> "$GITHUB_OUTPUT"
echo "ci_image=ghcr.io/${{ github.repository }}/gramps-ci:$suffix" >> "$GITHUB_OUTPUT"
# -----------------------------------------------------------------
# Lint (ci container)
# -----------------------------------------------------------------
lint:
name: Lint
needs: setup
runs-on: ubuntu-latest
# Non-blocking until the existing ruff E9/F63/F7/F82 errors across the
# addon set are cleaned up in a follow-up PR. Flip this off in that PR.
continue-on-error: true
container:
image: ${{ needs.setup.outputs.ci_image }}
steps:
- uses: actions/checkout@v4
- name: Run ruff (syntax and import errors only)
run: ruff check --select=E9,F63,F7,F82 --no-fix --exclude='*.gpr.py' .
- name: Check trailing whitespace in Python files
run: |
if git --no-pager grep --color -n --full-name '[ \t]$' -- '*.py'; then
echo "::error::Trailing whitespace found in Python files"
exit 1
fi
# -----------------------------------------------------------------
# Addon structure (bare runner — just bash, no deps needed)
# -----------------------------------------------------------------
addon-structure:
name: Addon Structure
runs-on: ubuntu-latest
# Non-blocking until the four addons missing po/template.pot are fixed
# in a follow-up PR. Flip this off in that PR.
continue-on-error: true
steps:
- uses: actions/checkout@v4
- name: Check all addons have po/template.pot
run: |
failed=0
for gpr in */*.gpr.py; do
addon_dir="$(dirname "$gpr")"
if [ ! -d "$addon_dir/po" ]; then
echo "::error::$addon_dir is missing po/ directory"
failed=1
elif [ ! -f "$addon_dir/po/template.pot" ]; then
echo "::error::$addon_dir is missing po/template.pot"
failed=1
fi
done
if [ "$failed" -eq 0 ]; then
echo "All addons have po/template.pot"
fi
exit $failed
# -----------------------------------------------------------------
# Compile check (ci container)
# -----------------------------------------------------------------
compile-check:
name: Compile Check
needs: setup
runs-on: ubuntu-latest
container:
image: ${{ needs.setup.outputs.ci_image }}
steps:
- uses: actions/checkout@v4
- name: Compile all Python files (excluding .gpr.py)
shell: bash
run: |
failed=0
while IFS= read -r f; do
if ! python3 -m py_compile "$f" 2>&1; then
failed=1
fi
done < <(find . -name '*.py' ! -name '*.gpr.py' ! -path './.git/*' ! -path '*/__pycache__/*')
exit $failed
# -----------------------------------------------------------------
# Unit tests — Linux (ci container)
# -----------------------------------------------------------------
unit-test-linux:
name: Unit Tests (Linux)
needs: setup
runs-on: ubuntu-latest
# Non-blocking until the currently-broken addon unit modules (import
# failures, stale API usage) are sorted out in follow-up PRs.
continue-on-error: true
container:
image: ${{ needs.setup.outputs.ci_image }}
steps:
- uses: actions/checkout@v4
- name: Install addon runtime deps (derived from requires_mod)
# Auto-derive the union of requires_mod across every .gpr.py in
# the repo. Mirrors Gramps' Addon Manager install path
# (gramps/gui/plug/_windows.py __on_install_clicked → req.install →
# gen/utils/requirements.py). Keeps .gpr.py files as the single
# source of truth for addon deps — no parallel list to maintain
# in the image or workflow. Best-effort: a package needing exotic
# system deps (pygraphviz → graphviz-dev, psycopg2 → libpq-dev)
# may fail here; the affected addon's tests will skip or fail in
# isolation without blocking the rest.
shell: bash
run: |
addon_mods=$(python3 - <<'PY'
import ast, glob, re
pat = re.compile(r"requires_mod\s*=\s*(\[[^\]]*\])")
mods = set()
for f in glob.glob("*/*.gpr.py"):
try:
text = open(f, encoding="utf-8").read()
except OSError:
continue
for m in pat.finditer(text):
try:
mods.update(ast.literal_eval(m.group(1)))
except (ValueError, SyntaxError):
pass
print(" ".join(sorted(mods)))
PY
)
if [ -n "$addon_mods" ]; then
echo "→ addon deps: $addon_mods"
for mod in $addon_mods; do
pip install "$mod" || echo "× $mod failed to install (continuing)"
done
else
echo "no requires_mod declarations found"
fi
- name: Run per-addon unit tests
# Filename convention (all OSes):
# test_*.py — general (any OS)
# test_linux_*.py — Linux-only
# test_windows_*.py — Windows-only
# test_integration_*.py — Linux-only, full-pipeline/DB-backed
# The Linux job runs test_*.py except the Windows-only and
# integration buckets. Integration tests run in their own job.
#
# shell: bash — the container's default shell is /bin/sh
# (dash on python:3.12-slim), which does not support the
# ${var//pattern/repl} and ${var%.py} parameter expansions
# used below. Falls silently under continue-on-error.
shell: bash
env:
PYTHONPATH: .
run: |
modules=""
for f in */tests/test_*.py; do
[ -f "$f" ] || continue
case "$(basename "$f")" in
test_integration*) continue ;;
test_windows_*) continue ;;
esac
case "$f" in
Sqlite/tests/test_sqlite.py) continue ;;
esac
mod="${f%.py}"
mod="${mod//\//.}"
modules="$modules $mod"
done
if [ -n "$modules" ]; then
echo "Running unit tests:$modules"
python3 -m unittest -v $modules
else
echo "No per-addon unit test modules found"
fi
# -----------------------------------------------------------------
# Unit tests — Windows (conda-forge: bundles PyGObject + GTK + Gramps)
# -----------------------------------------------------------------
unit-test-windows:
name: Unit Tests (Windows)
runs-on: windows-latest
# Non-blocking for the same reason as unit-test-linux.
continue-on-error: true
defaults:
run:
shell: bash -el {0}
steps:
- uses: actions/checkout@v4
- name: Set up Miniforge
uses: conda-incubator/setup-miniconda@v3
with:
miniforge-version: latest
activate-environment: addons-ci
environment-file: .github/environment.yml
use-mamba: true
- name: Verify environment
run: |
mamba info
mamba list | head -30
python -c "import gramps, gi; print('deps OK')"
- name: Install addon runtime deps (derived from requires_mod)
# See unit-test-linux for rationale. Uses `python` (conda-forge
# env) to match the surrounding Windows job style.
run: |
addon_mods=$(python - <<'PY'
import ast, glob, re
pat = re.compile(r"requires_mod\s*=\s*(\[[^\]]*\])")
mods = set()
for f in glob.glob("*/*.gpr.py"):
try:
text = open(f, encoding="utf-8").read()
except OSError:
continue
for m in pat.finditer(text):
try:
mods.update(ast.literal_eval(m.group(1)))
except (ValueError, SyntaxError):
pass
print(" ".join(sorted(mods)))
PY
)
if [ -n "$addon_mods" ]; then
echo "→ addon deps: $addon_mods"
for mod in $addon_mods; do
pip install "$mod" || echo "× $mod failed to install (continuing)"
done
else
echo "no requires_mod declarations found"
fi
- name: Run per-addon unit tests
# See filename-convention note in unit-test-linux. The Windows
# job runs test_*.py except test_linux_* and test_integration_*.
env:
PYTHONPATH: .
run: |
modules=""
for f in */tests/test_*.py; do
[ -f "$f" ] || continue
case "$(basename "$f")" in
test_integration*) continue ;;
test_linux_*) continue ;;
esac
case "$f" in
Sqlite/tests/test_sqlite.py) continue ;;
esac
mod="${f%.py}"
mod="${mod//\//.}"
modules="$modules $mod"
done
if [ -n "$modules" ]; then
echo "Running unit tests:$modules"
python -m unittest -v $modules
else
echo "No per-addon unit test modules found"
fi
# -----------------------------------------------------------------
# Integration tests — Gramps (ci container, xvfb available)
# -----------------------------------------------------------------
integration-test:
name: Integration Tests (Gramps)
runs-on: ubuntu-latest
needs: [setup, unit-test-linux]
container:
image: ${{ needs.setup.outputs.ci_image }}
options: --init
steps:
- uses: actions/checkout@v4
- name: Install addon runtime deps (derived from requires_mod)
# See unit-test-linux for rationale. The plugin registration test
# subprocess-loads each addon's module, which imports its
# requires_mod packages.
shell: bash
run: |
addon_mods=$(python3 - <<'PY'
import ast, glob, re
pat = re.compile(r"requires_mod\s*=\s*(\[[^\]]*\])")
mods = set()
for f in glob.glob("*/*.gpr.py"):
try:
text = open(f, encoding="utf-8").read()
except OSError:
continue
for m in pat.finditer(text):
try:
mods.update(ast.literal_eval(m.group(1)))
except (ValueError, SyntaxError):
pass
print(" ".join(sorted(mods)))
PY
)
if [ -n "$addon_mods" ]; then
echo "→ addon deps: $addon_mods"
for mod in $addon_mods; do
pip install "$mod" || echo "× $mod failed to install (continuing)"
done
else
echo "no requires_mod declarations found"
fi
- name: Run plugin registration tests
# shell: bash for consistency with the surrounding steps; the
# current command uses no bashisms, but keeps this block safe
# against future edits. Container default is /bin/sh → dash.
shell: bash
env:
PYTHONPATH: .
run: python3 -m unittest discover -s tests -p "test_*.py" -t . -v
- name: Run per-addon integration tests
# shell: bash — see unit-test-linux for rationale; the
# ${var//pattern/repl} and ${var%.py} expansions below are
# bash-only.
shell: bash
env:
PYTHONPATH: .
run: |
modules=""
for f in */tests/test_integration*.py; do
[ -f "$f" ] || continue
mod="${f%.py}"
mod="${mod//\//.}"
modules="$modules $mod"
done
if [ -n "$modules" ]; then
echo "Running per-addon integration tests:$modules"
python3 -m unittest -v $modules
else
echo "No per-addon integration test modules found"
fi
# -----------------------------------------------------------------
# Build (ci container)
# -----------------------------------------------------------------
build:
name: Build
needs: setup
runs-on: ubuntu-latest
container:
image: ${{ needs.setup.outputs.ci_image }}
steps:
- uses: actions/checkout@v4
- name: Determine GRAMPSPATH
id: gramps-path
run: |
GPATH=$(python3 -c "import gramps, os; print(os.path.dirname(os.path.dirname(gramps.__file__)))")
echo "path=$GPATH" >> "$GITHUB_OUTPUT"
- name: Build all addons
env:
GRAMPSPATH: ${{ steps.gramps-path.outputs.path }}
run: |
mkdir -p ../download
python3 make.py "${{ needs.setup.outputs.branch_suffix }}" build all