Geavanceerd
Zoeken inHow-to-gidsen
Zo zoek je
  • Typ de taak in je eigen woorden (poort vinden, firewall openen, schijf vol) of plak een foutmelding tussen aanhalingstekens.
  • Kies "Snel antwoord" om alleen de commando's te zien, of een gebied om in één vakgebied te blijven.
  • "twee woorden" vindt precies die zin.
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken
Probeer:

How-to 241CI/CD · GitHub

How to run GitHub Actions locally with act

Change the workflow, commit, push, wait three minutes, see a typo, repeat — debugging GitHub Actions this way is slow and fills the history with "fix ci" commits. act runs your workflows on your own machine in Docker containers that look like GitHub's runners. This how-to lists and runs jobs, passes secrets and event data, picks a runner image, and explains what act cannot do.

  • 5 Lessen
  • 3 Commando's

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

$ als gewone gebruiker# als root (of met sudo)

241.1

The quick answer

act -l
act pull_request -j test
act push -j build --secret-file .secrets --var-file .vars

Commando's in deze les

241.2

Step by step

  1. Install act (a single binary; see its releases or your package manager) and have Docker running.
  2. List the jobs (line 1) — shows each workflow, job and the events that trigger it.
  3. Run one job (line 2) — act EVENT -j JOB. Without -j all jobs for that event run. The first run asks which runner image size to use: Save the choice or set it: act -P ubuntu-latest=catthehacker/ubuntu:act-latest.
    • micro — tiny, many tools missing;
    • medium (catthehacker/ubuntu:act-latest) — good default;
    • large — close to GitHub's image, but many GB.
  4. Secrets and variables (line 3) — put test values in files that are **in .gitignore**:
.secrets
REGISTRY_TOKEN=test-token-not-real

Never use production secrets locally.

  1. Event data — test a workflow that reads the PR or tag:
event.json
{ "pull_request": { "head": { "ref": "feature/login" }, "base": { "ref": "main" } } }
act pull_request -e event.json -j test
  1. Fast feedback loop — act -j test --reuse keeps the container between runs; --dryrun (-n) only shows what would run.
  2. Know the limits — no real GITHUB_TOKEN permissions, OIDC to clouds does not work, services and caches behave differently, macOS/Windows runners cannot run. Use act for logic and scripts; the final check is still a real run on GitHub.
  3. Lint too — actionlint finds syntax and expression errors in seconds, before any run.

Commando's in deze les

241.3

Check that it worked

act -l lists your jobs; act pull_request -j test ends with Job succeeded for a working job and shows the same error as GitHub for a broken one; after the fix the real GitHub run is green on the first try.

Commando's in deze les

241.4

Common problems

ProblemCauseFix
command not found inside the jobMicro image without that tool.Medium or large image (-P).
Cannot connect to the Docker daemonDocker not running or no rights.Start Docker; add your user to the docker group.
Step using OIDC or GITHUB_TOKEN failsNot available locally.Skip that step locally (if: ${{ !env.ACT }}).
Secrets committed by mistake.secrets not ignored.Add it to .gitignore; rotate the secret.
Different result than on GitHubDifferent image or tool versions.Use the large image for that test; final run on GitHub.
ARM Mac errorsImages built for amd64.--container-architecture linux/amd64.

241.5

Go further

1Why use act?

It runs workflows locally in Docker, so you can test changes in seconds instead of pushing and waiting.

2What does act not replace?

Real GitHub features such as GITHUB_TOKEN permissions and OIDC; the final check is still a run on GitHub.

Alle commando's in dit hoofdstuk