-
Notifications
You must be signed in to change notification settings - Fork 1
538 lines (478 loc) · 16.8 KB
/
main.yml
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
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
name: Github Datamimic CE CI
run-name: ${{ github.actor || 'unknown' }} is running ${{ github.workflow || 'workflow' }} on ${{ github.repository || 'repo' }}
on:
push:
branches:
- development
tags:
- '[0-9]+.[0-9]+.[0-9]+'
pull_request:
branches:
- development
env:
RUNTIME_ENVIRONMENT: production
jobs:
setup:
runs-on: ubuntu-22.04
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Export latest tag
run: |
export RD_PROJECT_LATEST_TAG=${GITHUB_REF#refs/*/}
echo "RD_PROJECT_LATEST_TAG=$RD_PROJECT_LATEST_TAG"
echo "RD_PROJECT_LATEST_TAG=$RD_PROJECT_LATEST_TAG" >> build.env
- name: Export lib version without patch
run: |
export LIB_VERSION_WITHOUT_PATCH=$(echo "$RD_PROJECT_LATEST_TAG" | sed 's/\.[^.]*$//')
echo "LIB_VERSION_WITHOUT_PATCH=$LIB_VERSION_WITHOUT_PATCH"
echo "LIB_VERSION_WITHOUT_PATCH=$LIB_VERSION_WITHOUT_PATCH" >> build.env
- name: Upload build.env
uses: actions/upload-artifact@v4
with:
name: setup
path: build.env
if-no-files-found: error
retention-days: 1
install_dependencies:
runs-on: ubuntu-22.04
container: python:3.11-slim-buster
needs: setup
permissions:
contents: read
steps:
- name: Install dependencies os packages
run: |
apt-get update
apt-get install -y libpq-dev curl build-essential git
curl -LsSf https://astral.sh/uv/install.sh | sh
git config --global --add safe.directory $(realpath .)
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- name: Cache python venv
uses: actions/cache@v4
with:
path: .venv
key: ${{ runner.os }}-python-${{ hashFiles('./pyproject.toml') }}
- name: Check version
run: |
uv --version
echo testdb=${DB_HOST}:${DB_PORT}/${DB_DATABASE} with user=${DB_USER} password=${DB_PASSWORD}
echo MINIO_CONSUMER_HOST=${MINIO_CONSUMER_HOST} with MINIO_CONSUMER_ACCESS_KEY=${MINIO_CONSUMER_ACCESS_KEY} MINIO_CONSUMER_SECRET_KEY=${MINIO_CONSUMER_SECRET_KEY}
echo redis=${REDIS_HOST}:${REDIS_PORT} with password=${REDIS_PASSWORD}
echo logger_redis=${LOGGER_REDIS_HOST}:${LOGGER_REDIS_PORT} with password=${LOGGER_REDIS_PASSWORD}
shell: bash
- name: Create virtual env
run: |
uv venv .venv --python 3.11
. .venv/bin/activate
- name: Install dependencies
run: |
uv sync --all-extras
shell: bash
mypy:
runs-on: ubuntu-22.04
needs: install_dependencies
container: python:3.11-slim-buster
continue-on-error: true # TODO: Remove this line once all mypy errors are fixed
steps:
- name: Setup git
run: |
apt-get update
apt-get install -y git
git config --global --add safe.directory $(realpath .)
- name: Checkout repository
uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v3
- name: Load venv cache
uses: actions/cache/restore@v4
with:
path: .venv
key: ${{ runner.os }}-python-${{ hashFiles('./pyproject.toml') }}
- name: Run mypy
run: |
. .venv/bin/activate
uv run mypy datamimic_ce
shell: bash
ruff:
runs-on: ubuntu-22.04
needs: install_dependencies
container: python:3.11-slim-buster
continue-on-error: true # TODO: Remove this line once all ruff errors are fixed
steps:
- name: Setup git
run: |
apt-get update
apt-get install -y git
git config --global --add safe.directory $(realpath .)
- name: Checkout repository
uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v3
- name: Load venv cache
uses: actions/cache/restore@v4
with:
path: .venv
key: ${{ runner.os }}-python-${{ hashFiles('./pyproject.toml') }}
- name: Run ruff
run: |
. .venv/bin/activate
uv run ruff check datamimic_ce
shell: bash
build:
name: Build
runs-on: ubuntu-22.04
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
ref: ${{ github.event.pull_request.head.ref || github.ref }}
- name: Set Up Python 3.11
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install uv Package Manager
uses: astral-sh/setup-uv@v3
- name: Install dependencies
run: |
uv sync
shell: bash
- name: Build Package
run: |
uv build
shell: bash
- name: Upload Build Artifact
uses: actions/upload-artifact@v4
with:
path: dist/*
unit_test:
runs-on: ubuntu-22.04
needs: install_dependencies
container: python:3.11-slim-buster
steps:
- name: Setup git
run: |
apt-get update
apt-get install -y git
git config --global --add safe.directory $(realpath .)
- name: Checkout repository
uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v3
- name: Load venv cache
uses: actions/cache/restore@v4
with:
path: .venv
key: ${{ runner.os }}-python-${{ hashFiles('./pyproject.toml') }}
- name: Run unit tests with coverage
run: |
. .venv/bin/activate
uv run pytest tests_ce/unit_tests/ -n auto --cov=. --cov-report=xml
shell: bash
- name: Upload coverage report
uses: actions/upload-artifact@v4
with:
name: coverage-unit
path: coverage.xml
functional_test:
runs-on: ubuntu-22.04
needs: install_dependencies
container: python:3.11-slim-buster
services:
postgres:
image: postgres:13
env:
POSTGRES_USER: datamimic
POSTGRES_PASSWORD: datamimic
POSTGRES_DB: rd-datamimic
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
mongo:
image: mongo:4.4
env:
MONGO_INITDB_ROOT_USERNAME: datamimic
MONGO_INITDB_ROOT_PASSWORD: datamimic
ports:
- 27017:27017
options: --health-cmd "mongo --eval 'db.stats().ok'" --health-interval 10s --health-timeout 5s --health-retries 5
steps:
- name: Setup git
run: |
apt-get update
apt-get install -y git
git config --global --add safe.directory $(realpath .)
- name: Checkout repository
uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v3
- name: Load venv cache
uses: actions/cache/restore@v4
with:
path: .venv
key: ${{ runner.os }}-python-${{ hashFiles('./pyproject.toml') }}
- name: Run functional tests with coverage
run: |
. .venv/bin/activate
uv run pytest tests_ce/functional_tests/ --cov=. --cov-report=xml
shell: bash
- name: Upload coverage report
uses: actions/upload-artifact@v4
with:
name: coverage-functional
path: coverage.xml
integration_test:
runs-on: ubuntu-22.04
needs: install_dependencies
services:
postgres:
image: postgres:13
env:
POSTGRES_USER: datamimic
POSTGRES_PASSWORD: datamimic
POSTGRES_DB: rd-datamimic
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
mongo:
image: mongo:4.4
env:
MONGO_INITDB_ROOT_USERNAME: datamimic
MONGO_INITDB_ROOT_PASSWORD: datamimic
ports:
- 27017:27017
options: --health-cmd "mongo --eval 'db.stats().ok'" --health-interval 10s --health-timeout 5s --health-retries 5
container: python:3.11-slim-buster
steps:
- name: Setup git
run: |
apt-get update
apt-get install -y git
git config --global --add safe.directory $(realpath .)
- name: Checkout repository
uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v3
- name: Load venv cache
uses: actions/cache/restore@v4
with:
path: .venv
key: ${{ runner.os }}-python-${{ hashFiles('./pyproject.toml') }}
- name: Run integration tests with coverage
run: |
. .venv/bin/activate
uv run pytest tests_ce/integration_tests/ --cov=. --cov-report=xml
shell: bash
- name: Upload coverage report
uses: actions/upload-artifact@v4
with:
name: coverage-integration
path: coverage.xml
sonarcloud_analysis:
runs-on: ubuntu-22.04
needs: [ unit_test, functional_test, integration_test ]
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Download unit test coverage report
uses: actions/download-artifact@v4
with:
path: coverage-reports
- name: Move coverage reports to coverage directory and rename them
run: |
mv coverage-reports/coverage-functional/coverage.xml coverage-reports/coverage-functional.xml
mv coverage-reports/coverage-integration/coverage.xml coverage-reports/coverage-integration.xml
mv coverage-reports/coverage-unit/coverage.xml coverage-reports/coverage-unit.xml
rm -rf coverage-reports/coverage-functional
rm -rf coverage-reports/coverage-integration
rm -rf coverage-reports/coverage-unit
rm -rf coverage-reports/artifact
rm -rf coverage-reports/setup
shell: bash
- name: Display structure of downloaded files after renaming
run: ls -R coverage-reports
- name: Run SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
e2e_test:
name: E2E Test on ${{ matrix.os }} ${{ matrix.arch }}
if: github.ref == 'refs/heads/development' || startsWith(github.ref, 'refs/tags/')
runs-on: ${{ matrix.os }}
needs: [ build, unit_test, functional_test, integration_test ]
strategy:
matrix:
os: [ ubuntu-22.04, macos-latest, windows-latest ]
arch: [ x64, arm64 ]
python-version: [ '3.11' ]
exclude:
- os: windows-latest
arch: arm64 # Exclude Windows ARM64 as it's not supported
- os: ubuntu-22.04
arch: arm64 # Ubuntu GitHub runners do not support ARM64 yet
steps:
- name: Set Up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
architecture: ${{ matrix.arch }}
- name: Install uv Package Manager
run: |
python -m pip install --upgrade pip
pip install uv
- name: Download All Build Artifacts
uses: actions/download-artifact@v4
with:
path: dist
- name: Move *.whl and *.tar.gz to dist directory (Unix)
if: runner.os != 'Windows'
run: |
mv dist/artifact/*.whl dist
mv dist/artifact/*.tar.gz dist
rm -rf dist/artifact
rm -rf dist/setup
- name: Move *.whl and *.tar.gz to dist directory (Windows)
if: runner.os == 'Windows'
run: |
Move-Item dist\artifact\*.whl dist
Move-Item dist\artifact\*.tar.gz dist
Remove-Item -Path dist\artifact -Recurse -Force
Remove-Item -Path dist\setup -Recurse -Force
shell: pwsh
- name: List Contents of dist Directory
run: |
if [ "$RUNNER_OS" == "Windows" ]; then
dir dist
else
ls dist
fi
shell: bash
- name: Install Built Package on Windows
if: runner.os == 'Windows'
run: |
$wheel = Get-ChildItem -Path dist\*.whl | Select-Object -First 1
pip install $wheel.FullName
shell: pwsh
- name: Install Built Package on Unix
if: runner.os != 'Windows'
run: |
pip install dist/*.whl
shell: bash
- name: Run DATAMIMIC Help Command
run: datamimic --help
- name: List Available Demos
run: datamimic demo list
- name: Create All Demos
run: datamimic demo create --all --target my_demos
- name: Run demo-condition
run: datamimic run ./my_demos/demo-condition/datamimic.xml
- name: Run demo-custom-components
run: datamimic run ./my_demos/demo-custom-components/datamimic.xml
- name: Run demo-database
run: datamimic run ./my_demos/demo-database/datamimic.xml
- name: Run demo-datetime
run: datamimic run ./my_demos/demo-datetime/datamimic.xml
- name: Run demo-db-mapping
run: datamimic run ./my_demos/demo-db-mapping/datamimic.xml
- name: Run demo-json
run: datamimic run ./my_demos/demo-json/datamimic.xml
- name: Run demo-masking
run: datamimic run ./my_demos/demo-masking/datamimic.xml
- name: Run demo-model
run: datamimic run ./my_demos/demo-model/datamimic.xml
- name: Run demo-postprocess
run: datamimic run ./my_demos/demo-postprocess/datamimic.xml
- name: Run demo-py-scripting
run: datamimic run ./my_demos/demo-py-scripting/datamimic.xml
- name: Run demo-watermark
run: datamimic run ./my_demos/demo-watermark/datamimic.xml
- name: Run demo-xml
run: datamimic run ./my_demos/demo-xml/datamimic.xml
- name: Run overview-converter
run: datamimic run ./my_demos/overview-converter/datamimic.xml
- name: Run overview-generator
run: datamimic run ./my_demos/overview-generator/datamimic.xml
publish_dev:
if: github.ref == 'refs/heads/development'
runs-on: ubuntu-22.04
needs: [ e2e_test ]
environment:
name: testpypi
url: https://test.pypi.org/p/datamimic-ce
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/
contents: read
steps:
- name: Install uv
uses: astral-sh/setup-uv@v3
- name: Download All Build Artifacts
uses: actions/download-artifact@v4
with:
path: dist
- name: Move *.whl and *.tar.gz to dist directory
run: |
mv dist/artifact/*.whl dist
mv dist/artifact/*.tar.gz dist
rm -rf dist/artifact
rm -rf dist/setup
rm -rf dist/coverage-functional
rm -rf dist/coverage-integration
rm -rf dist/coverage-unit
- name: List Contents of dist Directory
run: ls -R dist
- name: Publish distribution to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
# verbose: true
release:
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-22.04
needs: [ e2e_test ]
environment:
name: pypi
url: https://pypi.org/p/datamimic-ce
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/
contents: read
steps:
- name: Download All Build Artifacts
uses: actions/download-artifact@v4
with:
path: dist
- name: Move *.whl and *.tar.gz to dist directory
run: |
mv dist/artifact/*.whl dist
mv dist/artifact/*.tar.gz dist
rm -rf dist/artifact
rm -rf dist/setup
rm -rf dist/coverage-functional
rm -rf dist/coverage-integration
rm -rf dist/coverage-unit
- name: List Contents of dist Directory
run: ls -R dist
- name: Publish distribution to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://upload.pypi.org/legacy/
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
trigger_ee_dev:
if: github.ref == 'refs/heads/development'
runs-on: ubuntu-22.04
needs: [ publish_dev ]
steps:
- name: trigger EE development pipelines
run: curl -X POST --fail -F token=$EE_TOKEN -F ref=development https://gitlab.dwellerlab.com/api/v4/projects/214/trigger/pipeline;
env:
EE_TOKEN: ${{ secrets.EE_TOKEN }}
shell: bash