I am planning to move our Travis CI build to GitHub Actions using Docker for our per-commit testing.
Can I reproducibly run these new GitHub Actions workflows locally? Is there a generic way to run any GitHub Actions workflow locally?
I am planning to move our Travis CI build to GitHub Actions using Docker for our per-commit testing.
Can I reproducibly run these new GitHub Actions workflows locally? Is there a generic way to run any GitHub Actions workflow locally?
There are tools like the already-mentioned act
, but they are not perfect.
You are not alone with this issue. Similar problems are:
And my solution for these problems is:
run: your command to run
Update 2022; Bit-bucket's Pipelines support running locally, which means 100% free use-hours, with the cost of buying own PC/Mac (if you want permanent server).
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.
You can use nektos/act which supports yaml syntax since 0.2.0 (prerelease).
Check out their latest release.
I'm assuming that you want to run the action locally because it is failing, and you want to debug it. If so, another alternative (which doesn't require running locally) is to use action-tmate to SSH into the machine running your action. From there, you can view logs, run commands, etc to work out what the problem is.
To get started:
- name: Setup tmate session
if: success() || failure()
uses: mxschmitt/action-tmate@v3
Push the changes to GitHub and rerun the action.
Wait for it to fail again - this time, instead of stopping the workflow, a tmate session will be opened, and the SSH details will be printed in the workflow console.
Connect via SSH from your own machine, and now you have full access to the runner machine.
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 :)
In my case ACT was failing even if the GitHub CI was passing so I have found this:
https://github.com/actions/runner
official github action runner (can be self-hosted). Follow instructions in readme.
It is a little different than the ACT but allows for example to pair repo CI to local runner (can use cuda for example)
To add on top of what's being said by @iirekm and @riQQ, in order to stay CI-agnostic and have some orchestration features, you could abstract your steps with Task and then call your tasks from your Github Actions or any other CI/CD. That way you also get the benefit of being able run everything locally.
with the use of docker containers, this tool called act, can be found here, https://github.com/nektos/act You can run all your github actions locally inside a docker container. NB: act builds all necessary containers for actions to run. all you do is follow the documentation on how to use the tool
Another option is to put all the work into makefiles, and using GitHub Action(s) to call make
.
That way, the jobs can be triggered to run locally via the make
command, or remotely via a GitHub Action (also using the make
command, but inside a GitHub Action).
I came across this approach mentioned here (one of the top comments on this thread).