Skip to content

Instantly share code, notes, and snippets.

@abelaska
Last active December 15, 2021 21:31
Show Gist options
  • Save abelaska/8d068e86a83f5fc099fe042f59964e46 to your computer and use it in GitHub Desktop.
Save abelaska/8d068e86a83f5fc099fe042f59964e46 to your computer and use it in GitHub Desktop.
Delete all the old workflows that aren't on the `main` branch
user=sli-do repo=slido-global-api; gh api repos/$user/$repo/actions/runs \
--paginate -q '.workflow_runs[] | select(.head_branch != "main") | "\(.id)"' | \
xargs -n1 -I % gh api --silent repos/$user/$repo/actions/runs/% -X DELETE
https://stackoverflow.com/a/64473987
Prerequisites:
You will find the latest gh version here.
Notes:
You may have to gh auth login if this is your first time using it
You may further change the command to gh api --silent if you prefer not to see the verbose output.
For the final xargs part of the command chain - the original used -J instead of -I, which is not supported by GNU xargs. -J results in a single command, and -I will execute the command for each records, so it's a bit slower.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment