-
Notifications
You must be signed in to change notification settings - Fork 1
417 lines (376 loc) · 14.7 KB
/
ci-full.yml
File metadata and controls
417 lines (376 loc) · 14.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
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
name: Full Test Suite
on:
schedule:
# Run weekly on Sunday at 03:00 UTC
- cron: '0 3 * * 0'
workflow_dispatch:
inputs:
mode:
description: 'Test mode'
required: false
default: 'per-demo'
type: choice
options:
- per-demo
- per-module
demo:
description: 'Demo module to test (per-demo mode only)'
required: false
default: 'all'
type: choice
options:
- all
- spp_mis_demo_v2
- spp_drims_sl_demo
- spp_grm_demo
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
ODOO_ADDONS_PATH: /opt/odoo/odoo/addons,/opt/odoo/odoo/odoo/addons,/mnt/extra-addons/openspp,/mnt/extra-addons/server-ux,/mnt/extra-addons/server-tools,/mnt/extra-addons/odoo-job-worker,/mnt/extra-addons/server-backend,/mnt/extra-addons/rest-framework,/mnt/extra-addons/muk-it
jobs:
# ============================================================================
# Build Docker image (warms cache for test jobs)
# ============================================================================
build:
runs-on: [self-hosted, linux, x64, openspp]
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
buildkitd-config-inline: |
[registry."docker.io"]
mirrors = ["172.17.0.1:5000"]
[registry."172.17.0.1:5000"]
http = true
- name: Build and cache image
uses: docker/build-push-action@v5
with:
context: .
file: docker/Dockerfile
push: false
cache-from: type=gha
cache-to: type=gha,mode=max
# ============================================================================
# Discover modules (per-module mode only)
# ============================================================================
discover:
if: github.event.inputs.mode == 'per-module'
runs-on: [self-hosted, linux, x64, openspp]
outputs:
modules: ${{ steps.detect.outputs.modules }}
steps:
- uses: actions/checkout@v4
- name: Detect all testable modules
id: detect
run: |
modules=$(python3 scripts/detect_modules.py --all --output=matrix)
echo "modules=$modules" >> "$GITHUB_OUTPUT"
echo "Discovered modules: $modules"
# ============================================================================
# Full test suite per demo module (per-demo mode or schedule)
# ============================================================================
test:
needs: build
if: github.event.inputs.mode != 'per-module'
runs-on: [self-hosted, linux, x64, openspp]
strategy:
fail-fast: false
matrix:
include:
- demo: spp_mis_demo_v2
name: "SP-MIS Demo"
- demo: spp_drims_sl_demo
name: "DRIMS Sri Lanka Demo"
- demo: spp_grm_demo
name: "GRM Demo"
name: ${{ matrix.name }}
timeout-minutes: 60
services:
db:
image: postgis/postgis:18-3.6-alpine
env:
POSTGRES_USER: odoo
POSTGRES_PASSWORD: odoo
POSTGRES_DB: postgres
ports:
- 5432
options: >-
--health-cmd "pg_isready -U odoo -d postgres"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Check if should run
id: check
run: |
demo_input="${{ github.event.inputs.demo }}"
if [ -z "$demo_input" ] || [ "$demo_input" = "all" ] || [ "$demo_input" = "${{ matrix.demo }}" ]; then
echo "should_run=true" >> $GITHUB_OUTPUT
else
echo "should_run=false" >> $GITHUB_OUTPUT
fi
- uses: actions/checkout@v4
if: steps.check.outputs.should_run == 'true'
- name: Set up Docker Buildx
if: steps.check.outputs.should_run == 'true'
uses: docker/setup-buildx-action@v3
with:
buildkitd-config-inline: |
[registry."docker.io"]
mirrors = ["172.17.0.1:5000"]
[registry."172.17.0.1:5000"]
http = true
- name: Build test image (from cache)
if: steps.check.outputs.should_run == 'true'
uses: docker/build-push-action@v5
with:
context: .
file: docker/Dockerfile
load: true
tags: openspp-test:${{ github.sha }}
cache-from: type=gha
- name: Discover service network
if: steps.check.outputs.should_run == 'true'
id: net
env:
DB_PORT: ${{ job.services.db.ports[5432] }}
run: |
DB_CONTAINER=$(docker ps --filter "publish=$DB_PORT" --format '{{.ID}}' | head -1)
JOB_NETWORK=$(docker inspect "$DB_CONTAINER" --format '{{range $net, $_ := .NetworkSettings.Networks}}{{$net}} {{end}}' | tr ' ' '\n' | grep github_network | head -1)
echo "name=$JOB_NETWORK" >> "$GITHUB_OUTPUT"
echo "Using network: $JOB_NETWORK"
- name: Create test database
if: steps.check.outputs.should_run == 'true'
env:
DB_PORT: ${{ job.services.db.ports[5432] }}
run: |
PGPASSWORD=odoo psql -h localhost -p "$DB_PORT" -U odoo -d postgres -c "CREATE DATABASE test_${{ matrix.demo }};"
- name: Compute spp_* test tags
if: steps.check.outputs.should_run == 'true'
id: tags
run: |
# Build --test-tags for all spp_* modules that have tests
tags=""
for dir in spp_*/; do
module="${dir%/}"
if [ -f "$module/__manifest__.py" ] && [ -d "$module/tests" ]; then
if [ -n "$tags" ]; then
tags="$tags,/$module"
else
tags="/$module"
fi
fi
done
echo "test_tags=$tags" >> $GITHUB_OUTPUT
echo "Found test tags: $tags"
- name: Install demo and run all spp_* tests
if: steps.check.outputs.should_run == 'true'
id: test
run: |
# Run tests and capture output - don't fail on exit code
# (shutdown race conditions can cause exit code 1 even when tests pass)
set +e
docker run --rm \
--network ${{ steps.net.outputs.name }} \
-e DB_HOST=db \
-e DB_PORT=5432 \
-e DB_USER=odoo \
-e DB_PASSWORD=odoo \
-v ${{ github.workspace }}:/mnt/extra-addons/openspp:rw \
--user $(id -u):$(id -g) \
--entrypoint "" \
openspp-test:${{ github.sha }} \
/opt/odoo/odoo/odoo-bin \
--addons-path=${ODOO_ADDONS_PATH} \
-d test_${{ matrix.demo }} \
--db_host=db \
--db_port=5432 \
--db_user=odoo \
--db_password=odoo \
--stop-after-init \
--no-http \
--data-dir /tmp/odoo-data \
-i ${{ matrix.demo }} \
--test-tags=${{ steps.tags.outputs.test_tags }} \
--log-level=test \
2>&1 | tee test_output_${{ matrix.demo }}.log
DOCKER_EXIT=${PIPESTATUS[0]}
set -e
# Parse test results from output
RESULT_LINE=$(grep "failed.*error(s).*tests" test_output_${{ matrix.demo }}.log | tail -1 || true)
echo "Test result: $RESULT_LINE"
if [ -z "$RESULT_LINE" ]; then
echo "test_passed=false" >> $GITHUB_OUTPUT
echo "::error::Could not find test results in output for ${{ matrix.demo }}"
else
# Extract failed and error counts
FAILED=$(echo "$RESULT_LINE" | sed -E 's/.*([0-9]+) failed.*/\1/')
ERRORS=$(echo "$RESULT_LINE" | sed -E 's/.*([0-9]+) error.*/\1/')
echo "Failed: $FAILED, Errors: $ERRORS"
if [ "$FAILED" -gt 0 ] || [ "$ERRORS" -gt 0 ]; then
echo "test_passed=false" >> $GITHUB_OUTPUT
echo "::error::Tests failed for ${{ matrix.demo }}: $FAILED failed, $ERRORS errors"
else
echo "test_passed=true" >> $GITHUB_OUTPUT
echo "Tests passed (exit code $DOCKER_EXIT may be non-zero due to shutdown race conditions)"
fi
fi
timeout-minutes: 45
- name: Check test result
if: steps.check.outputs.should_run == 'true' && steps.test.outputs.test_passed != 'true'
run: |
echo "Tests failed for ${{ matrix.demo }}"
exit 1
- name: Cleanup database
if: always() && steps.check.outputs.should_run == 'true'
env:
DB_PORT: ${{ job.services.db.ports[5432] }}
run: |
PGPASSWORD=odoo psql -h localhost -p "$DB_PORT" -U odoo -d postgres -c "DROP DATABASE IF EXISTS test_${{ matrix.demo }};" || true
# ============================================================================
# Per-module test (per-module mode only)
# ============================================================================
test-per-module:
needs: [build, discover]
if: github.event.inputs.mode == 'per-module' && needs.discover.outputs.modules != '[]'
runs-on: [self-hosted, linux, x64, openspp]
strategy:
fail-fast: false
matrix:
module: ${{ fromJson(needs.discover.outputs.modules) }}
name: ${{ matrix.module }}
timeout-minutes: 30
services:
db:
image: postgis/postgis:18-3.6-alpine
env:
POSTGRES_USER: odoo
POSTGRES_PASSWORD: odoo
POSTGRES_DB: postgres
ports:
- 5432
options: >-
--health-cmd "pg_isready -U odoo -d postgres"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
buildkitd-config-inline: |
[registry."docker.io"]
mirrors = ["172.17.0.1:5000"]
[registry."172.17.0.1:5000"]
http = true
- name: Build test image (from cache)
uses: docker/build-push-action@v5
with:
context: .
file: docker/Dockerfile
load: true
tags: openspp-test:${{ github.sha }}
cache-from: type=gha
- name: Discover service network
id: net
env:
DB_PORT: ${{ job.services.db.ports[5432] }}
run: |
DB_CONTAINER=$(docker ps --filter "publish=$DB_PORT" --format '{{.ID}}' | head -1)
JOB_NETWORK=$(docker inspect "$DB_CONTAINER" --format '{{range $net, $_ := .NetworkSettings.Networks}}{{$net}} {{end}}' | tr ' ' '\n' | grep github_network | head -1)
echo "name=$JOB_NETWORK" >> "$GITHUB_OUTPUT"
echo "Using network: $JOB_NETWORK"
- name: Create test database
env:
DB_PORT: ${{ job.services.db.ports[5432] }}
run: |
PGPASSWORD=odoo psql -h localhost -p "$DB_PORT" -U odoo -d postgres -c "CREATE DATABASE test_${{ matrix.module }};"
- name: Install and test ${{ matrix.module }}
id: test
run: |
# Run tests and capture output - don't fail on exit code
# (shutdown race conditions can cause exit code 1 even when tests pass)
set +e
docker run --rm \
--network ${{ steps.net.outputs.name }} \
-e DB_HOST=db \
-e DB_PORT=5432 \
-e DB_USER=odoo \
-e DB_PASSWORD=odoo \
-v ${{ github.workspace }}:/mnt/extra-addons/openspp:rw \
--user $(id -u):$(id -g) \
--entrypoint "" \
openspp-test:${{ github.sha }} \
/opt/odoo/odoo/odoo-bin \
--addons-path=${ODOO_ADDONS_PATH} \
-d test_${{ matrix.module }} \
--db_host=db \
--db_port=5432 \
--db_user=odoo \
--db_password=odoo \
--stop-after-init \
--no-http \
--data-dir /tmp/odoo-data \
-i ${{ matrix.module }} \
--test-tags=/${{ matrix.module }} \
--log-level=test \
2>&1 | tee test_output_${{ matrix.module }}.log
DOCKER_EXIT=${PIPESTATUS[0]}
set -e
# Parse test results from output
RESULT_LINE=$(grep "failed.*error(s).*tests" test_output_${{ matrix.module }}.log | tail -1 || true)
echo "Test result: $RESULT_LINE"
if [ -z "$RESULT_LINE" ]; then
echo "test_passed=false" >> $GITHUB_OUTPUT
echo "::error::Could not find test results in output for ${{ matrix.module }}"
else
# Extract failed and error counts
FAILED=$(echo "$RESULT_LINE" | sed -E 's/.*([0-9]+) failed.*/\1/')
ERRORS=$(echo "$RESULT_LINE" | sed -E 's/.*([0-9]+) error.*/\1/')
echo "Failed: $FAILED, Errors: $ERRORS"
if [ "$FAILED" -gt 0 ] || [ "$ERRORS" -gt 0 ]; then
echo "test_passed=false" >> $GITHUB_OUTPUT
echo "::error::Tests failed for ${{ matrix.module }}: $FAILED failed, $ERRORS errors"
else
echo "test_passed=true" >> $GITHUB_OUTPUT
echo "Tests passed (exit code $DOCKER_EXIT may be non-zero due to shutdown race conditions)"
fi
fi
timeout-minutes: 20
- name: Check test result
if: steps.test.outputs.test_passed != 'true'
run: |
echo "Tests failed for ${{ matrix.module }}"
exit 1
- name: Cleanup database
if: always()
env:
DB_PORT: ${{ job.services.db.ports[5432] }}
run: |
PGPASSWORD=odoo psql -h localhost -p "$DB_PORT" -U odoo -d postgres -c "DROP DATABASE IF EXISTS test_${{ matrix.module }};" || true
# ============================================================================
# Summary
# ============================================================================
summary:
needs: [test, test-per-module]
if: always()
runs-on: [self-hosted, linux, x64, openspp]
steps:
- name: Test results
run: |
test_result="${{ needs.test.result }}"
per_module_result="${{ needs.test-per-module.result }}"
echo "per-demo result: $test_result"
echo "per-module result: $per_module_result"
# Check whichever job actually ran (the other will be 'skipped')
if [ "$test_result" = "failure" ] || [ "$per_module_result" = "failure" ]; then
echo "::error::Test suite failed!"
exit 1
elif [ "$test_result" = "success" ] || [ "$per_module_result" = "success" ]; then
echo "All tests passed!"
else
echo "Results - per-demo: $test_result, per-module: $per_module_result"
fi