Chapitre 1 · Leçon 1
Automatiser lint, tests et déploiement
Section 1
Step 1
Le workflow CI est déclenché à chaque push et pull request. Il vérifie la qualité du code avant tout merge.
.github/workflows/ci.yml
1name: CI
2
3on:
4 push:
5 branches: [main, develop]
6 pull_request:
7 branches: [main]
8
9env:
10 NODE_VERSION: '20'
11 PNPM_VERSION: '9'
12
13jobs:
14 lint-and-test:
15 name: Lint, typecheck & tests
16 runs-on: ubuntu-latest
17
18 services:
19 postgres:
20 image: postgres:16-alpine
21 env:
22 POSTGRES_DB: test_db
23 POSTGRES_USER: test_user
24 POSTGRES_PASSWORD: test_pass
25 ports: ['5432:5432']
26 options: >-
27 --health-cmd pg_isready
28 --health-interval 10s
29 --health-timeout 5s
30 --health-retries 5
31
32 steps:
33 - name: Checkout code
34 uses: actions/checkout@v4
35
36 - name: Setup pnpm
37 uses: pnpm/action-setup@v4
38 with:
39 version: ${{ env.PNPM_VERSION }}
40
41 - name: Setup Node.js
42 uses: actions/setup-node@v4
43 with:
44 node-version: ${{ env.NODE_VERSION }}
45 cache: 'pnpm'
46
47 - name: Install dependencies
48 run: pnpm install --frozen-lockfile
49
50 - name: Typecheck
51 run: pnpm tsc --noEmit
52
53 - name: Lint
54 run: pnpm lint
55
56 - name: Apply migrations
57 env:
58 DATABASE_URL: postgresql://test_user:test_pass@localhost:5432/test_db
59 run: pnpm prisma migrate deploy
60
61 - name: Run tests
62 env:
63 DATABASE_URL: postgresql://test_user:test_pass@localhost:5432/test_db
64 JWT_SECRET: test-secret-32-chars-minimum-here
65 run: pnpm test --coverage
66
67 - name: Upload coverage
68 uses: codecov/codecov-action@v4
69 with:
70 token: ${{ secrets.CODECOV_TOKEN }}Step 2
Le workflow CD se déclenche après un merge sur main. Il build l'image Docker, la push sur le registre et déploie sur le VPS via SSH.