Skip to content

Instantly share code, notes, and snippets.

@mikerochip
Last active July 3, 2025 23:44
Show Gist options
  • Save mikerochip/f4cea7fb0e4db048dce1e265000bb2f6 to your computer and use it in GitHub Desktop.
Save mikerochip/f4cea7fb0e4db048dce1e265000bb2f6 to your computer and use it in GitHub Desktop.
Delete all runs of a GitHub workflow to remove it from the Actions UI
#!/bin/bash -e
command -v gh > /dev/null 2>&1 || { echo >&2 "\n'gh' was not found on your path. Install the GitHub CLI at https://github.com/cli/cli#installation\n"; exit 2; }
# Prompt for inputs
if [[ -z $OWNER ]]; then
read -rp "GitHub Owner (set OWNER to skip this): " OWNER
if [[ -z $OWNER ]]; then
echo "Missing OWNER"
exit 1
fi
fi
if [[ -z $REPO ]]; then
read -rp "Repo Name (set REPO to skip this): " REPO
if [[ -z $REPO ]]; then
echo "Missing REPO"
exit 1
fi
fi
if [[ -z "$WORKFLOW" ]]; then
read -rp "Workflow Name (set WORKFLOW to skip this): " WORKFLOW
if [[ -z $WORKFLOW ]]; then
echo "Missing WORKFLOW"
exit 1
fi
fi
# Get the workflow ID for the given name
echo ""
echo "Translating workflow name '$WORKFLOW' to Id..."
WorkflowId=$(gh api "repos/$OWNER/$REPO/actions/workflows" \
--jq ".workflows[] | select(.name == \"$WORKFLOW\") | .id")
if [[ -z "$WorkflowId" ]]; then
echo "Workflow '$WORKFLOW' not found"
exit 1
fi
echo ""
echo "Deleting runs for workflow id $WorkflowId"
# Get all run IDs for that workflow
RunIds=$(gh api "repos/$OWNER/$REPO/actions/workflows/$WorkflowId/runs?per_page=100" \
--paginate \
--jq '.workflow_runs[].id')
# Delete each run
echo ""
for runId in $RunIds; do
echo "Delete run: $runId"
gh api --method DELETE "repos/$OWNER/$REPO/actions/runs/$runId"
done
echo ""
echo "Done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment