|
| 1 | +--- |
| 2 | +#------------------------------------------------------------------------------ |
| 3 | +# Run Python unit tests |
| 4 | +#------------------------------------------------------------------------------ |
| 5 | +name: Test Python |
| 6 | +branding: |
| 7 | + icon: "git-pull-request" |
| 8 | + color: "orange" |
| 9 | +inputs: |
| 10 | + python-version: |
| 11 | + description: "The version of Python to use, such as 3.11.0" |
| 12 | + required: true |
| 13 | + type: string |
| 14 | + openai-api-organization: |
| 15 | + description: "The OpenAI API organization" |
| 16 | + required: true |
| 17 | + type: string |
| 18 | + openai-api-key: |
| 19 | + description: "The OpenAI API key" |
| 20 | + required: true |
| 21 | + type: string |
| 22 | + pinecone-api-key: |
| 23 | + description: "The Pinecone API key" |
| 24 | + required: true |
| 25 | + type: string |
| 26 | + pinecone-environment: |
| 27 | + description: "The Pinecone environment" |
| 28 | + required: true |
| 29 | + type: string |
| 30 | + pinecone-index-name: |
| 31 | + description: "The Pinecone index name" |
| 32 | + required: true |
| 33 | + type: string |
| 34 | + |
| 35 | +env: |
| 36 | + REQUIREMENTS_PATH: "api/terraform/python/layer_genai/requirements.txt" |
| 37 | + |
| 38 | +runs: |
| 39 | + using: "composite" |
| 40 | + steps: |
| 41 | + - name: Checkout code |
| 42 | + id: checkout |
| 43 | + uses: actions/checkout@v4 |
| 44 | + |
| 45 | + - name: Cache Python dependencies |
| 46 | + uses: actions/cache@v3 |
| 47 | + with: |
| 48 | + path: ~/.cache/pip |
| 49 | + key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} |
| 50 | + restore-keys: | |
| 51 | + ${{ runner.os }}-pip |
| 52 | +
|
| 53 | + - name: Set up Python |
| 54 | + uses: actions/setup-python@v4 |
| 55 | + with: |
| 56 | + python-version: ${{ inputs.python-version }} |
| 57 | + |
| 58 | + - name: locate site-packages path |
| 59 | + shell: bash |
| 60 | + run: | |
| 61 | + echo "SITE_PACKAGES_PATH=$(python -c 'import site; print(site.getsitepackages()[0])')" >> $GITHUB_ENV |
| 62 | +
|
| 63 | + - name: Install pip |
| 64 | + shell: bash |
| 65 | + run: | |
| 66 | + python -m pip install --upgrade pip |
| 67 | +
|
| 68 | + - name: Install dependencies |
| 69 | + shell: bash |
| 70 | + run: | |
| 71 | + pip install -r ./requirements.txt |
| 72 | + env: |
| 73 | + SITE_PACKAGES_PATH: ${{ env.SITE_PACKAGES_PATH }} |
| 74 | + |
| 75 | + - name: Create .env |
| 76 | + shell: bash |
| 77 | + run: | |
| 78 | + touch ./.env |
| 79 | + echo "OPENAI_API_ORGANIZATION=${{ env.OPENAI_API_ORGANIZATION }}" >> ./.env |
| 80 | + echo "OPENAI_API_KEY=${{ env.OPENAI_API_KEY }}" >> ./.env |
| 81 | + echo "PINECONE_API_KEY=${{ env.PINECONE_API_KEY }}" >> ./.env |
| 82 | + echo "PINECONE_ENVIRONMENT=${{ env.PINECONE_ENVIRONMENT }}" >> ./.env |
| 83 | + echo "PINECONE_INDEX_NAME=${{ env.PINECONE_INDEX_NAME }}" >> ./.env |
| 84 | + env: |
| 85 | + OPENAI_API_ORGANIZATION: ${{ inputs.openai-api-organization }} |
| 86 | + OPENAI_API_KEY: ${{ inputs.openai-api-key }} |
| 87 | + PINECONE_API_KEY: ${{ inputs.pinecone-api-key }} |
| 88 | + PINECONE_ENVIRONMENT: ${{ inputs.pinecone-environment }} |
| 89 | + PINECONE_INDEX_NAME: ${{ inputs.pinecone-index-name }} |
| 90 | + |
| 91 | + - name: Run Tests |
| 92 | + shell: bash |
| 93 | + run: | |
| 94 | + cd models && pytest -v -s tests/ |
| 95 | + python -m setup_test |
0 commit comments