Last active
July 31, 2021 21:09
-
-
Save jayzeng/352131ac1c2085371c574a3318fdaa79 to your computer and use it in GitHub Desktop.
clean up disabled github workflows
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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: