Skip to content

Mass delete all GitHub Actions workflow runs for a specific repository using GitHub CLI.

License

Notifications You must be signed in to change notification settings

scottgriv/bash-github_delete_workflow_runs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


Bash Badge
GitHub Badge Email Badge BuyMeACoffee Badge
Bronze


GitHub CLI - Delete GitHub Actions Workflow Runs

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!


Table of Contents

Features

This repository contains a Bash file delete_workflow_runs.sh, which will delete ALL workflow runs for a specific repository when executed.

Installation

  1. 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.

  2. 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.

  3. 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.

  4. Create the File: Use a text editor to create a new file with the script inside it.

  5. 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.

Usage

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

Resources

License

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.

Credits

Author: Scott Grivner
Email: scott.grivner@gmail.com
Website: scottgrivner.dev
Reference: Main Branch


Releases

No releases published

Packages

No packages published

Languages