<!--
  canonical-url: https://www.avonture.be/fr/blog/act-github-actions-locally
  published:     2026-11-30
  This is a static plain-Markdown mirror generated at build time.
  Visit the canonical URL above for the fully rendered page, with images and interactive components.
-->

# act : lancez vos GitHub Actions en local avant de pousser

> Arrêtez les commits « fix CI ». act exécute vos workflows GitHub Actions dans des containers Docker locaux : une erreur de formatage ou de lint apparaît en quelques secondes, sans aucun commit.

---
![act : lancez vos GitHub Actions en local avant de pousser](/img/v2/github_act.webp)

**TL;DR**

Tester un workflow GitHub Actions, normalement, c'est committer, pousser, attendre, et recommencer pour chaque petite erreur. `act` lit vos fichiers `.github/workflows` et exécute les jobs dans des containers Docker locaux : vous avez la réponse en quelques secondes, sans rien pousser. Cet article utilise un workflow Prettier et ESLint dans un container jetable, puis l'applique à votre propre repository.

`fix CI`. `fix CI again`. `really fix CI`. `please`. On a tous laissé ce genre d'historique dans une branch, chaque commit suivi de quelques minutes à regarder un spinner, pour apprendre finalement qu'un seul mot d'un fichier YAML était faux.

À la fin de cet article, vous lancerez votre workflow sur votre propre machine, et vous ne le pousserez qu'une fois au vert.

## Le voir à l'œuvre avec Docker {#seeing-it-in-action-with-docker}

*Vous connaissez déjà act ? [Passez directement à son utilisation sur votre propre repository](#use-it-on-your-own-repository) — ce chapitre n'est qu'un container jetable pour essayer sans risque.*

Un petit projet avec un vrai workflow : un job vérifie le formatage avec Prettier, un autre lance ESLint. Pas de push ni de compte GitHub ici, juste une commande :

```bash
/demo # act -j formatting
[Code quality/formatting] ⭐ Run Main npx --yes prettier@3 --check .
| Checking formatting...
| [warn] app.js
| [warn] Code style issues found in the above file. Run Prettier with --write to fix.
[Code quality/formatting]   ❌  Failure - Main npx --yes prettier@3 --check . [1.138150374s]
[Code quality/formatting] 🏁  Job failed

/demo # act -j lint
[Code quality/lint] ⭐ Run Main npx eslint .
| /demo/app.js
|   3:13  error  'unknownVariable' is not defined  no-undef
|
| ✖ 1 problem (1 error, 0 warnings)
[Code quality/lint]   ❌  Failure - Main npx eslint . [309.333448ms]
[Code quality/lint] 🏁  Job failed
```

C'est exactement le message que vous auriez lu dans l'interface GitHub, sans le commit, le push et l'attente. Pour essayer, cette image contient `act` et ce projet. Créez-la dans `/tmp/act` :

**Project: /tmp/act**

**Dockerfile**

```docker
# syntax=docker/dockerfile:1

# act, plus a small project whose GitHub Actions workflow currently fails.
# Bump ACT_VERSION during a /freshness pass.
FROM docker:29-cli

ARG ACT_VERSION=0.2.99
ARG TARGETARCH=amd64
RUN apk add --no-cache git && \
    case "${TARGETARCH}" in amd64) arch=x86_64 ;; *) arch=arm64 ;; esac && \
    wget -qO- "https://github.com/nektos/act/releases/download/v${ACT_VERSION}/act_Linux_${arch}.tar.gz" | \
    tar -xz -C /usr/local/bin act

WORKDIR /demo

COPY <<'YML' .github/workflows/quality.yml
name: Code quality
on: push

jobs:
  formatting:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - run: npx --yes prettier@3 --check .
  lint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - run: npm install --no-save eslint@10
      - run: npx eslint .
YML

COPY <<'JS' app.js
const answer   =  42
console.log( "Hello" )
console.log(unknownVariable)
JS

COPY <<'CFG' eslint.config.mjs
export default [
  {
    languageOptions: { globals: { console: "readonly" } },
    rules: { "no-undef": "error" },
  },
];
CFG

# act uses this image to play the role of GitHub's ubuntu-latest runner
COPY <<'RC' /root/.actrc
-P ubuntu-latest=node:24-bookworm-slim
RC

RUN git init -q && git add . && \
    git -c user.name=Demo -c user.email=demo@example.com commit -qm "Initial commit"

ENTRYPOINT []
CMD ["/bin/sh"]
```

> **Note:**
>
> Maintenant, lance 'docker build -t act-demo .' pour construire l'image Docker puis 'docker run --rm -it -v /var/run/docker.sock:/var/run/docker.sock act-demo' pour ouvrir un shell dans le container éphémère.

> **Le socket Docker donne le contrôle total:**
>
> Monter `/var/run/docker.sock` donne à ce container le contrôle de votre daemon Docker, donc de votre machine. `act` a besoin de cet accès où qu'il tourne. N'exécutez que des workflows de confiance : une étape `run:` locale, c'est du vrai code, et il tourne chez vous.

Voyez ce qui est disponible, puis lancez un job, et enfin le workflow complet :

```bash
/demo # act -l
INFO[0000] Using docker host 'unix:///var/run/docker.sock', and daemon socket 'unix:///var/run/docker.sock'
Stage  Job ID      Job name    Workflow name  Workflow file  Events
0      lint        lint        Code quality   quality.yml    push
0      formatting  formatting  Code quality   quality.yml    push

/demo # act -j formatting
/demo # act
```

Maintenant, corrigez le code, comme vous le feriez dans votre éditeur, et relancez :

```bash
/demo # printf 'const answer = 42;\nconsole.log("Hello", answer);\n' > app.js
/demo # act --quiet 2>&1 | grep 'Job '
[Code quality/formatting] 🏁  Job succeeded
[Code quality/lint      ] 🏁  Job succeeded
```

Deux jobs au vert, et vous n'avez toujours rien committé : `act` copie votre dossier de travail tel quel.

## Pourquoi on dirait la vraie CI {#why-it-feels-like-the-real-ci}

* `act` lit lui-même votre fichier de workflow : il n'y a rien à traduire, les jobs, les steps, `uses:` et `needs:` gardent leur sens.
* Chaque job tourne dans son propre container, et c'est pour ça que vos outils locaux et votre `PATH` ne peuvent pas masquer une dépendance manquante.
* C'est une simulation du runner, pas le runner : l'image que vous choisissez décide des outils présents, et certaines fonctionnalités propres à GitHub se comportent différemment ou sont absentes.

Si vous avez lu mon article sur [Dagger](/blog/dagger-python), l'objectif vous semblera familier, mais le mécanisme diffère. Dagger vous demande de réécrire les étapes sous forme de code portable, là où `act` rejoue votre syntaxe GitHub existante, telle quelle. Il n'y a rien à migrer.

## Utilisez-le sur votre propre repository {#use-it-on-your-own-repository}

### Donnez un vrai domicile à act {#give-act-a-permanent-home}

`/tmp/act` n'était là que pour la démo : il disparaît au prochain redémarrage, et son image embarque un projet de démonstration dont vous n'avez pas besoin. Pour vos propres projets, gardez un Dockerfile avec `act` seul dans `~/tools/act` : l'image pourra être reconstruite à tout moment (nouvelle machine, `docker image prune`, nouvelle version d'`act`) :

**Project: \~/tools/act**

**Dockerfile**

```docker
# syntax=docker/dockerfile:1

# act alone, to run the GitHub Actions workflows of any project on this machine.
# Build: docker build -t act-cli ~/tools/act
# Bump ACT_VERSION during a /freshness pass.
FROM docker:29-cli

ARG ACT_VERSION=0.2.99
ARG TARGETARCH=amd64
RUN apk add --no-cache git && \
    case "${TARGETARCH}" in amd64) arch=x86_64 ;; *) arch=arm64 ;; esac && \
    wget -qO- "https://github.com/nektos/act/releases/download/v${ACT_VERSION}/act_Linux_${arch}.tar.gz" | \
    tar -xz -C /usr/local/bin act

# Default runner image, used when the project has no .actrc of its own.
# Without it, act asks which image to use on its first run.
COPY <<'RC' /root/.actrc
-P ubuntu-latest=node:24-bookworm-slim
RC

WORKDIR /workspace
ENTRYPOINT ["act"]
```

Construisez-la sous son nom définitif, `act-cli` :

```bash
$ docker build -t act-cli ~/tools/act
```

Ensuite, depuis la racine de n'importe quel projet, là où se trouve `.github/` :

```bash
$ docker run --rm -it --network host -v /var/run/docker.sock:/var/run/docker.sock -v "$PWD":/workspace act-cli -l

Stage  Job ID                   Job name                                            Workflow name                      Workflow file           Events
0      update-readme-with-blog  update-readme-with-blog                             Latest blog post workflow          blog-post-workflow.yml  schedule,workflow_dispatch
0      deploy                   Deploy blog on avonture.be                          Deploy blog on avonture.be         deploy.yml              push,workflow_dispatch
0      build                    Build on Node ${{ matrix.node }}                    Node upgrade check                 node-upgrade-check.yml  workflow_dispatch
0      lint                     Lint JS/JSX and CSS                                 Code quality (ESLint + stylelint)  quality.yml             push,pull_request
0      snippet-lint             Lint the code files articles ship (blog/**/files/)  Code quality (ESLint + stylelint)  quality.yml             pull_request,push
0      internal-links           Internal links on new/changed articles              Code quality (ESLint + stylelint)  quality.yml             pull_request,push
0      e2e                      Playwright smoke/hydration (build)                  Code quality (ESLint + stylelint)  quality.yml             push,pull_request
```

C'est le repository de ce blog : quatre fichiers de workflow, sept jobs, lus en une seconde sans rien pousser.

Tout ce qui suit `act-cli` est passé à `act` : `-l` liste les jobs, `-j lint` en lance un. `--network host` permet aux jobs d'atteindre les serveurs de cache et d'artefacts qu'`act` ouvre dans son propre container.

### Optionnel : en faire une commande `act` {#optional-make-it-an-act-command}

*La ligne `docker run` ci-dessus vous suffit ? Passez [aux options](#the-options-you-need).*

Cette commande est longue. Une fonction shell la transforme en un simple `act`, disponible dans tous les dossiers. Elle a son propre fichier dans un dossier que votre shell charge au démarrage, la même organisation que dans [mon workflow ZSH modulaire](/blog/modular-zsh-workflow) : votre fichier rc reste court, et désinstaller l'outil revient à supprimer un fichier.

**act.sh**

```bash
# act through Docker: run the GitHub Actions workflows of the current
# project, from anywhere. Works in zsh and bash: save it as
# ~/.zsh/fns/act.zsh or ~/.bash/fns/act.sh (see the article).
#
#   act -l              -> list the jobs
#   act -j lint         -> run one job
#   act                 -> run the whole push workflow
#
# Run it from the root of the project, where .github/ lives.
act() {
    local image="act-cli"
    # Permanent home of the Dockerfile, so the image can always be rebuilt.
    local build_dir="${HOME}/tools/act"
    # Shown as is in the messages, so the command can be copied for any user.
    # shellcheck disable=SC2016
    local build_dir_shown='${HOME}/tools/act'

    if ! command -v docker >/dev/null 2>&1; then
        printf '\e[31mError: docker is not installed or not in your PATH.\e[0m\n' >&2
        return 1
    fi

    if ! docker image inspect "${image}" >/dev/null 2>&1; then
        printf '\e[31mError: the Docker image "%s" does not exist on this machine.\e[0m\n\n' "${image}" >&2
        printf 'How to continue:\n' >&2
        if [[ -f "${build_dir}/Dockerfile" ]]; then
            printf '  1. docker build -t %s "%s"\n' "${image}" "${build_dir_shown}" >&2
            printf '  2. Run your act command again.\n' >&2
        else
            printf '  1. Get the Dockerfile from https://www.avonture.be/blog/act-github-actions-locally\n' >&2
            printf '     and save it as %s/Dockerfile\n' "${build_dir_shown}" >&2
            printf '  2. docker build -t %s "%s"\n' "${image}" "${build_dir_shown}" >&2
            printf '  3. Run your act command again.\n' >&2
        fi
        return 1
    fi

    # -t only when both ends are a terminal, so piping the output still works.
    local tty_flags="-i"
    [[ -t 0 && -t 1 ]] && tty_flags="-it"

    # act drives the Docker daemon through its socket, which is root-equivalent
    # anyway: the container runs as root, with only the capability to read
    # every file of the project (a .secrets file is often chmod 600).
    # The act-cache volume keeps the downloaded actions between two runs.
    # --network host: the jobs must reach the cache and artifact servers
    # that act opens in this container.
    docker run --rm "${tty_flags}" \
        --network host \
        -v /var/run/docker.sock:/var/run/docker.sock \
        -v "${PWD}:/workspace" \
        -w /workspace \
        -v act-cache:/root/.cache \
        --read-only \
        --tmpfs /tmp \
        --cap-drop ALL \
        --cap-add DAC_READ_SEARCH \
        --security-opt no-new-privileges:true \
        "${image}" "$@"
}
```

Le code est le même pour zsh et bash ; seuls le dossier et le chargeur changent.

**1. Créez le fichier** dans `~/.zsh/fns/` :

**Project: \~/.zsh/fns**

**act.zsh**

```bash
# act through Docker: run the GitHub Actions workflows of the current
# project, from anywhere. Works in zsh and bash: save it as
# ~/.zsh/fns/act.zsh or ~/.bash/fns/act.sh (see the article).
#
#   act -l              -> list the jobs
#   act -j lint         -> run one job
#   act                 -> run the whole push workflow
#
# Run it from the root of the project, where .github/ lives.
act() {
    local image="act-cli"
    # Permanent home of the Dockerfile, so the image can always be rebuilt.
    local build_dir="${HOME}/tools/act"
    # Shown as is in the messages, so the command can be copied for any user.
    # shellcheck disable=SC2016
    local build_dir_shown='${HOME}/tools/act'

    if ! command -v docker >/dev/null 2>&1; then
        printf '\e[31mError: docker is not installed or not in your PATH.\e[0m\n' >&2
        return 1
    fi

    if ! docker image inspect "${image}" >/dev/null 2>&1; then
        printf '\e[31mError: the Docker image "%s" does not exist on this machine.\e[0m\n\n' "${image}" >&2
        printf 'How to continue:\n' >&2
        if [[ -f "${build_dir}/Dockerfile" ]]; then
            printf '  1. docker build -t %s "%s"\n' "${image}" "${build_dir_shown}" >&2
            printf '  2. Run your act command again.\n' >&2
        else
            printf '  1. Get the Dockerfile from https://www.avonture.be/blog/act-github-actions-locally\n' >&2
            printf '     and save it as %s/Dockerfile\n' "${build_dir_shown}" >&2
            printf '  2. docker build -t %s "%s"\n' "${image}" "${build_dir_shown}" >&2
            printf '  3. Run your act command again.\n' >&2
        fi
        return 1
    fi

    # -t only when both ends are a terminal, so piping the output still works.
    local tty_flags="-i"
    [[ -t 0 && -t 1 ]] && tty_flags="-it"

    # act drives the Docker daemon through its socket, which is root-equivalent
    # anyway: the container runs as root, with only the capability to read
    # every file of the project (a .secrets file is often chmod 600).
    # The act-cache volume keeps the downloaded actions between two runs.
    # --network host: the jobs must reach the cache and artifact servers
    # that act opens in this container.
    docker run --rm "${tty_flags}" \
        --network host \
        -v /var/run/docker.sock:/var/run/docker.sock \
        -v "${PWD}:/workspace" \
        -w /workspace \
        -v act-cache:/root/.cache \
        --read-only \
        --tmpfs /tmp \
        --cap-drop ALL \
        --cap-add DAC_READ_SEARCH \
        --security-opt no-new-privileges:true \
        "${image}" "$@"
}
```

**2. Chargez le dossier depuis `~/.zshrc`.** C'est déjà fait si vous avez suivi un de mes articles ["Ollama daily use"](/series/ollama-daily-use). Sinon, ajoutez à la fin de `~/.zshrc` :

```zsh title="~/.zshrc"
for fn_file in ~/.zsh/fns/*.zsh; do
  source "$fn_file"
done
```

**3. Ouvrez un nouveau terminal** (ou lancez `exec zsh`).

**1. Créez le fichier** dans `~/.bash/fns/` :

**Project: \~/.bash/fns**

**act.sh**

```bash
# act through Docker: run the GitHub Actions workflows of the current
# project, from anywhere. Works in zsh and bash: save it as
# ~/.zsh/fns/act.zsh or ~/.bash/fns/act.sh (see the article).
#
#   act -l              -> list the jobs
#   act -j lint         -> run one job
#   act                 -> run the whole push workflow
#
# Run it from the root of the project, where .github/ lives.
act() {
    local image="act-cli"
    # Permanent home of the Dockerfile, so the image can always be rebuilt.
    local build_dir="${HOME}/tools/act"
    # Shown as is in the messages, so the command can be copied for any user.
    # shellcheck disable=SC2016
    local build_dir_shown='${HOME}/tools/act'

    if ! command -v docker >/dev/null 2>&1; then
        printf '\e[31mError: docker is not installed or not in your PATH.\e[0m\n' >&2
        return 1
    fi

    if ! docker image inspect "${image}" >/dev/null 2>&1; then
        printf '\e[31mError: the Docker image "%s" does not exist on this machine.\e[0m\n\n' "${image}" >&2
        printf 'How to continue:\n' >&2
        if [[ -f "${build_dir}/Dockerfile" ]]; then
            printf '  1. docker build -t %s "%s"\n' "${image}" "${build_dir_shown}" >&2
            printf '  2. Run your act command again.\n' >&2
        else
            printf '  1. Get the Dockerfile from https://www.avonture.be/blog/act-github-actions-locally\n' >&2
            printf '     and save it as %s/Dockerfile\n' "${build_dir_shown}" >&2
            printf '  2. docker build -t %s "%s"\n' "${image}" "${build_dir_shown}" >&2
            printf '  3. Run your act command again.\n' >&2
        fi
        return 1
    fi

    # -t only when both ends are a terminal, so piping the output still works.
    local tty_flags="-i"
    [[ -t 0 && -t 1 ]] && tty_flags="-it"

    # act drives the Docker daemon through its socket, which is root-equivalent
    # anyway: the container runs as root, with only the capability to read
    # every file of the project (a .secrets file is often chmod 600).
    # The act-cache volume keeps the downloaded actions between two runs.
    # --network host: the jobs must reach the cache and artifact servers
    # that act opens in this container.
    docker run --rm "${tty_flags}" \
        --network host \
        -v /var/run/docker.sock:/var/run/docker.sock \
        -v "${PWD}:/workspace" \
        -w /workspace \
        -v act-cache:/root/.cache \
        --read-only \
        --tmpfs /tmp \
        --cap-drop ALL \
        --cap-add DAC_READ_SEARCH \
        --security-opt no-new-privileges:true \
        "${image}" "$@"
}
```

**2. Chargez le dossier depuis `~/.bashrc`.** Ajoutez à la fin de `~/.bashrc` (le test `-r` évite qu'un dossier vide affiche une erreur) :

```bash title="~/.bashrc"
for fn_file in ~/.bash/fns/*.sh; do
  [[ -r "$fn_file" ]] && source "$fn_file"
done
```

**3. Ouvrez un nouveau terminal** (ou lancez `exec bash`).

Vérifiez que le shell connaît la fonction : `type act` doit répondre `act is a shell function`. La fonction monte le **dossier courant** comme `/workspace`, lancez-la donc depuis la racine de votre projet.

Si l'image manque, la fonction n'échoue pas avec une erreur Docker cryptique, elle vous explique comment la reconstruire :

```text
Error: the Docker image "act-cli" does not exist on this machine.

How to continue:
  1. docker build -t act-cli "${HOME}/tools/act"
  2. Run your act command again.
```

Et si `~/tools/act/Dockerfile` a disparu lui aussi, le message renvoie vers cet article pour le récupérer.

> **Elle masque un act natif:**
>
> La fonction s'appelle `act`, elle prend donc le pas sur un binaire `act` installé localement, avec Homebrew ou `gh extension install nektos/gh-act` par exemple. Si vous l'installez nativement un jour, supprimez la fonction ou renommez-la.

### Les options utiles {#the-options-you-need}

La suite de ce chapitre écrit `act …`. Sans la fonction, mettez la ligne `docker run … act-cli` à la place.

| Vous voulez                                                              | Commande                                    |
| ------------------------------------------------------------------------ | ------------------------------------------- |
| Lancer un seul job                                                       | `act -j lint`                               |
| Simuler une pull request                                                 | `act pull_request`                          |
| Voir le plan, sans exécution                                             | `act -n`                                    |
| Fournir des secrets depuis un fichier                                    | `act --secret-file .secrets`                |
| Choisir l'image du runner                                                | `act -P ubuntu-latest=<image>`              |
| Passer des artefacts entre jobs (`upload-artifact`, `download-artifact`) | `act --artifact-server-path /tmp/artifacts` |

`actions/cache` fonctionne tel quel : `act` lance son propre serveur de cache. `upload-artifact` et `download-artifact` échouent tant que vous ne démarrez pas le serveur d'artefacts avec `--artifact-server-path`.

### Exemple : les contrôles qualité de ce blog {#example-this-blogs-quality-checks}

Le repository de ce blog, [cavo789/blog](https://github.com/cavo789/blog), contient un vrai `quality.yml`, source de quatre des jobs listés plus haut. `-W` limite `act` à ce fichier :

```bash
$ act -l -W .github/workflows/quality.yml
Stage  Job ID          Job name                                            Workflow name                      Workflow file  Events
0      internal-links  Internal links on new/changed articles              Code quality (ESLint + stylelint)  quality.yml    push,pull_request
0      e2e             Playwright smoke/hydration (build)                  Code quality (ESLint + stylelint)  quality.yml    push,pull_request
0      lint            Lint JS/JSX and CSS                                 Code quality (ESLint + stylelint)  quality.yml    push,pull_request
0      snippet-lint    Lint the code files articles ship (blog/**/files/)  Code quality (ESLint + stylelint)  quality.yml    push,pull_request
```

Lancez le job `lint` avec l'image de runner par défaut, `act -j lint`, et il échoue sur une étape qui passe sur GitHub :

```bash
[Code quality (ESLint + stylelint)/Lint JS/JSX and CSS]   | $ node scripts/check-snippet-sources.mjs
[Code quality (ESLint + stylelint)/Lint JS/JSX and CSS]   | <ref *1> Error: spawnSync git ENOENT
[Code quality (ESLint + stylelint)/Lint JS/JSX and CSS]   ❌  Failure - Main Run lint (ESLint + stylelint) [8.369179434s]
```

Le script appelle `git`, et `node:24-bookworm-slim` ne l'embarque pas, contrairement au runner de GitHub. C'est l'**image du runner** qui joue : l'image slim ne convient qu'aux workflows qui n'ont besoin que de Node. `catthehacker/ubuntu:act-latest`, une image populaire conçue pour `act`, a `git` mais pas `yarn`, donc `setup-node` échoue une étape plus loin. La version non-slim `node:24-bookworm` a les deux :

```bash
$ act -j lint -P ubuntu-latest=node:24-bookworm
[Code quality (ESLint + stylelint)/Lint JS/JSX and CSS] ⭐ Run Main Run lint (ESLint + stylelint)
[Code quality (ESLint + stylelint)/Lint JS/JSX and CSS]   | $ yarn lint:js && yarn lint:css && yarn lint:types && yarn lint:snippets
[Code quality (ESLint + stylelint)/Lint JS/JSX and CSS]   ✅  Success - Main Run lint (ESLint + stylelint) [8.282250914s]
[Code quality (ESLint + stylelint)/Lint JS/JSX and CSS] 🏁  Job succeeded
```

Quand un job échoue en local et passe sur GitHub, regardez d'abord l'image du runner.

Taper `-P` à chaque exécution devient vite pénible. `act` lit un fichier `.actrc` à la racine du projet, une option par ligne, et le fichier du projet l'emporte sur celui par défaut intégré à l'image. Le repository de ce blog contient celui-ci, committé avec les workflows :

```text title=".actrc"
-P ubuntu-latest=node:24-bookworm
```

Désormais, un simple `act -j lint` utilise la bonne image, pour vous et pour quiconque clone le projet.

Et un simple `act`, sans option, joue l'événement `push` : chaque job de chaque workflow déclenché par un push démarre d'un coup, chacun dans son container :

```bash
$ act
[Deploy blog on avonture.be/Deploy blog on avonture.be                               ] ⭐ Run Set up job
[Code quality (ESLint + stylelint)/Lint JS/JSX and CSS                               ] ⭐ Run Set up job
[Code quality (ESLint + stylelint)/Lint JS/JSX and CSS                               ] 🚀  Start image=node:24-bookworm
[Code quality (ESLint + stylelint)/Lint the code files articles ship (blog/**/files/)] ⭐ Run Set up job
[Code quality (ESLint + stylelint)/Lint the code files articles ship (blog/**/files/)] 🚀  Start image=node:24-bookworm
[Deploy blog on avonture.be/Deploy blog on avonture.be                               ] 🚀  Start image=node:24-bookworm
[Code quality (ESLint + stylelint)/Internal links on new/changed articles            ] ⭐ Run Set up job
[Code quality (ESLint + stylelint)/Internal links on new/changed articles            ] 🚀  Start image=node:24-bookworm
[Code quality (ESLint + stylelint)/Playwright smoke/hydration (build)                ] ⭐ Run Set up job
[Code quality (ESLint + stylelint)/Playwright smoke/hydration (build)                ] 🚀  Start image=node:24-bookworm
```

Cinq jobs, dont le **deploy**, le [workflow qui publie ce blog](/blog/github-action). Ici il ne peut pas joindre le serveur, parce que les secrets GitHub ne sont pas sur ce PC et que ses variables SSH sont vides, mais c'est de la chance, pas une protection. Nommez le job (`-j lint`) ou le workflow (`-W .github/workflows/quality.yml`) pendant que vous travaillez, et protégez le déploiement lui-même, comme montré plus bas.

### Exemple : un workflow de déploiement {#example-a-deploy-workflow}

`act` ne simule pas les étapes : il les exécute. Un workflow de déploiement lancé avec `act` déploie, exactement comme il le ferait sur GitHub. Voici un projet avec un seul job de déploiement :

```bash
$ act -l
Stage  Job ID  Job name     Workflow name               Workflow file  Events
0      deploy  Deploy site  Deploy site on example.com  deploy.yml     push,workflow_dispatch
```

Son job lit des secrets, comme une clé SSH et un nom d'host, créés dans l'interface web de GitHub.

> **Les secrets de GitHub restent sur GitHub:**
>
> Les valeurs saisies sous *Settings → Secrets and variables → Actions* ne peuvent pas être relues, ni dans l'interface ni via l'API. `act` n'y a pas accès : sans fichier `.secrets`, chaque `secrets.X` est une chaîne vide, et le job échoue à sa première connexion. Pour l'exécuter en local, vous devez fournir chaque valeur vous-même, dans un fichier `.secrets` (`NAME=value`, une par ligne, les mêmes noms que sur GitHub), ajouté à votre `.gitignore`.

D'abord, regardez le plan sans rien exécuter :

```bash
$ act push -n
```

Puis déclenchez le même événement qu'un `git push` :

```bash
$ act push --secret-file .secrets
```

`act workflow_dispatch` le déclenche comme le ferait le bouton **Run workflow**, et `act -j deploy` lance le job quel que soit l'événement.

> **C'est un vrai déploiement:**
>
> Avec de vrais identifiants dans `.secrets`, le job se connecte à votre serveur et déploie **votre dossier de travail tel quel**, modifications non committées comprises. GitHub, lui, aurait déployé le commit poussé. Committez d'abord, ou gardez `-n` tant que vous n'êtes pas sûr.

Si vous ne voulez jamais déployer depuis votre PC, dites-le dans le workflow lui-même, plutôt que de compter sur la présence ou non du bon fichier `.secrets`. `act` définit la variable `ACT` dans chaque job, et GitHub non : cette étape est donc ignorée en local et s'exécute sur GitHub :

```yaml title=".github/workflows/deploy.yml"
      - name: Deploy
        if: ${{ !env.ACT }}
        run: ./deploy.sh
```

Toutes les étapes précédentes tournent quand même (build, tests, packaging), vous vérifiez donc tout jusqu'au déploiement lui-même. La même condition convient pour une notification Slack ou une publication vers un registry.

Si une étape a besoin de `secrets.GITHUB_TOKEN`, que GitHub crée tout seul, fournissez-le vous-même : `-s GITHUB_TOKEN="$(gh auth token)"`.

## Un workflow réutilisable {#a-workflow-you-can-reuse}

L'exemple ci-dessus est volontairement petit, mais le principe passe à l'échelle. Stylelint, shellcheck ou les [outils de qualité Python](/blog/python-qa) ne sont que d'autres jobs dans le même fichier, et chacun peut être lancé seul avec `act -j`. C'est particulièrement confortable pendant l'écriture d'un nouveau workflow : changez une ligne, lancez le job, lisez le résultat, sans un seul commit de bruit dans votre branch.

Cela complète un [hook pre-commit](/blog/git-precommit) plutôt que de le remplacer. Le hook vérifie le commit rapidement, et `act` vous dit si le pipeline lui-même est correct.

## Conclusion {#conclusion}

Au début de cet article, tester un workflow voulait dire quatre commits et beaucoup d'attente. Avec `act`, le retour arrive maintenant en quelques secondes, et votre historique ne contient plus que le commit qui compte. L'exécution sur GitHub reste le juge final, puisqu'une simulation locale ne peut pas tout reproduire, mais elle confirmera surtout ce que vous savez déjà. La prochaine fois que vous touchez un fichier dans `.github/workflows`, lancez `act` d'abord ; l'historique de votre branch vous dira merci.
