using act to run github actions locally
act is a tool that lets you run github actions locally. it’s useful for testing and debugging workflows without pushing to your repo.
problem
testing github actions can be slow and cumbersome. each change requires a commit, push, and wait for the action to run on github’s servers.
solution
act allows you to run actions locally, speeding up the development cycle and reducing the load on github’s servers.
installation and setup
install act on mac using homebrew:
brew install act
ensure docker is installed and running, as act uses it to simulate the github actions environment.
mac m1 installation
architecture error
INFO[0000] Using docker host 'unix:///Users/outatimedev/.docker/run/docker.sock', and daemon socket 'unix:///Users/outatimedev/.docker/run/docker.sock'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'. ⚠[CI/Build, Push, and Deploy] 🚀 Start image=catthehacker/ubuntu:act-latest[CI/Build, Push, and Deploy] 🐳 docker pull image=catthehacker/ubuntu:act-latest platform= username= forcePull=true^CError: context canceled
to solve just add --container-architecture linux/amd64
to your act command:
act --container-architecture linux/amd64
docker socket error
Error: failed to start container: Error response from daemon: error while creating mount source path '/host_mnt/Users/outatimedev/.docker/run/docker.sock': mkdir /host_mnt/Users/outatimedev/.docker/run/docker.sock: operation not supported
figure out which socket is being used by docker:
➜ outatime git:(master) ✗ docker context lsNAME DESCRIPTION DOCKER ENDPOINT ERRORdefault Current DOCKER_HOST based configuration unix:///var/run/docker.sockdesktop-linux * Docker Desktop unix:///Users/outatimedev/.docker/run/docker.sock
so we get this error because we are running docker desktop and the socket is located in ~/.docker/run/docker.sock
.
to solve this issue, you need to create a symlink to the docker socket:
# you might need to use sudoln -s /Users/outatimedev/.docker/run/docker.sock /var/run/docker.sock
.actrc file
you can create a ~/.actrc
file in your project directory to store default options for act:
--container-architecture linux/amd64
basic usage
run all actions:
act
run a specific job:
act -j <job_name>
use a specific event:
act push
common use cases
- testing workflow changes:
act -W .github/workflows/my-workflow.yml
- debugging a specific job:
act -j build -s GITHUB_TOKEN=<your_token>
- using custom docker image:
act -P ubuntu-latest=myuser/myimage:latest
potential pitfalls
- secrets: act doesn’t have access to your github secrets by default. use
-s
flag to pass secrets:
act -s MY_SECRET=value
-
resource limitations: some actions might require more resources than your local machine can provide.
-
platform-specific actions: actions designed for specific os or architectures might not work locally.
conclusion
act is a powerful tool for local github actions development. it speeds up testing, simplifies debugging, and reduces dependency on github’s infrastructure. remember to keep your local environment as close to github’s as possible for accurate results.
key takeaways:
- install with homebrew on mac
- use docker to simulate github’s environment
- easily test specific jobs or events
- be mindful of secrets and resource limitations