Skip to content

Instantly share code, notes, and snippets.

@aryankaran
Forked from retyui/remove-all.md
Created September 30, 2022 05:41
Show Gist options
  • Save aryankaran/2cb5b70a9ed63cd26bb3bc0a68c9d5f1 to your computer and use it in GitHub Desktop.
Save aryankaran/2cb5b70a9ed63cd26bb3bc0a68c9d5f1 to your computer and use it in GitHub Desktop.
Simple way to remove all workflow runs in GitHub Actions:

Simple way to remove all workflow runs in Github Actions:

export user=NameOrOrgName
export repo=RepoName


gh api repos/$user/$repo/actions/runs --paginate -q '.workflow_runs[] | select(.workflow_id = 21456768) | "\(.id)"'  | xargs -n1 -I % gh api repos/$user/$repo/actions/runs/% -X DELETE


gh api "repos/$user/$repo/actions/runs?created=*..2022-07-16" --paginate -q '.workflow_runs[] | select(.workflow_id == 21456768) | "\(.id)"'  | xargs -n1 -I % gh api repos/$user/$repo/actions/runs/% -X DELETE

gh api repos/$user/$repo/actions/runs?created=2022-06-15..2022-07-16

gh api "repos/$user/$repo/actions/runs?workflow_id=21456768"


  {
      "id": 2677488357,
      "name": "aaaa",
      "node_id": "WFR_kwLOFhRH7c6flzrl",
      "head_branch": "name",
      "head_sha": "e90657391639ee0d1f645ca83bb7ef1e1218ed32",
      "path": ".github/workflows/name.yml",
      "run_number": 4759,
      "event": "pull_request",
      "status": "completed",
      "conclusion": "success",
      "workflow_id": 21456768,
      "check_suite_id": 7375336252,
      "check_suite_node_id": "CS_kwDOFhRH7c8AAAABt5qzPA",
      "url": "https://api.github.com/repos/name/repo/actions/runs/2677488357",
      "html_url": "https://github.com/name/repo/actions/runs/2677488357",
      "pull_requests": [],
      "created_at": "2022-07-15T14:35:25Z",
      "updated_at": "2022-07-15T14:49:51Z",



gh api "repos/$user/$repo/actions/runs?created=*..2022-07-16" --paginate -q '.workflow_runs[] | select(.workflow_id == 21456768) | "\(.id)"'  | xargs -n1 -I % gh api repos/$user/$repo/actions/runs/% -X DELETE

gh api "repos/$user/$repo/actions/runs?created=*..2022-07-16" --paginate -q '.workflow_runs[] | select(.workflow_id == 21456768) | "\(.id)"'  > ids.txt
cat ids.txs | xargs -n1 -I % gh api repos/$user/$repo/actions/runs/% -X DELETE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment