Testing Github Actions Locally¶
The Github Actions workflows can be tested locally using nektos/act which allows you to test Github Actions locally, without pushing changes to the remote.
Prerequisites¶
- Install the
act
tool, docs. - Install the Github CLI (
gh
) for authentication: linux, macos. -
Authenticate with the Github CLI:
gh auth login
Testing Workflows¶
Testing a Workflow that uses a Matrix Strategy¶
bash
act -j build --workflows .github/workflows/tox_verify.yaml -s GITHUB_TOKEN=$(gh auth token) --matrix python:3.10
Testing Release Builds¶
Release builds require the ref
input to be specified. To test a release build locally:
-
Create a JSON file specifying the input data required for a release build (the release tag), e.g,
event.json
:json { "ref": "refs/tags/stable@v4.2.0" }
-
Run
act
and specify the workflow file, the Github token, and the event file:bash act -j build --workflows .github/workflows/fixtures_feature.yaml -s GITHUB_TOKEN=$(gh auth token) -e event.json