Setting Up Local Testing of GitHub Actions
Testing GitHub Actions locally can help speed up your development process by avoiding frequent pushes to GitHub.
1. Prerequisites
Before you begin, ensure you have the following installed:
- Git: Download Git
- Docker: Install Docker
- act CLI:
act
is a tool to run GitHub Actions locally.- Install via Homebrew (macOS/Linux):
brew install act
- Install on other platforms: act GitHub Repository
- Install via Homebrew (macOS/Linux):
2. Installing act
-
Verify installation by running:
act --version
-
If
act
is not found, ensure your PATH includes the directory whereact
is installed.
3. Setting Up Your Repository
Ensure your GitHub Actions workflows are in the .github/workflows/
directory of your repository. If no workflows exist, create a new file, e.g., .github/workflows/test.yml
.
Example workflow file:
name: CI Test
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Run a sample command
run: echo "Hello, World!"
4. Configuring act
4.1 Choosing a Docker Image
act
uses Docker images to simulate GitHub Actions runners. Use the -P
flag to specify a platform (e.g., ubuntu-latest
).
Example:
act -P ubuntu-latest=nektos/act-environments-ubuntu:18.04
You can also configure default images by creating a .actrc
file in your home directory:
-P ubuntu-latest=nektos/act-environments-ubuntu:18.04
4.2 Providing Secrets
If your workflow uses secrets, define them in a .secrets
file:
MY_SECRET=supersecretvalue
Run act
with:
act -s MY_SECRET=supersecretvalue
Alternatively, load secrets from the .secrets
file:
act --secret-file .secrets
5. Running act
Navigate to your repository and execute act
:
act
Common Flags
-j
: Run a specific job.act -j build
-e
: Use a specific event file.act -e event.json
-n
: Dry run (no actions are executed).act -n
6. Debugging and Logs
To view detailed logs:
act -v
If a workflow fails, act
will output error messages and stack traces for debugging.
7. Limitations of act
- AWS OIDC does not seem to work with
act
. Might be added in the future. Just test once and see if it works. Do not spend time on this. Deploy to GitHub and test the OIDC authentication there.
By following these steps, you can effectively test and debug GitHub Actions workflows locally, saving time and improving reliability.