Last active
November 10, 2021 14:22
-
-
Save moeinalmasi/2c8f10503c22d533908a2a0506fe6e44 to your computer and use it in GitHub Desktop.
Clear 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
# Bash script to delete the manually disabled GitHub workflows | |
# Step 0: install gh, jq and xargs (brew is going to help alot with this...) | |
# Step 1: manually disable the workflow: Actions -> select the workflow you wanna disable -> from ... click "Disable workflow" | |
# Step 2: update the org and repo name parameters below | |
# Step 3: execute the script and pray hard! (first you would need to authenticate "gh auth login", once authenticated run "bash clear-github-workflows.sh") | |
# Pro tip: comment out line number 23 first and run the script once and using line 15 validate you are deleting the right workflows | |
org=<org_name | |
repo=<repo_name> | |
# Get workflow IDs with status "disabled_manually" | |
workflow_ids=($(gh api repos/$org/$repo/actions/workflows | jq '.workflows[] | select(.["state"] | contains("disabled_manually")) | .id')) | |
echo "Organization: $org" | |
echo "Repository: $repo" | |
workflow_names=($(gh api repos/$org/$repo/actions/workflows | jq '.workflows[] | select(.["state"] | contains("disabled_manually")) | .name')) | |
echo "Deleting these disabled workflows: ${workflow_names[@]}" | |
for workflow_id in "${workflow_ids[@]}" | |
do | |
echo "Listing runs for the disabled workflow ID: $workflow_id" | |
run_ids=( $(gh api repos/$org/$repo/actions/workflows/$workflow_id/runs --paginate | jq '.workflow_runs[].id') ) | |
for run_id in "${run_ids[@]}" | |
do | |
echo "Deleting run ID: $run_id" | |
gh api repos/$org/$repo/actions/runs/$run_id -X DELETE >/dev/null | |
done | |
done | |
echo "Deleted disabled workflows successfully!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment