Search code examples
github-actionsgithub-apicicd

Using Github Actions REST API, how to correlate reruns to the original run similar to the UI?


I'm trying to get all recent runs in my repo on a specific branch. I then want to be able to correlate them.

Example
Lets say I have 5 runs(01,02,03,04,05), 01-03 are fresh runs, 04 is rerun of 01 and 05 is rerun of 03.

How can I detect these rerun relations, similarly to how they're grouped in the UI dropdown?


Solution

  • We can discover the desired relation between workflow runs using the /repos/{owner}/{repo}/actions/runs API. We will get workflow runs for the current repository. According to the response, the JSON contains workflow_runs array. Each workflow item contains previous_attempt_url property pointing to a previous run. If a particular run has no rerun attempt the property will be null. You can use the property to build a rerun tree.