Skip to content

Commit

Permalink
Add cleanup script and workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
jhamon committed Feb 7, 2024
1 parent b8c12eb commit 3297661
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .github/actions/cleanup-all/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: 'Cleanup All'
description: 'Delete all indexes and collections associated with API key'

inputs:
PINECONE_API_KEY:
description: 'The Pinecone API key'
required: true

runs:
using: 'composite'
steps:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.9
- name: Setup Poetry
uses: ./.github/actions/setup-poetry
- name: Cleanup all
shell: bash
run: poetry run python3 scripts/cleanup-all.py
env:
PINECONE_API_KEY: ${{ inputs.PINECONE_API_KEY }}
15 changes: 15 additions & 0 deletions .github/workflows/cleanup.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: 'Cleanup All Indexes/Collections'

on:
workflow_dispatch: {}

jobs:
cleanup-all:
name: Cleanupu all indexes/collections
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Cleanup all
uses: ./.github/actions/cleanup-all
with:
PINECONE_API_KEY: ${{ secrets.PINECONE_API_KEY }}
25 changes: 25 additions & 0 deletions scripts/cleanup-all.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import os
from pinecone import Pinecone

def main():
pc = Pinecone(api_key=os.environ.get('PINECONE_API_KEY', None))

for collection in pc.list_collections().names():
try:
print('Deleting collection: ' + collection)
pc.delete_collection(collection)
except Exception as e:
print('Failed to delete collection: ' + collection + ' ' + str(e))
pass

for index in pc.list_indexes().names():
try:
print('Deleting index: ' + index)
pc.delete_index(index)
except Exception as e:
print('Failed to delete index: ' + index + ' ' + str(e))
pass

if __name__ == '__main__':
main()

0 comments on commit 3297661

Please sign in to comment.