Skip to content

Instantly share code, notes, and snippets.

@jayzeng
Last active July 31, 2021 21:09
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 jayzeng/352131ac1c2085371c574a3318fdaa79 to your computer and use it in GitHub Desktop.
Save jayzeng/352131ac1c2085371c574a3318fdaa79 to your computer and use it in GitHub Desktop.
clean up disabled github workflows
#!/bin/bash
OWNER=<org_name>
REPO=$1
WORKFLOW_NAME=$2
# list workflows
WORKFLOW_IDS=($(gh api -X GET /repos/$OWNER/$REPO/actions/workflows | jq -r '.workflows[] | select(.state=="disabled_manually") | .id'))
for WORKFLOW_ID in "${WORKFLOW_IDS}"
do
# delete all runs
echo "deleting existing runs: $WORKFLOW_ID"
gh api -X GET "/repos/$OWNER/$REPO/actions/workflows/$WORKFLOW_ID/runs" | jq '.workflow_runs[] | .id' | xargs -I{} gh api -X DELETE /repos/$OWNER/$REPO/actions/runs/{}
done
@jayzeng
Copy link
Author

jayzeng commented Jul 31, 2021

GitHub lacks a way to delete workflows (per https://github.community/t/is-there-a-way-to-delete-or-hide-old-renamed-workflows/16281), this is a dead-simple shell script to delete manually disabled workflows, by removing runs tied to a given repo.

Usage:

chmod +x ./workflow_clean.sh
./workflow_clean.sh your_reponame

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment