Skip to content

Commit

Permalink
Merge pull request #96 from FullStackWithLawrence/next
Browse files Browse the repository at this point in the history
refactor: move all test logic to standalone actions
  • Loading branch information
lpm0073 authored Nov 17, 2023
2 parents b18ce59 + 4fe15d3 commit a4bd894
Show file tree
Hide file tree
Showing 5 changed files with 174 additions and 80 deletions.
30 changes: 30 additions & 0 deletions .github/actions/tests/pre-commit/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#------------------------------------------------------------------------------
# Run pre-commit
#------------------------------------------------------------------------------
name: Test pre-commit
branding:
icon: 'git-pull-request'
color: 'orange'
inputs:
python-version:
description: 'The version of Python to use, such as 3.11.0'
required: true
type: string

runs:
using: "composite"
steps:
- name: Checkout code
id: checkout
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ inputs.python-version }}

# see: https://pre-commit.ci/lite.html
- name: pre-commit ci
id: pre-commit-ci
if: always()
uses: pre-commit-ci/[email protected]
56 changes: 56 additions & 0 deletions .github/actions/tests/python/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#------------------------------------------------------------------------------
# Run Python unit tests
#------------------------------------------------------------------------------
name: Test Python
branding:
icon: 'git-pull-request'
color: 'orange'
inputs:
python-version:
description: 'The version of Python to use, such as 3.11.0'
required: true
type: string
env:
REQUIREMENTS_PATH: 'api/terraform/python/layer_genai/requirements.txt'

runs:
using: "composite"
steps:
- name: Checkout code
id: checkout
uses: actions/checkout@v4

- name: Set up Python
if: steps.file_changes.outputs.files_changed != '' || steps.file_changes.outputs.requirements_changed != ''
uses: actions/setup-python@v4
with:
python-version: ${{ inputs.python-version }} }}}

- name: Install dependencies
if: steps.file_changes.outputs.files_changed != '' || steps.file_changes.outputs.requirements_changed != ''
run: |
python -m pip install --upgrade pip
pip install -r ./requirements.txt
pip install -r ${{ env.REQUIREMENTS_PATH }}
cp -R ./api/terraform/python/layer_genai/openai_utils venv/lib/python${{ inputs.python-version }}/site-packages/
- name: Create .env
if: steps.file_changes.outputs.files_changed != '' || steps.file_changes.outputs.requirements_changed != ''
run: |
touch ./.env
echo "OPENAI_API_ORGANIZATION=${{ secrets.OPENAI_API_ORGANIZATION }}" >> ./.env
echo "OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }}" >> ./.env
echo "PINECONE_API_KEY=${{ secrets.PINECONE_API_KEY }}" >> ./.env
echo "PINECONE_ENVIRONMENT=${{ secrets.PINECONE_ENVIRONMENT }}" >> ./.env
- name: Test lambda_openai_v2
if: steps.file_changes.outputs.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.files_changed != '' || steps.file_changes.outputs.requirements_changed != ''
run: |
cd ./api/terraform/python/lambda_langchain
pytest -v -s tests/
25 changes: 25 additions & 0 deletions .github/actions/tests/reactjs/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#------------------------------------------------------------------------------
# Run ReactJS unit tests
#------------------------------------------------------------------------------
name: Test ReactJS
branding:
icon: 'git-pull-request'
color: 'orange'

runs:
using: "composite"
steps:
- name: Checkout code
id: checkout
uses: actions/checkout@v4

- name: Check for ReactJS files changed
id: file_changes
run: |
echo "::set-output name=reactjs_files_changed::$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | grep '^client/' || true)"
- name: Run ReactJS Tests
if: steps.file_changes.outputs.reactjs_files_changed != ''
id: reactjs_tests
run: |
echo "Test scaffolding for ReactJS"
40 changes: 40 additions & 0 deletions .github/actions/tests/terraform/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#------------------------------------------------------------------------------
# Run Terraform tests
#------------------------------------------------------------------------------
name: Test Terraform
branding:
icon: 'git-pull-request'
color: 'orange'

runs:
using: "composite"
steps:
- name: Checkout code
id: checkout
uses: actions/checkout@v4

- 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 != ''
run: |
cd api/terraform
terraform init
- 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
103 changes: 23 additions & 80 deletions .github/workflows/pullRequestController.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ permissions:
pages: write
id-token: write

env:
python-version: "3.11"

jobs:
check_for_pending_release:
name: test-semantic-release
Expand Down Expand Up @@ -103,53 +106,23 @@ jobs:
python_tests:
needs: check_for_pending_release
runs-on: ubuntu-latest
env:
REQUIREMENTS_PATH: 'api/terraform/python/layer_genai/requirements.txt'

steps:
- name: Checkout code
id: checkout
uses: actions/checkout@v4

- name: Check for Python files changed
- name: Check for changed files
id: file_changes
run: |
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)"
echo "::set-output name=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 'requirements.txt$' || true)"
- name: Set up Python
if: steps.file_changes.outputs.py_files_changed != '' || steps.file_changes.outputs.requirements_changed != ''
uses: actions/setup-python@v4
- name: Run Python tests
if: steps.file_changes.outputs.files_changed != '' || steps.file_changes.outputs.requirements_changed != ''
uses: ./.github/actions/tests/python
with:
python-version: 3.11

- 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/
python-version: "${{ env.python-version}}"

terraform_tests:
needs: check_for_pending_release
Expand All @@ -159,36 +132,14 @@ jobs:
id: checkout
uses: actions/checkout@v4

- name: Check for Terraform files changed
- name: Check for changed files
id: file_changes
run: |
echo "::set-output name=terraform_files_changed::$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | grep '\.tf$' || true)"
echo "::set-output name=files_changed::$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | grep '\.tf$' || true)"
- 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 != ''
run: |
cd api/terraform
terraform init
- 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
- name: Run Terraform tests
if: steps.file_changes.outputs.files_changed != ''
uses: ./.github/actions/tests/reactjs

reactjs_tests:
needs: check_for_pending_release
Expand All @@ -198,16 +149,14 @@ jobs:
id: checkout
uses: actions/checkout@v4

- name: Check for ReactJS files changed
- name: Check for changed files
id: file_changes
run: |
echo "::set-output name=reactjs_files_changed::$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | grep '^client/' || true)"
echo "::set-output name=files_changed::$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} -- './client/' || true)"
- name: Run ReactJS Tests
if: steps.file_changes.outputs.reactjs_files_changed != ''
id: reactjs_tests
run: |
echo "Test scaffolding for ReactJS"
- name: Run ReactJS tests
if: steps.file_changes.outputs.files_changed != ''
uses: ./.github/actions/tests/reactjs

pre_commit_tests:
needs: check_for_pending_release
Expand All @@ -217,13 +166,7 @@ jobs:
id: checkout
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
- name: Run pre-commit tests
uses: ./.github/actions/tests/pre-commit
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/[email protected]
python-version: "${{ env.python-version}}"

0 comments on commit a4bd894

Please sign in to comment.