forked from AyushAggarwal1/presidio
-
Notifications
You must be signed in to change notification settings - Fork 1
459 lines (402 loc) · 14.2 KB
/
ci.yml
File metadata and controls
459 lines (402 loc) · 14.2 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
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
name: CI
on:
pull_request:
branches: [ main ]
push:
branches: [ main ]
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions: read-all
env:
REGISTRY_NAME: ${{ secrets.ACR_NAME }}.azurecr.io
TAG: gha${{ github.run_number }}
jobs:
lint:
name: Linting
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
persist-credentials: false
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.11'
- name: Install ruff
run: pip install ruff
- name: Run ruff check
run: ruff check
dependency-review:
name: Dependency Review
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
permissions:
contents: read
pull-requests: write
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
persist-credentials: false
- name: Dependency Review
uses: actions/dependency-review-action@v4
with:
fail-on-severity: low
allow-licenses: MIT, Apache-2.0, BSD-3-Clause
comment-summary-in-pr: on-failure
test:
name: Test ${{ matrix.component.name }} (Python ${{ matrix.python-version }})
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
strategy:
matrix:
python-version: ['3.10', '3.11', '3.12', '3.13']
component:
- name: 'Analyzer'
path: 'presidio-analyzer'
extras: '--all-extras'
spacy-models: 'en_core_web_lg en_core_web_sm'
- name: 'Anonymizer'
path: 'presidio-anonymizer'
extras: ''
spacy-models: ''
- name: 'Image Redactor'
path: 'presidio-image-redactor'
extras: ''
spacy-models: 'en_core_web_lg'
- name: 'CLI'
path: 'presidio-cli'
extras: ''
spacy-models: ''
- name: 'Structured'
path: 'presidio-structured'
extras: ''
spacy-models: ''
env:
POETRY_CACHE_DIR: /mnt/poetry_cache
COVERAGE_THRESHOLD: 90
PRIMARY_PYTHON: '3.13'
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
persist-credentials: true
fetch-depth: 0
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
cache-dependency-path: ${{ matrix.component.path }}/pyproject.toml
- name: Install Poetry
run: |
python -m pip install --upgrade pip
python -m pip install poetry
- name: Setup Poetry Cache Directory
run: |
sudo mkdir -p $POETRY_CACHE_DIR
sudo chown -R runner $POETRY_CACHE_DIR
- name: Install system dependencies for Image Redactor
if: matrix.component.name == 'Image Redactor'
run: |
sudo apt-get update
sudo apt-get install tesseract-ocr -y
- name: Install dependencies
working-directory: ${{ matrix.component.path }}
run: |
poetry install ${{ matrix.component.extras }}
- name: Install presidio-analyzer for Image Redactor
if: matrix.component.name == 'Image Redactor'
working-directory: ${{ matrix.component.path }}
run: |
poetry run pip install -e ../presidio-analyzer/.
- name: Download spaCy models
if: matrix.component.spacy-models != ''
working-directory: ${{ matrix.component.path }}
run: |
for model in ${{ matrix.component.spacy-models }}; do
poetry run python -m spacy download $model
done
- name: Run tests with coverage
working-directory: ${{ matrix.component.path }}
run: |
PACKAGE_NAME=$(echo "${{ matrix.component.path }}" | sed 's/-/_/g')
poetry run pytest --cov=$PACKAGE_NAME --cov-report=xml:coverage.xml --cov-report=term --cov-report=html -vv --tb=short
if [ "${{ github.event_name }}" = "pull_request" ]; then
echo "Checking PR difference coverage (>= ${{ env.COVERAGE_THRESHOLD }}%) with diff-cover..."
poetry run diff-cover coverage.xml \
--compare-branch=origin/${{ github.base_ref }} \
--fail-under=${{ env.COVERAGE_THRESHOLD }} \
--show-uncovered
fi
- name: Comment PR with Coverage
if: matrix.python-version == env.PRIMARY_PYTHON
uses: py-cov-action/python-coverage-comment-action@v3
with:
GITHUB_TOKEN: ${{ github.token }}
MINIMUM_GREEN: 85
MINIMUM_ORANGE: 70
COVERAGE_DATA_BRANCH: coverage-data
SUBPROJECT_ID: ${{ matrix.component.path }}
COVERAGE_PATH: ${{ matrix.component.path }}
- name: Build wheel package
working-directory: ${{ matrix.component.path }}
run: |
pip install build
python -m build --wheel
build-platform-images:
name: Build ${{ matrix.image }} (${{ matrix.platform }})
runs-on: ${{ matrix.runner }}
needs: [lint]
if: github.ref == 'refs/heads/main'
permissions:
id-token: write
contents: read
strategy:
matrix:
include:
- image: presidio-anonymizer
platform: linux/amd64
runner: ubuntu-latest
- image: presidio-analyzer
platform: linux/amd64
runner: ubuntu-latest
- image: presidio-image-redactor
platform: linux/amd64
runner: ubuntu-latest
- image: presidio-anonymizer
platform: linux/arm64
runner: ubuntu-24.04-arm
- image: presidio-analyzer
platform: linux/arm64
runner: ubuntu-24.04-arm
- image: presidio-image-redactor
platform: linux/arm64
runner: ubuntu-24.04-arm
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
persist-credentials: false
- name: Azure Login using OIDC
uses: azure/login@v2
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Log in to Azure Container Registry
run: az acr login --name ${{ secrets.ACR_NAME }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and Push ${{ matrix.image }} for ${{ matrix.platform }}
run: |
# Create platform-specific tag
PLATFORM_TAG=$(echo "${{ matrix.platform }}" | sed 's/\//-/g')
docker buildx build \
--platform ${{ matrix.platform }} \
--push \
--tag ${{ env.REGISTRY_NAME }}/${{ matrix.image }}:${{ env.TAG }}-${PLATFORM_TAG} \
--cache-from type=registry,ref=${{ env.REGISTRY_NAME }}/public/${{ matrix.image }}:latest \
--cache-to type=inline \
--attest type=sbom \
--attest type=provenance,mode=max \
./${{ matrix.image }}
env:
REGISTRY_NAME: ${{ env.REGISTRY_NAME }}
TAG: ${{ env.TAG }}
create-manifests:
name: Create Multi-Platform Manifests
runs-on: ubuntu-latest
needs: build-platform-images
if: github.ref == 'refs/heads/main'
permissions:
id-token: write
contents: read
steps:
- name: Azure Login using OIDC
uses: azure/login@v2
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Log in to Azure Container Registry
run: az acr login --name ${{ secrets.ACR_NAME }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Create all multi-platform manifests
run: |
IMAGES=("presidio-anonymizer" "presidio-analyzer" "presidio-image-redactor")
for image in "${IMAGES[@]}"; do
echo "Creating manifest for $image"
docker buildx imagetools create \
--tag ${{ env.REGISTRY_NAME }}/${image}:${{ env.TAG }} \
${{ env.REGISTRY_NAME }}/${image}:${{ env.TAG }}-linux-amd64 \
${{ env.REGISTRY_NAME }}/${image}:${{ env.TAG }}-linux-arm64
done
env:
REGISTRY_NAME: ${{ env.REGISTRY_NAME }}
TAG: ${{ env.TAG }}
e2e-tests:
name: E2E Tests (${{ matrix.platform }})
runs-on: ${{ matrix.runner }}
needs: create-manifests
if: github.ref == 'refs/heads/main'
permissions:
id-token: write
contents: read
strategy:
matrix:
include:
- platform: linux/amd64
runner: ubuntu-latest
- platform: linux/arm64
runner: ubuntu-24.04-arm
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
persist-credentials: false
- name: Azure Login using OIDC
uses: azure/login@v2
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Log in to Azure Container Registry
run: az acr login --name ${{ secrets.ACR_NAME }}
- name: Pull Presidio images from ACR
run: |
export DOCKER_DEFAULT_PLATFORM=${{ matrix.platform }}
docker compose -f docker-compose.yml pull
env:
REGISTRY_NAME: ${{ env.REGISTRY_NAME }}
TAG: :${{ env.TAG }}
- name: Start Presidio cluster
run: |
export DOCKER_DEFAULT_PLATFORM=${{ matrix.platform }}
docker compose -f docker-compose.yml up -d
env:
REGISTRY_NAME: ${{ env.REGISTRY_NAME }}
TAG: :${{ env.TAG }}
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.10'
- name: Cache E2E dependencies
uses: actions/cache@v5
with:
path: |
~/.cache/pip
e2e-tests/env
key: ${{ runner.os }}-${{ matrix.platform }}-e2e-${{ hashFiles('e2e-tests/requirements.txt') }}
restore-keys: |
${{ runner.os }}-${{ matrix.platform }}-e2e-
- name: Install E2E test dependencies
working-directory: e2e-tests
run: |
python -m venv env
source env/bin/activate
python -m pip install --upgrade pip
pip install -r requirements.txt
python -m spacy download en_core_web_lg
- name: Wait for services to be ready
run: sleep 60
- name: Download Ollama model for Ollama LangExtract recognizer tests
run: |
docker exec $(docker ps -qf "name=ollama") ollama pull qwen2.5:1.5b
docker exec $(docker ps -qf "name=ollama") ollama run qwen2.5:1.5b
- name: Run E2E tests
working-directory: e2e-tests
run: |
source env/bin/activate
pytest -vv --tb=short
- name: Capture Docker logs on failure (${{ matrix.platform }})
if: failure()
run: |
echo "Capturing Docker logs for platform: ${{ matrix.platform }}"
docker compose -f docker-compose.yml logs
- name: Stop Docker containers
if: always()
run: |
docker compose -f docker-compose.yml down
# Local build and test jobs for external contributors (no secrets required)
local-build-and-test:
name: Local Build and E2E Tests (${{ matrix.platform }})
runs-on: ${{ matrix.runner }}
needs: [lint]
if: github.ref != 'refs/heads/main'
strategy:
matrix:
include:
- platform: linux/amd64
runner: ubuntu-latest
- platform: linux/arm64
runner: ubuntu-24.04-arm
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
persist-credentials: false
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build Presidio images locally
run: |
# Build all images locally without pushing
docker compose -f docker-compose.yml build
env:
REGISTRY_NAME: 'mcr.microsoft.com'
IMAGE_PREFIX: ''
TAG: gha${{ github.run_number }}
- name: Start Presidio cluster locally
run: |
docker compose -f docker-compose.yml up -d
env:
REGISTRY_NAME: 'mcr.microsoft.com'
IMAGE_PREFIX: ''
TAG: gha${{ github.run_number }}
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.10'
- name: Cache E2E dependencies
uses: actions/cache@v5
with:
path: |
~/.cache/pip
e2e-tests/env
key: ${{ runner.os }}-${{ matrix.platform }}-local-e2e-${{ hashFiles('e2e-tests/requirements.txt') }}
restore-keys: |
${{ runner.os }}-${{ matrix.platform }}-local-e2e-
- name: Install E2E test dependencies
working-directory: e2e-tests
run: |
python -m venv env
source env/bin/activate
python -m pip install --upgrade pip
pip install -r requirements.txt
python -m spacy download en_core_web_lg
- name: Wait for services to be ready
run: sleep 60
- name: Download Ollama model for Ollama LangExtract recognizer tests
run: |
docker exec $(docker ps -qf "name=ollama") ollama pull qwen2.5:1.5b
docker exec $(docker ps -qf "name=ollama") ollama run qwen2.5:1.5b
- name: Run E2E tests
working-directory: e2e-tests
run: |
source env/bin/activate
pytest -vv --tb=short
- name: Capture Docker logs on failure
if: failure()
run: |
echo "Capturing Docker logs for local build"
docker compose -f docker-compose.yml logs
- name: Stop Docker containers
if: always()
run: |
docker compose -f docker-compose.yml down