Skip to content

Added more e2e tests for the workflows and added ai summary feature f… #133

Added more e2e tests for the workflows and added ai summary feature f…

Added more e2e tests for the workflows and added ai summary feature f… #133

Workflow file for this run

name: Run Tests and Verify Coverage
on:
push:
branches: ["**"]
pull_request:
branches: ["**"]
types: [opened, synchronize, reopened]
workflow_dispatch:
jobs:
test:
name: Run Unit & Integration Tests
runs-on: ubuntu-latest
outputs:
coverage_percent: ${{ steps.extract_coverage.outputs.coverage_percent }}
services:
postgres:
image: postgres:15
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: test_db
ports: ["5432:5432"]
options: >-
--health-cmd "pg_isready -U postgres"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 22
- name: Install dependencies
run: npm ci
- name: Copy example .env if present
run: |
if [ -f .env.example ]; then
cp .env.example .env
else
echo ".env.example not found, skipping..."
fi
- name: Run database migrations (Supabase)
uses: supabase/setup-cli@v1
with:
version: latest
continue-on-error: true
- run: supabase db push || echo "Skipping local migration if not needed"
- name: Run Unit Tests with Coverage
run: npm run test:coverage
env:
NODE_ENV: test
DATABASE_URL: postgresql://postgres:postgres@localhost:5432/test_db
- name: Run Integration Tests (API, Supabase)
run: npm test
env:
NODE_ENV: test
DATABASE_URL: postgresql://postgres:postgres@localhost:5432/test_db
NEXT_PUBLIC_SUPABASE_URL: ${{ secrets.NEXT_PUBLIC_SUPABASE_URL }}
NEXT_PUBLIC_SUPABASE_ANON_KEY: ${{ secrets.NEXT_PUBLIC_SUPABASE_ANON_KEY }}
- name: Install Playwright browsers
run: npx playwright install --with-deps
- name: Build Next.js app for E2E tests
run: npm run build
env:
NODE_ENV: production
NEXT_PUBLIC_SUPABASE_URL: ${{ secrets.NEXT_PUBLIC_SUPABASE_URL }}
NEXT_PUBLIC_SUPABASE_ANON_KEY: ${{ secrets.NEXT_PUBLIC_SUPABASE_ANON_KEY }}
- name: Run End-to-End Tests (Playwright)
if: ${{ hashFiles('e2e/**') != '' }}
run: npm run test:e2e
env:
NODE_ENV: test
BASE_URL: http://localhost:3000
NEXT_PUBLIC_SUPABASE_URL: ${{ secrets.NEXT_PUBLIC_SUPABASE_URL }}
NEXT_PUBLIC_SUPABASE_ANON_KEY: ${{ secrets.NEXT_PUBLIC_SUPABASE_ANON_KEY }}
- name: Extract Coverage Percentage
id: extract_coverage
run: |
COVERAGE_PERCENT=$(cat coverage/coverage-summary.json | jq '.total.lines.pct' 2>/dev/null || echo "0")
echo "COVERAGE_PERCENT=${COVERAGE_PERCENT}" >> $GITHUB_ENV
echo "coverage_percent=${COVERAGE_PERCENT}" >> $GITHUB_OUTPUT
- name: Post coverage comment to PR
uses: actions/github-script@v7
if: ${{ github.event_name == 'pull_request' }}
with:
script: |
const coverage = process.env.COVERAGE_PERCENT || 'N/A';
const color = coverage < 50 ? 'red' : coverage < 80 ? 'yellow' : 'brightgreen';
const badge = `![Coverage](https://img.shields.io/badge/coverage-${coverage}%25-${color})`;
const body = `${badge}\n\n> **Unit + Integration coverage:** ${coverage}%`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body
});
validate_coverage:
name: Validate Coverage Threshold
runs-on: ubuntu-latest
needs: test
if: github.event_name == 'pull_request'
steps:
- name: Validate minimum coverage (80%)
run: |
COVERAGE=${{ needs.test.outputs.coverage_percent }}
echo "Reported coverage: ${COVERAGE}%"
if [ "$COVERAGE" != "N/A" ] && (( $(echo "$COVERAGE < 80" | bc -l) )); then
echo "Coverage below threshold (80%)."
exit 1
else
echo "Coverage meets minimum threshold."
fi
e2e:
name: End-to-End Tests (Playwright)
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 22
- name: Install dependencies
run: npm ci
- name: Install Playwright browsers
run: npx playwright install --with-deps
- name: Build Next.js app
run: npm run build
env:
NODE_ENV: production
NEXT_PUBLIC_SUPABASE_URL: ${{ secrets.NEXT_PUBLIC_SUPABASE_URL }}
NEXT_PUBLIC_SUPABASE_ANON_KEY: ${{ secrets.NEXT_PUBLIC_SUPABASE_ANON_KEY }}
- name: Run Playwright E2E Tests
run: npm run test:e2e
env:
NODE_ENV: test
BASE_URL: http://localhost:3000
NEXT_PUBLIC_SUPABASE_URL: ${{ secrets.NEXT_PUBLIC_SUPABASE_URL }}
NEXT_PUBLIC_SUPABASE_ANON_KEY: ${{ secrets.NEXT_PUBLIC_SUPABASE_ANON_KEY }}