Skip to content

Instantly share code, notes, and snippets.

@jerlendds
Created January 7, 2026 17:38
Show Gist options
  • Select an option

  • Save jerlendds/87c9e4c1864d258be661224bbc2124ca to your computer and use it in GitHub Desktop.

Select an option

Save jerlendds/87c9e4c1864d258be661224bbc2124ca to your computer and use it in GitHub Desktop.
delete all artifacts
USER="jerlendds" # Replace with your GitHub username
# Fetch all repos with write/admin access
REPOS=$(gh api /user/repos\?affiliation=owner,collaborator,organization_member --paginate | python3 -c "import sys, json; repos = json.load(sys.stdin); [print(repo['full_name']) for repo in repos if repo['permissions']['admin'] or repo['permissions']['push']]")
for REPO in $REPOS; do
echo "Processing repository: $REPO"
# Optional: List recent workflow runs
echo "Listing recent workflow runs for $REPO"
gh run list --repo "$REPO" --limit 5 --json databaseId,status,conclusion
# Delete all artifacts
echo "Deleting artifacts for $REPO"
ARTIFACT_IDS=$(gh api /repos/"$REPO"/actions/artifacts --paginate | python3 -c "import sys, json; artifacts = json.load(sys.stdin)['artifacts']; print('Found ' + str(len(artifacts)) + ' artifacts'); [print(artifact['id']) for artifact in artifacts]")
if [ -z "$ARTIFACT_IDS" ]; then
echo "No artifacts to delete"
else
echo "$ARTIFACT_IDS" | tail -n +2 | xargs -n1 -I % bash -c "gh api -X DELETE /repos/\"$REPO\"/actions/artifacts/% && sleep 1"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment