How to run GitHub Actions workflows locally?
Solution 1:
There are tools like the already-mentioned act
, but they are not perfect.
You are not alone with this issue. Similar problems are:
- how to test Jenkins builds locally
- how to test GitLab CI builds locally
- how to test Circle CI builds locally
- how to test XXXX builds locally
And my solution for these problems is:
- avoid functionalities provided by your CI tools (GitHub Actions, Gitlab CI, etc)
- write as much as possible in CI-agnostic way (BASH scripts, PowerShell scripts, Gradle scripts, NPM scripts, Dockerfiles, Ansible scripts - anything you know)
- invoke those scripts from your CI tool. In GitHub actions:
run: your command to run
Solution 2:
You can use nektos/act which supports yaml syntax since 0.2.0 (prerelease).
Check out their latest release.
Solution 3:
One way to test Github actions is to create a private repo, and iterate the actions conf there. So you can avoid polluting the actual repo with broken commits.
I know, this is not a direct answer to the question - this is not a local way. But this didn’t occur to me at first and I think this could be enough for many use cases.
Solution 4:
your best bet is https://github.com/nektos/act however (prior to 0.2.0) it doesn't support yaml syntax yet, though there is a lot of interest aka: https://github.com/nektos/act/issues/80 https://github.com/nektos/act/issues/76 and https://github.com/nektos/act/issues/74
Gitlab has gitlab-runner exec docker job-name
but that's Gitlab :)