-
Notifications
You must be signed in to change notification settings - Fork 0
Testing GitHub Actions Locally with gh and act
gh is GitHub’s command-line interface. It lets us inspect pull requests, workflow runs, logs, and check results without leaving the terminal.
act runs GitHub Actions workflows locally using Docker. This helps detect workflow, dependency, compiler, and test failures before pushing changes and waiting for GitHub CI.
Local act runs approximate GitHub-hosted runners but are not an exact replacement for the official CI environment. Final validation must still happen on GitHub.
Install and authenticate the GitHub CLI:
gh auth login
gh auth statusInstall act as a gh extension:
gh extension install https://github.com/nektos/gh-act
gh act --versionDocker must be installed and running.
List the jobs detected in the workflows:
gh act -lValidate workflow parsing and job dependencies without executing them:
gh act push -n \
-P ubuntu-latest=ghcr.io/catthehacker/ubuntu:act-latestRun only the style job:
gh act push -j style \
-P ubuntu-latest=ghcr.io/catthehacker/ubuntu:act-latest \
--rmRun the tests job:
gh act push -j tests \
-P ubuntu-latest=ghcr.io/catthehacker/ubuntu:act-latest \
--rmIf tests declares needs: style, act will run the style job first.
Some pre-commit hooks modify files. To protect the working repository, run act from a disposable clone:
SOURCE=/path/to/repository
ACT_WORK=$(mktemp -d /tmp/project-act.XXXXXX)
git clone "$SOURCE" "$ACT_WORK"
cd "$ACT_WORK"
gh act push -j tests \
--bind \
-P ubuntu-latest=ghcr.io/catthehacker/ubuntu:act-latest \
--rmThe disposable clone provides valid Git metadata while isolating any changes made by workflow steps.
List recent workflow runs:
gh run listInspect a run:
gh run view RUN_IDShow logs from failed steps:
gh run view RUN_ID --log-failedInspect the checks associated with a pull request:
gh pr checks PR_NUMBERcloe-org maintainers: https://github.com/orgs/cloe-org/teams/cloe-maintainers