Skip to content

Instantly share code, notes, and snippets.

@clarkritchie
Created December 18, 2024 01:17
Show Gist options
  • Save clarkritchie/071a3cbced4f5286d751bce0099fed61 to your computer and use it in GitHub Desktop.
Save clarkritchie/071a3cbced4f5286d751bce0099fed61 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
OWNER=clarkritchie
REPO=${1:-database}
WORKFLOW_ID=${2}
if [ -z "$WORKFLOW_ID" ]; then
echo "Must specify a workflow name"
exit 1
fi
# gh config set pager cat
# GH_PAGER=cat
cat <<EOF
You are about to delete the workflow run history for:
- Owner: $OWNER
- Repository: $REPO
- Workflow ID: $WORKFLOW_ID
EOF
read -p "Do you want to proceed? (yes/no): " confirmation
if [[ "$confirmation" == "yes" ]]; then
gh api repos/$OWNER/$REPO/actions/workflows/$WORKFLOW_ID/runs --paginate -q '.workflow_runs[] | select(.head_branch != "master") | "\(.id)"' | \
xargs -n1 -I % gh api repos/$OWNER/$REPO/actions/runs/% -X DELETE
else
echo "Operation cancelled."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment