Skip to content

Instantly share code, notes, and snippets.

@jonguenther
Created February 28, 2024 10:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonguenther/1eabd6c724a7aa0c405d5316613f417c to your computer and use it in GitHub Desktop.
Save jonguenther/1eabd6c724a7aa0c405d5316613f417c to your computer and use it in GitHub Desktop.
Delete Github Actions Workflows
#!/bin/bash
# This script uses the gh cli to delete all workflows in a repo
# Useful if you want to regularly clean up your workflows (e.g. to free up some shared storage)
# based on https://github.com/orgs/community/discussions/77039#discussioncomment-7685341
# the gh cli only allows to delete 20 workflows at a time, so we wrap it in a loop
# and set the exit condition to when no more workflows are available
while true; do
# Fetch the list of workflow runs and extract the databaseId using jq
database_ids=$(gh run list --json databaseId --jq '.[].databaseId')
# Check if there are any databaseIds
if [ -z "$database_ids" ]; then
echo "No more databaseIds found. Exiting."
break
fi
# Loop over each databaseId and delete the corresponding workflow run
echo "Starting to delete workflow runs..."
echo "$database_ids" | xargs -n 1 gh run delete
# Sleep for a while to avoid hitting rate limits
sleep 1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment