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
Bitbucket's Pipelines support is running locally, which means 100% free use-hours, with the cost of buying own PC/Mac (if you want a permanent server).
gitlab-runner exec docker my-job
One way to test GitHub Actions is to create a private repository, and iterate the actions configuration there. So you can avoid polluting the actual repository 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.
-P windows-latest=...
" But nothing is accepted as arguments to -P I tried this: -P ubuntu-latest=node:16-buster-slim but same error every time
Commented
Nov 4, 2022 at 12:15
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 act. However (prior to 0.2.0) it doesn't support YAML syntax yet, though there is a lot of interest, AKA: Didn't work with YAML #80, YAML syntax support #76 and Support Actions v2 #74.
GitLab has gitlab-runner exec docker job-name
, but that's only for GitLab :)
In my case, Act was failing even if the GitHub CI was passing, so I have found this:
It is the official GitHub action runner (can be self-hosted). Follow the instructions in the README.
It is a little different than the ACT, but it allows, for example, to pair the repository CI to a 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.
It's surprising that there is still no official way to do this. Act seems like a very good answer but I want to propose a couple of other solutions:
Both these tools let you run you workflows locally and then you CICD can be just a single line command.
With the use of Docker containers, there is this tool called Act. You can run all your GitHub Actions stuff 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).
nejtos/act
to support YAML syntax, see my answer below with links to the issues it's being discussed.