Skip to content

Commit 3297661

Browse files
committed
Add cleanup script and workflow
1 parent b8c12eb commit 3297661

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: 'Cleanup All'
2+
description: 'Delete all indexes and collections associated with API key'
3+
4+
inputs:
5+
PINECONE_API_KEY:
6+
description: 'The Pinecone API key'
7+
required: true
8+
9+
runs:
10+
using: 'composite'
11+
steps:
12+
- name: Set up Python
13+
uses: actions/setup-python@v4
14+
with:
15+
python-version: 3.9
16+
- name: Setup Poetry
17+
uses: ./.github/actions/setup-poetry
18+
- name: Cleanup all
19+
shell: bash
20+
run: poetry run python3 scripts/cleanup-all.py
21+
env:
22+
PINECONE_API_KEY: ${{ inputs.PINECONE_API_KEY }}

.github/workflows/cleanup.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: 'Cleanup All Indexes/Collections'
2+
3+
on:
4+
workflow_dispatch: {}
5+
6+
jobs:
7+
cleanup-all:
8+
name: Cleanupu all indexes/collections
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
- name: Cleanup all
13+
uses: ./.github/actions/cleanup-all
14+
with:
15+
PINECONE_API_KEY: ${{ secrets.PINECONE_API_KEY }}

scripts/cleanup-all.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import os
2+
from pinecone import Pinecone
3+
4+
def main():
5+
pc = Pinecone(api_key=os.environ.get('PINECONE_API_KEY', None))
6+
7+
for collection in pc.list_collections().names():
8+
try:
9+
print('Deleting collection: ' + collection)
10+
pc.delete_collection(collection)
11+
except Exception as e:
12+
print('Failed to delete collection: ' + collection + ' ' + str(e))
13+
pass
14+
15+
for index in pc.list_indexes().names():
16+
try:
17+
print('Deleting index: ' + index)
18+
pc.delete_index(index)
19+
except Exception as e:
20+
print('Failed to delete index: ' + index + ' ' + str(e))
21+
pass
22+
23+
if __name__ == '__main__':
24+
main()
25+

0 commit comments

Comments
 (0)