Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions .github/workflows/lambda-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: Lambda Tests

on:
push:
branches: [main, develop]
pull_request:
branches: [main, develop]

jobs:
discover:
runs-on: ubuntu-latest
outputs:
lambdas: ${{ steps.find.outputs.lambdas }}
steps:
- uses: actions/checkout@v4
- name: Find all lambdas
id: find
run: |
lambdas=$(ls -d apps/backend/lambdas/*/ | grep -Ev "(tools)" | jq -R -s -c 'split("\n") | map(select(. != ""))')
echo "lambdas=$lambdas" >> $GITHUB_OUTPUT

test:
needs: discover
runs-on: ubuntu-latest

services:
postgres:
image: postgres:16
env:
POSTGRES_USER: branch_dev
POSTGRES_PASSWORD: password
POSTGRES_DB: branch_db
ports:
- 5432:5432
options: >-
--health-cmd="pg_isready"
--health-interval=10s
--health-timeout=5s
--health-retries=5

strategy:
fail-fast: false
matrix:
lambda: ${{ fromJson(needs.discover.outputs.lambdas) }}

steps:
- uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'

- name: Setup database schema
run: psql postgres://branch_dev:password@localhost:5432/branch_db -f apps/backend/db/db_setup.sql

- name: Install dependencies
working-directory: ${{ matrix.lambda }}
run: npm ci --legacy-peer-deps

- name: Run tests
working-directory: ${{ matrix.lambda }}
run: |
LAMBDA_NAME=$(basename ${{ matrix.lambda }})
npm run dev &
sleep 5
curl --fail --retry 5 --retry-delay 2 http://localhost:3000/${LAMBDA_NAME}/health
npm test
env:
DATABASE_URL: postgres://branch_dev:password@localhost:5432/branch_db?options=-csearch_path%3Dbranch
2 changes: 1 addition & 1 deletion infrastructure/github/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ resource "github_branch_protection" "main" {

required_status_checks {
strict = true
contexts = ["terraform-plan-summary"]
contexts = ["terraform-plan-summary", "lambda-tests"]
}

enforce_admins = false
Expand Down
Loading