-
Notifications
You must be signed in to change notification settings - Fork 9
408 lines (340 loc) · 12.3 KB
/
Copy pathci.yml
File metadata and controls
408 lines (340 loc) · 12.3 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
name: CI
on:
push:
pull_request:
workflow_dispatch:
env:
CONTAINER_REGISTRY_URL: ${{ vars.CONTAINER_REGISTRY_URL }}
APP_NAME: ${{ vars.APP_NAME }}
UDATA_WORKING_DIR: udata
permissions:
id-token: write # Required for OIDC for npm publication
contents: read
jobs:
# ============================================
# JOB 1: Build - generates artifacts once
# ============================================
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Install pnpm
uses: pnpm/action-setup@v4
- name: Use Node.js
uses: actions/setup-node@v6
with:
node-version: "24.x"
cache: "pnpm"
- name: Install datagouv-components dependencies
working-directory: ./datagouv-components
run: pnpm install
- name: Build datagouv-components CSS
working-directory: ./datagouv-components
run: pnpm run css
- name: Install dependencies
run: pnpm install
- name: Build application
run: NUXT_APP_COMMIT_ID=$(git rev-parse --short HEAD) pnpm run build
- name: Upload build artifacts
uses: actions/upload-artifact@v7
with:
name: build-output
path: .output
retention-days: 1
if-no-files-found: error
include-hidden-files: true
# ============================================
# JOB 2: Quality - lint + typecheck (runs in parallel with build)
# ============================================
quality:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Install pnpm
uses: pnpm/action-setup@v4
- name: Use Node.js
uses: actions/setup-node@v6
with:
node-version: "24.x"
cache: "pnpm"
- name: Install cdata dependencies
run: pnpm install
- name: Run lint
run: pnpm run lint
- name: Run typecheck
run: pnpm run typecheck
- name: Install datagouv-components dependencies
working-directory: ./datagouv-components
run: pnpm install
- name: Run datagouv-components typecheck
working-directory: ./datagouv-components
run: pnpm run typecheck
- name: Run datagouv-components lint
working-directory: ./datagouv-components
run: pnpm run lint
# ============================================
# JOB 3: E2E Tests (runs in parallel with quality)
# ============================================
e2e:
needs: build
timeout-minutes: 30
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
browser: [chromium, firefox]
include:
- browser: chromium
projects: "--project=setup --project=setup-normal-user --project=chromium --project=chromium-normal-user --project=chromium-2fa-user"
- browser: firefox
projects: "--project=setup --project=setup-normal-user --project=firefox"
container:
image: mcr.microsoft.com/playwright:v1.58.2-noble
options: --user 1001
services:
mongodb:
image: mongo:6.0.4
ports:
- 27017:27017
redis:
image: redis
ports:
- 6379:6379
steps:
- name: Checkout cdata
uses: actions/checkout@v6
- name: Download build artifacts
uses: actions/download-artifact@v8
with:
name: build-output
path: .output
- name: Checkout udata
uses: actions/checkout@v6
with:
repository: opendatateam/udata
path: ${{ env.UDATA_WORKING_DIR }}
ref: main
- name: Set up uv
uses: astral-sh/setup-uv@v6
with:
python-version: "3.11"
working-directory: ${{ env.UDATA_WORKING_DIR }}
- name: Install pnpm
uses: pnpm/action-setup@v4
- name: Set up Node.js
uses: actions/setup-node@v6
with:
node-version: "24"
cache: "pnpm"
cache-dependency-path: pnpm-lock.yaml
- name: Install Node.js dependencies for cdata
run: pnpm install
- name: Install Python dependencies for udata
working-directory: ${{ env.UDATA_WORKING_DIR }}
run: |
uv sync --frozen
- name: Configure udata
working-directory: ${{ env.UDATA_WORKING_DIR }}
run: |
cat << 'EOF' > udata.cfg
from udata.settings import Defaults
DEBUG = True
TESTING = True
SECRET_KEY = 'test-secret-key-for-ci'
API_TOKEN_SECRET = 'test-api-token-secret-for-ci'
SEND_MAIL = False
SERVER_NAME = 'localhost:7000'
CDATA_BASE_URL="http://localhost:3000"
CACHE_TYPE = 'null'
DEFAULT_LANGUAGE = 'fr'
SCHEMA_CATALOG_URL='https://schema.data.gouv.fr/schemas/schemas.json'
URLS_ALLOW_PRIVATE = True
URLS_ALLOW_LOCAL = True
URLS_ALLOWED_TLDS = Defaults.URLS_ALLOWED_TLDS | set(['local'])
URLS_RESOLVE_HOSTNAME = False
PLUGINS = []
FS_ROOT = 'fs'
SESSION_COOKIE_SECURE = False
SECURITY_EMAIL_VALIDATOR_ARGS = {
"check_deliverability": False
}
SECURITY_TWO_FACTOR = True
MONGODB_HOST = 'mongodb://mongodb:27017/udata'
CELERY_BROKER_URL = 'redis://redis:6379'
CELERY_RESULT_BACKEND = 'redis://redis:6379'
EOF
- name: Initialize udata
working-directory: ${{ env.UDATA_WORKING_DIR }}
run: |
# Create fs directory
mkdir -p fs
# Initialize udata
uv run udata init
uv run udata licenses
uv run udata spatial load
uv run udata import-fixtures
uv run udata user create --first-name "Admin" --last-name "User" --email "admin@example.com" --password "@1337Password42" --admin
uv run udata user create --first-name "Normal" --last-name "User" --email "normal@example.com" --password "@1337Password42"
uv run udata user create --first-name "2FA" --last-name "User" --email "2fa@example.com" --password "@1337Password42"
uv run inv i18nc
# Start udata server in background
uv run inv serve --port=7000 > udata.log 2>&1 &
# Wait for udata to be ready
timeout 90 bash -c 'until curl -f http://localhost:7000/api/1/site/; do sleep 2; done'
echo "udata server is ready"
- name: Start cdata server
env:
NUXT_PUBLIC_API_BASE: http://localhost:7000
NUXT_PUBLIC_HOMEPAGE_HERO_IMAGES: "hero_15.png"
NUXT_SITE_URL: http://localhost:3000
run: |
# Start cdata server in background using pre-built artifacts
PORT=3000 node .output/server/index.mjs > cdata.log 2>&1 &
# Wait for cdata to be ready
timeout 90 bash -c 'until curl -f http://localhost:3000; do sleep 2; done'
echo "cdata server is ready"
- name: Run E2E tests
env:
BASE_URL: http://localhost:3000
NUXT_PUBLIC_API_BASE: http://localhost:7000
UDATA_WORKING_DIR: ${{ env.UDATA_WORKING_DIR }}
CI: true
run: pnpm run test:e2e ${{ matrix.projects }}
- name: Kill udata server
if: always()
working-directory: ${{ env.UDATA_WORKING_DIR }}
run: |
# Kill udata server to release the lock so that post setup-uv can prune the cache
pkill -f "uv run inv serve" || true
- name: Show server logs
if: always()
run: |
echo "=== UDATA SERVER LOGS ==="
cat $UDATA_WORKING_DIR/udata.log || echo "No udata logs found"
echo ""
echo "=== CDATA SERVER LOGS ==="
cat cdata.log || echo "No cdata logs found"
- name: Upload screenshots
uses: actions/upload-artifact@v7
if: always()
with:
name: playwright-screenshots-${{ matrix.browser }}
path: tests/**/*-snapshots
retention-days: 7
- name: Upload Playwright report
uses: actions/upload-artifact@v7
if: always()
with:
name: playwright-report-${{ matrix.browser }}
path: playwright-report/
retention-days: 7
# ============================================
# JOB 4: Docker - build & push Docker image (automatic on main, manual on any branch)
# ============================================
docker:
needs: [quality, e2e]
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch'
permissions:
contents: read
outputs:
image-tag: ${{ steps.meta.outputs.tags }}
version: ${{ steps.version.outputs.short }}
steps:
- uses: actions/checkout@v6
- name: Download build artifacts
uses: actions/download-artifact@v8
with:
name: build-output
path: .output
- name: Set version
id: version
run: |
echo "short=${GITHUB_SHA:0:7}" >> $GITHUB_OUTPUT
echo "long=$GITHUB_SHA" >> $GITHUB_OUTPUT
- name: Log in to GitLab Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.CONTAINER_REGISTRY_URL }}
username: oauth2
password: ${{ secrets.GITLAB_API_TOKEN }}
- name: Extract metadata for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.CONTAINER_REGISTRY_URL }}/${{ env.APP_NAME }}
tags: |
type=sha,format=short,prefix=
type=sha,format=long,prefix=
type=ref,event=branch
type=ref,event=tag
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
# ============================================
# JOB 5: Sentry - upload source maps (automatic on main, manual on any branch)
# ============================================
sentry:
needs: [quality, e2e]
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch'
steps:
- uses: actions/checkout@v6
- name: Download build artifacts
uses: actions/download-artifact@v8
with:
name: build-output
path: .output
- name: Set version
id: version
run: |
echo "short=${GITHUB_SHA:0:7}" >> $GITHUB_OUTPUT
- name: Create Sentry release
uses: getsentry/action-release@v3
env:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
SENTRY_ORG: ${{ secrets.SENTRY_ORG }}
SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }}
SENTRY_URL: ${{ secrets.SENTRY_URL }}
with:
sourcemaps: ".output/public/_nuxt"
url_prefix: "~/_nuxt"
environment: ${{ github.ref_name }}
version: ${{ steps.version.outputs.short }}
ignore_missing: true
# ============================================
# JOB 6: Publish datagouv-components (automatic on main, manual on any branch)
# ============================================
publish-datagouv-components:
needs: [quality, e2e]
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch'
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Install pnpm
uses: pnpm/action-setup@v4
- name: Set up Node.js with OIDC auth
uses: actions/setup-node@v6
with:
node-version: "24"
cache: "pnpm"
registry-url: "https://registry.npmjs.org"
- name: Install datagouv-components dependencies
working-directory: ./datagouv-components
run: pnpm install
- name: Publish datagouv-components
working-directory: ./datagouv-components
run: |
LATEST=$(npm view @datagouv/components-next@dev version 2>/dev/null \
|| npm view @datagouv/components-next version 2>/dev/null \
|| echo "0.0.0")
echo "Using base version $LATEST"
pnpm version "$LATEST" --no-git-tag-version --allow-same-version
# Then, we increment the preprelease version number
pnpm version prerelease --preid=dev --no-git-tag-version
pnpm run publish-dev --no-git-checks