GitHub Actions

CI/CD natif GitHub - automatiser workflows sur push, PR, planification, gratuit pour repos publics

TL;DR

Quoi : Plateforme CI/CD et d’automatisation intégrée à GitHub.

Pourquoi : Intégration native GitHub, gratuit pour les repos publics, marketplace d’actions, builds matriciels.

Quick Start

Créez .github/workflows/ci.yml :

name: CI

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: '20'
      - run: npm ci
      - run: npm test

Poussez pour déclencher le workflow.

Cheatsheet

DéclencheurSyntaxe
Pushon: push
Pull requeston: pull_request
Planifiéon: schedule: - cron: '0 0 * * *'
Manuelon: workflow_dispatch
Autre workflowon: workflow_call

Gotchas

Matrix builds

jobs:
  test:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node: [18, 20, 22]
        os: [ubuntu-latest, windows-latest]
    steps:
      - uses: actions/setup-node@v4
        with:
          node-version: ${{ matrix.node }}

Secrets and environment variables

jobs:
  deploy:
    runs-on: ubuntu-latest
    env:
      NODE_ENV: production
    steps:
      - run: echo ${{ secrets.API_KEY }}
      - run: echo $NODE_ENV

Caching dependencies

- uses: actions/cache@v4
  with:
    path: ~/.npm
    key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}

Conditional steps

- name: Deploy
  if: github.ref == 'refs/heads/main'
  run: ./deploy.sh

Artifacts

- uses: actions/upload-artifact@v4
  with:
    name: build
    path: dist/

Next Steps