How to run Github workflow on every commit of a push

Hello everyone,

I have some tests that I would like to run on every commit of my repository. I have the following script in my repo:

name: CI

on: [push]

    runs-on: ubuntu-latest

      - uses: actions/checkout@v2
      - run: echo "my tests, place holder for the real tests"

Unfortunately, if I push some new commits to my repository, the tests are only run against the most recent of the commits in that push. I would like to test every commit that I have pushed. Is there a way to do this?

There is no builtin way to make on: push run a workflow for each commit. You could obviously push after every commit, but other than that, I can only think of the followings two things:

  • Call the REST API multiple times to dispatch a workflow run for each commit
  • Dynamically construct a job matrix, one job per commit (but it will then be a single workflow run and possibly run into a timeout if there are too many jobs)

Call the REST API multiple times to dispatch a workflow run for each commit

Can you give any further pointers on how to achieve this? I’m a little out of my depth here, so any help would be welcome.


Ideally, every commit would also have one of those little “success” or “failure” markers in the github interface. But that may be too much to ask?

There’s an example how to call the REST API in an Action using GITHUB_TOKEN:

The endpoint to dispatch a workflow run is documented here:

There is a problem however: The reference can only be a branch or tag name. It cannot be an arbitrary commit hash. To dispatch a workflow run for each commit, you will have to create a tag for every commit first I’m afraid.

Mhm, that is a shame. It surprises me that nobody else is having this problem. I assume that with your other option to “Dynamically construct a job matrix”, all of the jobs will be attributed to the last commit, and not the intended ones? So if one job fails, the last commit will be marked as a failure?

Is there otherwise a way for me to manually trigger a workflow for a specific commit through github’s website?

(Thanks for all your help BTW!)

Presumably, yes.

The Web UI only lets you pick branches to dispatch workflows, whereas the API supports branches and tags. There is no way to dispatch workflow runs for specific commits, which was also confirmed by a staff member.

You could set an input with the commit hash that you want to use in the checkout, but you would still need to specify a branch. I’m not sure if the run will be associated with the latest commit on that branch or the commit that you use in the checkout action, but my guess is the former.

Okay, it sounds that the easiest solution will indeed be to just push commit-by-commit. For the interested, here is a stackoverflow answer that explains how to automate this:

Thanks again!