DEV Community

Cover image for How to test your GitHub Actions locally
Rajvir Singh for ByteSlash

Posted on • Updated on

How to test your GitHub Actions locally

So Dev & GitHub Team just announced the Github Action Hackathon. I am also participating in it. But I ran into a troublesome problem, and I think some of you guys are too. That is we always have to push the files to the remote repo in order to test the action, But it is a kinda pain to do it every time you make a change. I finally have found a solution to this problem.

Act the solution

"Think globally, act locally"

The two important reasons that you should use Act:

  • Fast Feedback - Rather than having to commit/push every time you want to test out the changes you are making to your .github/workflows/ files (or for any changes to embedded GitHub actions), you can use act to run the actions locally. The environment variables and filesystem are all configured to match what GitHub provides.
  • Local Task Runner - I love make. However, I also hate repeating myself. With act, you can use the GitHub Actions defined in your .github/workflows/ to replace your Makefile!

I copied them from Act's readme, Because I am lazy

Act is pretty reliable for testing actions, And I can go into details but I would be just repeating the stuff that is already on Act's Readme. So if you want deeper dive then you can check Act's Repo.

I hope you guys can figure everything else yourselves, as I am also busy making my project for this hackathon. But I felt an urge to tell others about this amazing tool.

Have a good day, Best of luck!
Rajvir Singh

Top comments (6)

Collapse
 
cardinalby profile image
Cardinal

As a author of several actions I also wondered whether I can make a feedback loop shorter and write integration tests for my actions. Act is great, but it fits better for running the entire workflows and doesn't provide an API for examining outputs and other commands of individual actions (steps). For this purpose I had to write own API convenient for running individual actions locally, which allows isolate even individual JS functions and provide all inputs for them as well as read all commands produced by an action. You can check out it here: github.com/cardinalby/github-actio...

Collapse
 
luwang1983 profile image
LuWang1983

When testing using ACT, it scans the .github/workflows directory to run the jobs, but I find it a bit cumbersome that it only allows one action yaml file at a time, otherwise, it will error out with conflicts. If anyone knows any workaround or a better way to test these actions by selecting a file, that'll be really helpful!

Collapse
 
gausoft9 profile image
Gauthier

Please. Is scheduled tasks (cron) supported ?

Collapse
 
deninpaulv profile image
Denin Paul

Awesome article! I always wondered if there was a better way. Not anymore!

Collapse
 
rajvirsingh1313 profile image
Rajvir Singh

Thanks Denin, Yeah I too wondered around, as pushing everytime you added a space is annoying and makes commit meaningless. But I now found the solution now I finally can complete my project

Collapse
 
rajvirsingh1313 profile image
Rajvir Singh

I hope everyone is enjoying this hackathon, If you guys have any other tools that mighty be helpful for others then please share them in comments.

Have a good day
Rajvir