How to trigger GHA rerun for given commit

I would like to automate something that I currently do manually via the web UI: re-run the workflow for a given commit.

In the UI I click on the green/red checkmark behind the commit, and then the “rerun all jobs” button. But I am running into two problems when doing this with the API:

  • The GET /repos/:owner/:repo/commits/:ref/check-runs api returns general check-run-id’s (also for non-gha checks) but we need an GHA run_id. There is another api to get recent GHA runs, however I can’t find a way to get the run_id for a given commit. Is there a way to get the GHA run_id from a given commit ?

  • With POST /repos/:owner/:repo/actions/runs/:run_id/rerun you get a 403 permission denied error when trying to re-run a workflow that has previously succeeded? This is strange because this is now allowed in the UI (it wasn’t possible a while ago). Is it on purpose that you cannot rerun a succesful workflow?

:wave: Welcome to the GitHub Support Community, @jeroen!

There isn’t an endpoint that you can pass a commit SHA for obtaining the list of associated workflow runs.

As a next step, one approach you can take is listing the workflow runs for a repository. The response has a workflow_runs field, where each element represents a workflow run specifying the head_sha and run_number.

You could write a script that filters the response for those two fields and decide which workflow runs to re-run. It’s only possible to re-run failed workflows at this time (see Managing a workflow run: Viewing your workflow history for more details).

Does this context help with what you’re looking to accomplish? :thought_balloon: