-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Testing: Create and delete test index
Create a test index before running pytest, then delete it after. Uses 'PINECONE_API_KEY' Action secret for access to the Pinecone API.
- Loading branch information
Showing
6 changed files
with
170 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
name: 'Create Index' | ||
description: 'Creates an index to be used in other tests' | ||
|
||
inputs: | ||
region: | ||
description: 'The region of the index' | ||
required: false | ||
default: 'us-west-2' | ||
cloud: | ||
description: 'The cloud of the index' | ||
required: false | ||
default: 'aws' | ||
name_prefix: | ||
description: 'The prefix of the index name' | ||
required: false | ||
default: 'index-name' | ||
dimension: | ||
description: 'The dimension of the index' | ||
required: false | ||
default: '3' | ||
metric: | ||
description: 'The metric of the index' | ||
required: false | ||
default: 'cosine' | ||
PINECONE_API_KEY: | ||
description: 'The Pinecone API key' | ||
required: true | ||
|
||
outputs: | ||
index_name: | ||
description: 'The name of the index, including randomized suffix' | ||
value: ${{ steps.create-index.outputs.index_name }} | ||
|
||
runs: | ||
using: 'composite' | ||
steps: | ||
- name: Create index | ||
id: create-index | ||
shell: bash | ||
run: python3 tests/scripts/create_index.py | ||
env: | ||
PINECONE_API_KEY: ${{ inputs.PINECONE_API_KEY }} | ||
NAME_PREFIX: ${{ inputs.name_prefix }} | ||
REGION: ${{ inputs.region }} | ||
CLOUD: ${{ inputs.cloud }} | ||
DIMENSION: ${{ inputs.dimension }} | ||
METRIC: ${{ inputs.metric }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: 'Delete Index' | ||
description: 'Deletes an index to be used in other tests' | ||
|
||
inputs: | ||
index_name: | ||
description: 'The name of the index to delete' | ||
required: true | ||
PINECONE_API_KEY: | ||
description: 'The Pinecone API key' | ||
required: true | ||
|
||
|
||
runs: | ||
using: 'composite' | ||
steps: | ||
- name: Delete index | ||
shell: bash | ||
run: python3 tests/scripts/delete_index.py | ||
env: | ||
PINECONE_API_KEY: ${{ inputs.PINECONE_API_KEY }} | ||
INDEX_NAME: ${{ inputs.index_name }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
""" | ||
Create a Pinecone index for use in some later GitHub action. Takes input from | ||
environment variables, then writes the output to the file named in | ||
GITHUB_OUTPUT. | ||
""" | ||
|
||
import os | ||
import random | ||
import string | ||
from pinecone import Pinecone | ||
|
||
|
||
def read_env_var(name): | ||
value = os.environ.get(name) | ||
if value is None: | ||
raise 'Environment variable {} is not set'.format(name) | ||
return value | ||
|
||
|
||
def random_string(length): | ||
return ''.join(random.choice(string.ascii_lowercase) for _ in range(length)) | ||
|
||
|
||
def write_gh_output(name, value): | ||
with open(os.environ['GITHUB_OUTPUT'], 'a') as fh: | ||
print(f'{name}={value}', file=fh) | ||
|
||
|
||
def main(): | ||
pc = Pinecone(api_key=read_env_var('PINECONE_API_KEY')) | ||
index_name = read_env_var('NAME_PREFIX') + random_string(20) | ||
environment = os.environ.get('ENVIRONMENT') | ||
if environment: | ||
spec = { | ||
'pod': { | ||
'environment': environment, | ||
'pod_type': 'p1.x1' | ||
} | ||
} | ||
else: | ||
spec = { | ||
'serverless': { | ||
'cloud': read_env_var('CLOUD'), | ||
'region': read_env_var('REGION'), | ||
} | ||
} | ||
|
||
pc.create_index( | ||
name=index_name, | ||
metric=read_env_var('METRIC'), | ||
dimension=int(read_env_var('DIMENSION')), | ||
spec=spec | ||
) | ||
write_gh_output('index_name', index_name) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
""" | ||
Delete the Pinecone index named by the env var 'INDEX_NAME' | ||
""" | ||
|
||
import os | ||
from pinecone import Pinecone | ||
|
||
|
||
def read_env_var(name): | ||
value = os.environ.get(name) | ||
if value is None: | ||
raise 'Environment variable {} is not set'.format(name) | ||
return value | ||
|
||
|
||
def main(): | ||
pc = Pinecone(api_key=read_env_var('PINECONE_API_KEY')) | ||
to_delete = read_env_var('INDEX_NAME') | ||
pc.delete_index(name=to_delete) | ||
print('Index deleted: ' + to_delete) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
def test_dummy(): | ||
pass |