How do I get the list of runs for last 30 days in github actions?

746 Views Asked by At

How do I modify this API call to get the list of runs for the last 30 days?

Endpoint:

https://api.github.com/repos/[OWNER]/[REPO]/actions/runs

I tried:

https://github.infra.cloudera.com/api/v3/repos/[OWNER]/[REPO]/actions/runs?created=datetime.today() - timedelta(days=30)

and it didn't work.

2

There are 2 best solutions below

0
On

With gh cli search for failed actions from the last 30 days and list the ids:

gh run list --jq ' .[]| select(.conclusion| contains("failure"))|

            select(.createdAt > (now-( 30 * 86400) | strftime("%Y-%m-%dT%H-%M-%SZ") ))|

            .databaseId' --json conclusion,databaseId,createdAt -R  <[OWNER]/[REPO]>

Check the output with:

gh run view <id> -R <[OWNER]/[REPO]>

Refine fields and conditions for purpose.

0
On

You might be looking for "Workflow runs":

GET /repos/{owner}/{repo}/actions/workflows/{workflow_id}/runs

With created parameter and >=YYYY-MM-DD query

For example, you'd run

GET /repos/{owner}/{repo}/actions/workflows/{workflow_id}/runs?created=>=YYYY-MM-DD

And replace YYYY-MM-DD with your datetime output in this format