Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run GitHub Actions workflows 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?

like image 476
William Entriken Avatar asked Dec 09 '19 00:12

William Entriken


People also ask

Can you run a GitHub workflow locally?

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.

How do I manually run a workflow action in GitHub?

On GitHub.com, navigate to the main page of the repository. Under your repository name, click Actions. In the left sidebar, click the workflow you want to run. Above the list of workflow runs, select Run workflow.

Where do GitHub workflows run?

Workflows are defined in the . github/workflows directory in a repository, and a repository can have multiple workflows, each of which can perform a different set of tasks.


Video Answer


2 Answers

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
like image 198
iirekm Avatar answered Sep 24 '22 06:09

iirekm


You can use nektos/act which supports yaml syntax since 0.2.0 (prerelease).

Check out their latest release.

like image 45
Webber Avatar answered Sep 22 '22 06:09

Webber