|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + |
| 6 | +env: |
| 7 | + CONTAINER_REGISTRY_URL: ${{ vars.CONTAINER_REGISTRY_URL }} |
| 8 | + APP_NAME: ${{ vars.APP_NAME }} |
| 9 | + |
| 10 | +jobs: |
| 11 | + # ============================================ |
| 12 | + # JOB 1: Build - generates artifacts once |
| 13 | + # ============================================ |
| 14 | + build: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + steps: |
| 17 | + - uses: actions/checkout@v4 |
| 18 | + |
| 19 | + - name: Install pnpm |
| 20 | + uses: pnpm/action-setup@v4 |
| 21 | + |
| 22 | + - name: Use Node.js |
| 23 | + uses: actions/setup-node@v4 |
| 24 | + with: |
| 25 | + node-version: '20.x' |
| 26 | + cache: 'pnpm' |
| 27 | + |
| 28 | + - name: Install datagouv-components dependencies |
| 29 | + working-directory: ./datagouv-components |
| 30 | + run: pnpm install |
| 31 | + |
| 32 | + - name: Build datagouv-components CSS |
| 33 | + working-directory: ./datagouv-components |
| 34 | + run: pnpm run css |
| 35 | + |
| 36 | + - name: Install dependencies |
| 37 | + run: pnpm install |
| 38 | + |
| 39 | + - name: Build application |
| 40 | + run: NUXT_APP_COMMIT_ID=$(git rev-parse --short HEAD) pnpm run build |
| 41 | + |
| 42 | + - name: Upload build artifacts |
| 43 | + uses: actions/upload-artifact@v4 |
| 44 | + with: |
| 45 | + name: build-output |
| 46 | + path: .output |
| 47 | + retention-days: 1 |
| 48 | + if-no-files-found: error |
| 49 | + include-hidden-files: true |
| 50 | + |
| 51 | + # ============================================ |
| 52 | + # JOB 2: Quality - lint + typecheck (runs in parallel with build) |
| 53 | + # ============================================ |
| 54 | + quality: |
| 55 | + runs-on: ubuntu-latest |
| 56 | + steps: |
| 57 | + - uses: actions/checkout@v4 |
| 58 | + |
| 59 | + - name: Install pnpm |
| 60 | + uses: pnpm/action-setup@v4 |
| 61 | + |
| 62 | + - name: Use Node.js |
| 63 | + uses: actions/setup-node@v4 |
| 64 | + with: |
| 65 | + node-version: '20.x' |
| 66 | + cache: 'pnpm' |
| 67 | + |
| 68 | + - name: Install cdata dependencies |
| 69 | + run: pnpm install |
| 70 | + |
| 71 | + - name: Run lint |
| 72 | + run: pnpm run lint |
| 73 | + |
| 74 | + - name: Run typecheck |
| 75 | + run: pnpm run typecheck |
| 76 | + |
| 77 | + - name: Install datagouv-components dependencies |
| 78 | + working-directory: ./datagouv-components |
| 79 | + run: pnpm install |
| 80 | + |
| 81 | + - name: Run datagouv-components typecheck |
| 82 | + working-directory: ./datagouv-components |
| 83 | + run: pnpm run typecheck |
| 84 | + |
| 85 | + - name: Run datagouv-components lint |
| 86 | + working-directory: ./datagouv-components |
| 87 | + run: pnpm run lint |
| 88 | + |
| 89 | + # ============================================ |
| 90 | + # JOB 3: E2E Tests (runs in parallel with quality) |
| 91 | + # ============================================ |
| 92 | + e2e: |
| 93 | + needs: build |
| 94 | + timeout-minutes: 30 |
| 95 | + runs-on: ubuntu-latest |
| 96 | + container: |
| 97 | + image: mcr.microsoft.com/playwright:v1.57.0-noble |
| 98 | + options: --user 1001 |
| 99 | + |
| 100 | + services: |
| 101 | + mongodb: |
| 102 | + image: mongo:6.0.4 |
| 103 | + ports: |
| 104 | + - 27017:27017 |
| 105 | + redis: |
| 106 | + image: redis |
| 107 | + ports: |
| 108 | + - 6379:6379 |
| 109 | + |
| 110 | + steps: |
| 111 | + - name: Checkout cdata |
| 112 | + uses: actions/checkout@v4 |
| 113 | + |
| 114 | + - name: Download build artifacts |
| 115 | + uses: actions/download-artifact@v4 |
| 116 | + with: |
| 117 | + name: build-output |
| 118 | + path: .output |
| 119 | + |
| 120 | + - name: Checkout udata |
| 121 | + uses: actions/checkout@v4 |
| 122 | + with: |
| 123 | + repository: opendatateam/udata |
| 124 | + path: udata |
| 125 | + ref: main |
| 126 | + |
| 127 | + - name: Set up uv |
| 128 | + uses: astral-sh/setup-uv@v6 |
| 129 | + with: |
| 130 | + python-version: "3.11" |
| 131 | + working-directory: udata |
| 132 | + |
| 133 | + - name: Install pnpm |
| 134 | + uses: pnpm/action-setup@v4 |
| 135 | + |
| 136 | + - name: Set up Node.js |
| 137 | + uses: actions/setup-node@v4 |
| 138 | + with: |
| 139 | + node-version: "24" |
| 140 | + cache: "pnpm" |
| 141 | + cache-dependency-path: pnpm-lock.yaml |
| 142 | + |
| 143 | + - name: Install Node.js dependencies for cdata |
| 144 | + run: pnpm install |
| 145 | + |
| 146 | + - name: Install Python dependencies for udata |
| 147 | + working-directory: udata |
| 148 | + run: | |
| 149 | + uv sync --frozen |
| 150 | +
|
| 151 | + - name: Configure udata |
| 152 | + working-directory: udata |
| 153 | + run: | |
| 154 | + cat << 'EOF' > udata.cfg |
| 155 | + from udata.settings import Defaults |
| 156 | +
|
| 157 | + DEBUG = True |
| 158 | + TESTING = True |
| 159 | + SECRET_KEY = 'test-secret-key-for-ci' |
| 160 | + SEND_MAIL = False |
| 161 | + SERVER_NAME = 'localhost:7000' |
| 162 | + CDATA_BASE_URL="http://localhost:3000" |
| 163 | +
|
| 164 | + CACHE_TYPE = 'null' |
| 165 | + DEFAULT_LANGUAGE = 'fr' |
| 166 | +
|
| 167 | + SCHEMA_CATALOG_URL='https://schema.data.gouv.fr/schemas/schemas.json' |
| 168 | +
|
| 169 | + URLS_ALLOW_PRIVATE = True |
| 170 | + URLS_ALLOW_LOCAL = True |
| 171 | + URLS_ALLOWED_TLDS = Defaults.URLS_ALLOWED_TLDS | set(['local']) |
| 172 | +
|
| 173 | + PLUGINS = [] |
| 174 | + FS_ROOT = 'fs' |
| 175 | +
|
| 176 | + SESSION_COOKIE_SECURE = False |
| 177 | +
|
| 178 | + SECURITY_EMAIL_VALIDATOR_ARGS = { |
| 179 | + "check_deliverability": False |
| 180 | + } |
| 181 | +
|
| 182 | + MONGODB_HOST = 'mongodb://mongodb:27017/udata' |
| 183 | + CELERY_BROKER_URL = 'redis://redis:6379' |
| 184 | + CELERY_RESULT_BACKEND = 'redis://redis:6379' |
| 185 | + EOF |
| 186 | +
|
| 187 | + - name: Initialize udata |
| 188 | + working-directory: udata |
| 189 | + run: | |
| 190 | + # Create fs directory |
| 191 | + mkdir -p fs |
| 192 | +
|
| 193 | + # Initialize udata |
| 194 | + uv run udata init |
| 195 | +
|
| 196 | + uv run udata licenses |
| 197 | + uv run udata spatial load |
| 198 | + uv run udata import-fixtures |
| 199 | +
|
| 200 | + uv run udata user create --first-name "Admin" --last-name "User" --email "[email protected]" --password "@1337Password42" --admin |
| 201 | + uv run udata user create --first-name "Normal" --last-name "User" --email "[email protected]" --password "@1337Password42" |
| 202 | +
|
| 203 | + uv run inv i18nc |
| 204 | +
|
| 205 | + # Start udata server in background |
| 206 | + uv run inv serve --port=7000 > udata.log 2>&1 & |
| 207 | +
|
| 208 | + # Wait for udata to be ready |
| 209 | + timeout 90 bash -c 'until curl -f http://localhost:7000/api/1/site/; do sleep 2; done' |
| 210 | + echo "udata server is ready" |
| 211 | +
|
| 212 | + - name: Start cdata server |
| 213 | + env: |
| 214 | + NUXT_PUBLIC_API_BASE: http://localhost:7000 |
| 215 | + NUXT_PUBLIC_HOMEPAGE_HERO_IMAGES: "hero_15.png" |
| 216 | + run: | |
| 217 | + # Start cdata server in background using pre-built artifacts |
| 218 | + PORT=3000 node .output/server/index.mjs > cdata.log 2>&1 & |
| 219 | +
|
| 220 | + # Wait for cdata to be ready |
| 221 | + timeout 90 bash -c 'until curl -f http://localhost:3000; do sleep 2; done' |
| 222 | + echo "cdata server is ready" |
| 223 | +
|
| 224 | + - name: Run E2E tests |
| 225 | + env: |
| 226 | + BASE_URL: http://localhost:3000 |
| 227 | + NUXT_PUBLIC_API_BASE: http://localhost:7000 |
| 228 | + CI: true |
| 229 | + run: pnpm run test:e2e |
| 230 | + |
| 231 | + - name: Kill udata server |
| 232 | + if: always() |
| 233 | + working-directory: udata |
| 234 | + run: | |
| 235 | + # Kill udata server to release the lock so that post setup-uv can prune the cache |
| 236 | + pkill -f "uv run inv serve" || true |
| 237 | +
|
| 238 | + - name: Show server logs |
| 239 | + if: always() |
| 240 | + run: | |
| 241 | + echo "=== UDATA SERVER LOGS ===" |
| 242 | + cat udata/udata.log || echo "No udata logs found" |
| 243 | + echo "" |
| 244 | + echo "=== CDATA SERVER LOGS ===" |
| 245 | + cat cdata.log || echo "No cdata logs found" |
| 246 | +
|
| 247 | + - name: Upload screenshots |
| 248 | + uses: actions/upload-artifact@v4 |
| 249 | + if: always() |
| 250 | + with: |
| 251 | + name: playwright-screenshots |
| 252 | + path: tests/**/*-snapshots |
| 253 | + retention-days: 7 |
| 254 | + |
| 255 | + - name: Upload Playwright report |
| 256 | + uses: actions/upload-artifact@v4 |
| 257 | + if: always() |
| 258 | + with: |
| 259 | + name: playwright-report |
| 260 | + path: playwright-report/ |
| 261 | + retention-days: 7 |
| 262 | + |
| 263 | + # ============================================ |
| 264 | + # JOB 4: Docker - build & push Docker image (all branches, not PRs) |
| 265 | + # ============================================ |
| 266 | + docker: |
| 267 | + needs: [quality, e2e] |
| 268 | + runs-on: ubuntu-latest |
| 269 | + permissions: |
| 270 | + contents: read |
| 271 | + outputs: |
| 272 | + image-tag: ${{ steps.meta.outputs.tags }} |
| 273 | + version: ${{ steps.version.outputs.short }} |
| 274 | + steps: |
| 275 | + - uses: actions/checkout@v4 |
| 276 | + |
| 277 | + - name: Download build artifacts |
| 278 | + uses: actions/download-artifact@v4 |
| 279 | + with: |
| 280 | + name: build-output |
| 281 | + path: .output |
| 282 | + |
| 283 | + - name: Set version |
| 284 | + id: version |
| 285 | + run: | |
| 286 | + echo "short=${GITHUB_SHA:0:7}" >> $GITHUB_OUTPUT |
| 287 | + echo "long=$GITHUB_SHA" >> $GITHUB_OUTPUT |
| 288 | +
|
| 289 | + - name: Log in to GitLab Container Registry |
| 290 | + uses: docker/login-action@v3 |
| 291 | + with: |
| 292 | + registry: ${{ env.CONTAINER_REGISTRY_URL }} |
| 293 | + username: oauth2 |
| 294 | + password: ${{ secrets.GITLAB_API_TOKEN }} |
| 295 | + |
| 296 | + - name: Extract metadata for Docker |
| 297 | + id: meta |
| 298 | + uses: docker/metadata-action@v5 |
| 299 | + with: |
| 300 | + images: ${{ env.CONTAINER_REGISTRY_URL }}/${{ env.APP_NAME }} |
| 301 | + tags: | |
| 302 | + type=sha,format=short,prefix= |
| 303 | + type=sha,format=long,prefix= |
| 304 | + type=ref,event=branch |
| 305 | + type=ref,event=tag |
| 306 | +
|
| 307 | + - name: Build and push Docker image |
| 308 | + uses: docker/build-push-action@v6 |
| 309 | + with: |
| 310 | + context: . |
| 311 | + push: true |
| 312 | + tags: ${{ steps.meta.outputs.tags }} |
| 313 | + labels: ${{ steps.meta.outputs.labels }} |
| 314 | + |
| 315 | + # ============================================ |
| 316 | + # JOB 5: Sentry - upload source maps (runs in parallel with publish) |
| 317 | + # ============================================ |
| 318 | + sentry: |
| 319 | + needs: [quality, e2e] |
| 320 | + runs-on: ubuntu-latest |
| 321 | + steps: |
| 322 | + - uses: actions/checkout@v4 |
| 323 | + |
| 324 | + - name: Download build artifacts |
| 325 | + uses: actions/download-artifact@v4 |
| 326 | + with: |
| 327 | + name: build-output |
| 328 | + path: .output |
| 329 | + |
| 330 | + - name: Set version |
| 331 | + id: version |
| 332 | + run: | |
| 333 | + echo "short=${GITHUB_SHA:0:7}" >> $GITHUB_OUTPUT |
| 334 | +
|
| 335 | + - name: Create Sentry release |
| 336 | + uses: getsentry/action-release@v3 |
| 337 | + env: |
| 338 | + SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} |
| 339 | + SENTRY_ORG: ${{ secrets.SENTRY_ORG }} |
| 340 | + SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }} |
| 341 | + SENTRY_URL: ${{ secrets.SENTRY_URL }} |
| 342 | + with: |
| 343 | + sourcemaps: '.output/public/_nuxt' |
| 344 | + url_prefix: '~/_nuxt' |
| 345 | + environment: ${{ github.ref_name }} |
| 346 | + version: ${{ steps.version.outputs.short }} |
| 347 | + ignore_missing: true |
0 commit comments