Skip to content

Instantly share code, notes, and snippets.

@gubatron
Last active October 12, 2024 22:06
Show Gist options
  • Save gubatron/47552e1bfa345a142b2248be1925efb6 to your computer and use it in GitHub Desktop.
Save gubatron/47552e1bfa345a142b2248be1925efb6 to your computer and use it in GitHub Desktop.
Batch delete 30 Github Workflow Run Logs using the github command line tool
#
# This script uses the github command line tool
# to delete the last 30 logs from your repository's workflow runs
#
# Requirements
#
# gh - github command line (brew install gh)
# you will need a GH_TOKEN, create it here: https://github.com/settings/tokens
#
# once you've created the personal access token with permission to manage your workflows
# you gotta tell gh which repository it's working with using
# $ gh repo set-default
# you will be presented an interactive list to pick the repo you want to delete workflow logs from
# jq - json command line processor (brew
repo=yourrepo
user=yourgithubusername
WORKFLOW_RUN_IDS=$(gh api /repos/${user}/${repo}/actions/runs | jq -r ".workflow_runs[] | [.id] | @tsv")
for id in ${WORKFLOW_RUN_IDS}
do
echo "Workflow ID: ${id}"
gh api -X DELETE "/repos/${user}/${repo}/actions/runs/${id}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment