diff --git a/.github/workflows/pullRequestController.yml b/.github/workflows/pullRequestController.yml index 914dd0f6..8051e807 100644 --- a/.github/workflows/pullRequestController.yml +++ b/.github/workflows/pullRequestController.yml @@ -117,14 +117,39 @@ jobs: echo "::set-output name=py_files_changed::$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | grep '\.py$' || true)" echo "::set-output name=requirements_changed::$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | grep '^${{ env.REQUIREMENTS_PATH }}$' || true)" - - name: Run Python Tests + - name: Set up Python if: steps.file_changes.outputs.py_files_changed != '' || steps.file_changes.outputs.requirements_changed != '' - id: python_tests - uses: ./.github/workflows/testPython.yml + uses: actions/setup-python@v4 + with: + python-version: 3.11 - - name: No Python changes detected - if: steps.file_changes.outputs.py_files_changed == '' && steps.file_changes.outputs.requirements_changed == '' - run: echo "No Python or requirements.txt changes detected." + - name: Install dependencies + if: steps.file_changes.outputs.py_files_changed != '' || steps.file_changes.outputs.requirements_changed != '' + run: | + python -m pip install --upgrade pip + pip install -r ./requirements.txt + cp -R ./api/terraform/python/layer_genai/openai_utils /opt/hostedtoolcache/Python/3.11.6/x64/lib/python3.11/site-packages/ + + - name: Create .env + if: steps.file_changes.outputs.py_files_changed != '' || steps.file_changes.outputs.requirements_changed != '' + run: | + touch ./.env + echo "OPENAI_API_ORGANIZATION=${OPENAI_API_ORGANIZATION}" >> ./.env + echo "OPENAI_API_KEY=${OPENAI_API_KEY}" >> ./.env + echo "PINECONE_API_KEY=${PINECONE_API_KEY}" >> ./.env + echo "PINECONE_ENVIRONMENT=${PINECONE_ENVIRONMENT}" >> ./.env + + - name: Test lambda_openai_v2 + if: steps.file_changes.outputs.py_files_changed != '' || steps.file_changes.outputs.requirements_changed != '' + run: | + cd ./api/terraform/python/lambda_openai_v2 + pytest -v -s tests/ + + - name: Test lambda_langchain + if: steps.file_changes.outputs.py_files_changed != '' || steps.file_changes.outputs.requirements_changed != '' + run: | + cd ./api/terraform/python/lambda_langchain + pytest -v -s tests/ terraform_tests: needs: check_for_pending_release @@ -139,14 +164,31 @@ jobs: run: | echo "::set-output name=terraform_files_changed::$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | grep '\.tf$' || true)" - - name: Run Terraform Tests + - name: Configure AWS credentials + if: steps.file_changes.outputs.terraform_files_changed != '' + uses: aws-actions/configure-aws-credentials@v4 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: ${{ secrets.AWS_REGION }} + + - name: Terraform Init if: steps.file_changes.outputs.terraform_files_changed != '' - id: terraform_tests - uses: ./.github/workflows/testTerraform.yml + run: | + cd api/terraform + terraform init - - name: No Terraform changes detected - if: steps.file_changes.outputs.py_files_changed == '' - run: echo "No Terraform changes detected." + - name: Terraform Validate + if: steps.file_changes.outputs.terraform_files_changed != '' + run: | + cd api/terraform + terraform validate + + - name: Terraform Format + if: steps.file_changes.outputs.terraform_files_changed != '' + run: | + cd api/terraform + terraform fmt -check reactjs_tests: needs: check_for_pending_release @@ -164,11 +206,8 @@ jobs: - name: Run ReactJS Tests if: steps.file_changes.outputs.reactjs_files_changed != '' id: reactjs_tests - uses: ./.github/workflows/testReact.yml - - - name: No ReactJS changes detected - if: steps.file_changes.outputs.py_files_changed == '' - run: echo "No ReactJS changes detected." + run: | + echo "Test scaffolding for ReactJS" pre_commit_tests: needs: check_for_pending_release @@ -178,6 +217,13 @@ jobs: id: checkout uses: actions/checkout@v4 - - name: Run ReactJS Tests - id: precommit_tests - uses: ./.github/workflows/testPreCommitRules.yml + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: 3.11 + + # see: https://pre-commit.ci/lite.html + - name: pre-commit ci + id: pre-commit-ci + if: always() + uses: pre-commit-ci/lite-action@v1.0.0 diff --git a/.github/workflows/testPreCommitRules.yml b/.github/workflows/testPreCommitRules.yml deleted file mode 100644 index 98119b7c..00000000 --- a/.github/workflows/testPreCommitRules.yml +++ /dev/null @@ -1,25 +0,0 @@ -# ----------------------------------------------------------------------------- -# pre-commit tests -# ----------------------------------------------------------------------------- - name: Test pre-commit rules - - on: - workflow_dispatch: - pull_request: - - jobs: - pre-commit: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: 3.11 - - # see: https://pre-commit.ci/lite.html - - name: pre-commit ci - id: pre-commit-ci - if: always() - uses: pre-commit-ci/lite-action@v1.0.0 diff --git a/.github/workflows/testPython.yml b/.github/workflows/testPython.yml deleted file mode 100644 index a0202c72..00000000 --- a/.github/workflows/testPython.yml +++ /dev/null @@ -1,61 +0,0 @@ -# ----------------------------------------------------------------------------- -# Python Tests -# -# This workflow will run tests on the Python code located in ./api/terraform/python -# -# Notes: -# - pull_request_target is used instead of pull_request because the -# pull_request_target event behaves in an almost identical way to the -# pull_request event, however, t runs in the context of the base repository of the -# pull request rather than in the merge commit. This means that you have -# access to Github Organization secrets when the workflow is triggered by -# a pull_request_target event. -# -# - optionally add `if: github.actor != 'dependabot[bot]'` to the python-tests job to -# prevent dependabot from running tests -# ----------------------------------------------------------------------------- - name: Test Python - - on: [workflow_dispatch] - - jobs: - python-tests: - env: - OPENAI_API_ORGANIZATION: ${{ secrets.OPENAI_API_ORGANIZATION }} - OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} - PINECONE_API_KEY: ${{ secrets.PINECONE_API_KEY }} - PINECONE_ENVIRONMENT: ${{ secrets.PINECONE_ENVIRONMENT }} - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: 3.11 - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r ./requirements.txt - cp -R ./api/terraform/python/layer_genai/openai_utils /opt/hostedtoolcache/Python/3.11.6/x64/lib/python3.11/site-packages/ - - - name: Create .env - run: | - touch ./.env - echo "OPENAI_API_ORGANIZATION=${OPENAI_API_ORGANIZATION}" >> ./.env - echo "OPENAI_API_KEY=${OPENAI_API_KEY}" >> ./.env - echo "PINECONE_API_KEY=${PINECONE_API_KEY}" >> ./.env - echo "PINECONE_ENVIRONMENT=${PINECONE_ENVIRONMENT}" >> ./.env - - - name: Test lambda_openai_v2 - run: | - cd ./api/terraform/python/lambda_openai_v2 - pytest -v -s tests/ - - - name: Test lambda_langchain - run: | - cd ./api/terraform/python/lambda_langchain - pytest -v -s tests/ diff --git a/.github/workflows/testReact.yml b/.github/workflows/testReact.yml deleted file mode 100644 index a1066268..00000000 --- a/.github/workflows/testReact.yml +++ /dev/null @@ -1,29 +0,0 @@ -# ----------------------------------------------------------------------------- -# ReactJS Tests -# -# This workflow will run tests on the ReactJS code located in ./api/reactjs/ -# -# Notes: -# - pull_request_target is used instead of pull_request because the -# pull_request_target event behaves in an almost identical way to the -# pull_request event, however, t runs in the context of the base repository of the -# pull request rather than in the merge commit. This means that you have -# access to Github Organization secrets when the workflow is triggered by -# a pull_request_target event. -# -# - optionally add `if: github.actor != 'dependabot[bot]'` to the reactjs-tests job to -# prevent dependabot from running tests -# ----------------------------------------------------------------------------- - name: Test ReactJS - - on: [workflow_dispatch] - - jobs: - test-reactjs: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - - name: Test ReactJS - run: | - echo "Test scaffolding for ReactJS" diff --git a/.github/workflows/testTerraform.yml b/.github/workflows/testTerraform.yml deleted file mode 100644 index abf8a936..00000000 --- a/.github/workflows/testTerraform.yml +++ /dev/null @@ -1,48 +0,0 @@ -# ----------------------------------------------------------------------------- -# Terraform Tests -# -# This workflow will run tests on the Terraform code located in ./api/terraform/ -# -# Notes: -# - pull_request_target is used instead of pull_request because the -# pull_request_target event behaves in an almost identical way to the -# pull_request event, however, t runs in the context of the base repository of the -# pull request rather than in the merge commit. This means that you have -# access to Github Organization secrets when the workflow is triggered by -# a pull_request_target event. -# -# - optionally add `if: github.actor != 'dependabot[bot]'` to the terraform-tests job to -# prevent dependabot from running tests -# ----------------------------------------------------------------------------- - name: Test Terraform - - on: [workflow_dispatch] - - jobs: - test-terraform: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: hashicorp/setup-terraform@v1 - - - name: Configure AWS credentials - uses: aws-actions/configure-aws-credentials@v4 - with: - aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} - aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - aws-region: ${{ secrets.AWS_REGION }} - - - name: Terraform Init - run: | - cd api/terraform - terraform init - - - name: Terraform Validate - run: | - cd api/terraform - terraform validate - - - name: Terraform Format - run: | - cd api/terraform - terraform fmt -check diff --git a/tox.ini b/tox.ini index 5163be58..44742ae3 100644 --- a/tox.ini +++ b/tox.ini @@ -19,7 +19,7 @@ commands = pytest ignore = D205,D413,D400,D401 max-line-length =120 max-complexity = 10 -exclude = api/terraform/python/lambda_openai/venv, api/terraform/python/lambda_openai/lambda_dist_pkg, api/terraform/python/lambda_langchain/lambda_dist_pkg +exclude = api/terraform/python/lambda_openai/venv, api/terraform/python/lambda_openai/lambda_dist_pkg, api/terraform/python/lambda_openai_v2/lambda_dist_pkg, api/terraform/python/lambda_langchain/lambda_dist_pkg extend-exclude = *__init__.py,*__version__.py,venv,lambda_dist_pkg select = C101