Have you ever wanted to clean-up and delete past GitHub Actions Workflow Runs/Logs but did not want to click on each run individually to delete it?
Well, save some time and utilize GitHub CLI to mass delete all GitHub Actions workflow runs for a specific repository!
This repository contains a Bash file delete_workflow_runs.sh
, which will delete ALL workflow runs for a specific repository when executed.
-
Install GitHub CLI (gh): This tool allows you to interact with GitHub from the command line. You can install it using Homebrew on your Mac with the command
brew install gh
. -
jq Tool: This is a command-line JSON processor that the script uses to parse JSON data. Install it on your Mac using Homebrew with the command
brew install jq
. -
GitHub Authentication: To use the GitHub CLI (gh), you need to be authenticated. You don't necessarily need an API key; instead, you authenticate your GitHub CLI installation with your GitHub account. Once installed, you can authenticate by running
gh auth login
and following the prompts. -
Create the File: Use a text editor to create a new file with the script inside it.
-
Make It Executable: Before you can run your Bash script, you need to make it executable. You can do this from the terminal with the following command:
chmod +x delete_workflow_runs.sh
After setting up these prerequisites, you can run your script. Here's the script for reference:
gh api --paginate /repos/username/reponame/actions/runs | \
jq -r '.workflow_runs[] | [.id] | @tsv' | \
while read -r value; do
echo "Deleting $value"
gh api -X DELETE "/repos/username/reponame/actions/runs/$value"
done
Important
Remember to replace username
and reponame
with your GitHub username and the repository name, respectively.
This script works by:
- Using the GitHub CLI to fetch a list of workflow runs for a specific repository.
- Piping the output to jq to extract the run IDs.
- Looping over each ID and using the GitHub CLI to delete the corresponding workflow run.
Pagination
- By default, the script is only deleting 25 workflow runs at a time, this is likely due to the GitHub API's pagination feature.
- The GitHub API, like many APIs, uses pagination to limit the number of items returned in a single response. This is done to manage load on the server and to ensure faster response times.
- The GitHub CLI (gh) simplifies pagination with the
--paginate
flag which is written into the script. With the--paginate
flag, the script will loop through each page of the API response until there are no more pages left.
Running the Script: Once the script is executable, you can run it from the terminal in the directory where the script is located:
./delete_workflow_runs.sh
- GitHub CLI Tool
- Mass deletion of GitHub Actions workflow runs (a blog post that inspired me to tackle this problem)
- Bash Reference Manual
- Bash Guide for Beginners
- Bash Scripting Tutorial
- Bash Scripting Cheatsheet
This project is released under the terms of The Unlicense, which allows you to use, modify, and distribute the code as you see fit.
- The Unlicense removes traditional copyright restrictions, giving you the freedom to use the code in any way you choose.
- For more details, see the LICENSE file in this repository.
Author: Scott Grivner
Email: [email protected]
Website: scottgrivner.dev
Reference: Main Branch