blob: ae3a4f84237e2eacd81a124000659f8c9a6bd2f5 [file] [log] [blame]
#!/bin/bash
#
# This script helps with deleting old workflows on github.
OP=$1
REPO=repos/project-chip/zap
if [ -z "$OP" ]; then
echo "Usage: workflow-ops [ list [xxxxx] | delete xxxxx ]"
echo ""
echo " list : lists all workflows"
echo " list ID : lists all runs under a given workflow"
echo " delete ID : DELETES all runs under a given workflow"
echo ""
echo "WARNING: If you run 'delete' this WILL DELETE all the workflow runs under a given workflow."
echo "Make sure you know what you're doing! Really!!"
exit
fi
if [ "$OP" == "list" ]; then
ID=$2
if [ -z "$ID" ]; then
gh api $REPO/actions/workflows | jq -cM '.workflows[] | [.id, .name, .path]'
else
gh api $REPO/actions/workflows/$ID/runs --paginate | jq '.workflow_runs[] | .id'
fi
elif [ "$OP" == "delete" ]; then
ID=$2
if [ -z "$ID" ]; then
echo "You need to provide ID."
exit
fi
echo "Deleting workflow runs for workflow $ID. Please wait. This might take a while...."
gh api $REPO/actions/workflows/$ID/runs --paginate | jq '.workflow_runs[] | .id' | xargs -n1 -I% gh api $REPO/actions/runs/% -X DELETE
else
echo "Unknown command: $OP"
fi