Running GitHub Actions Locally | Sonatype Open Source Community Handbook

Running GitHub Actions Locally

You can locally test the GitHub Actions defined in this your project using nektos act.

Setup

The first time you run act, it can take a long time (with no output) to download the various Docker goodies. Give it time before deciding it is stuck.

Simply run:

act

Rancher Desktop on Mac

If you are using Rancher Desktop on Mac, you may see errors like this:

%  act -j build
INFO[0000] Using docker host 'unix:///var/run/docker.sock', and daemon socket 'unix:///var/run/docker.sock'
[Continuous Integration/build] 🚀  Start image=ghcr.io/catthehacker/ubuntu:act-latest
[Continuous Integration/build]   🐳  docker pull image=ghcr.io/catthehacker/ubuntu:act-latest platform= username= forcePull=true
Error: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

You can print out your Docker contexts with the following command:

% docker context ls
NAME                DESCRIPTION                               DOCKER ENDPOINT                         ERROR
default             Current DOCKER_HOST based configuration   unix:///var/run/docker.sock
rancher-desktop *   Rancher Desktop moby context              unix:///Users/bhamail/.rd/docker.sock

You can set the DOCKER_HOST environment variable as shown below which will allow act to use the correct Docker context:

export DOCKER_HOST=$(docker context inspect | jq -r '.[0].Endpoints.docker.Host')

See: slight modification that helps for rancher desktop

Apple Silicon

If running on Apple Silicon (ARM), launch act with this flag:

   act --container-architecture linux/amd64

Without this flag, I saw this warning:

WARN  ⚠ You are using Apple M-series chip and you have not specified container architecture, you might encounter issues while running act. If so, try running it with '--container-architecture linux/amd64'. ⚠

and this error:

...   🐳  docker exec cmd=[bash --noprofile --norc -e -o pipefail /var/run/act/workflow/1] user= workdir=
| docker compose build
[+] Building 0.0s (0/0)
| permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get "http://%2Fvar%2Frun%2Fdocker.sock/_ping": dial unix /var/run/docker.sock: connect: permission denied
...

Usage

To get a list of available jobs, run:

    $ act -l

To run a specific job, use the -j flag:

    $ act -j <job-name>

For example, to run the build job from the ci.yml file, use this command:

    $ act --workflows .github/workflows/ci.yml -j build