mirror of
https://github.com/ramvignesh-b/pi-ku.git
synced 2026-05-04 20:43:48 +00:00
164 lines
4.1 KiB
YAML
164 lines
4.1 KiB
YAML
name: CI
|
|
|
|
on:
|
|
push:
|
|
branches: [ main ]
|
|
pull_request:
|
|
branches: [ main ]
|
|
|
|
env:
|
|
# WHY?: services are executed way before the env can be sourced from .env file
|
|
DB_NAME: piku_test_db
|
|
DB_USER: test
|
|
DB_PASSWORD: password123
|
|
|
|
jobs:
|
|
setup-environment:
|
|
name: Generate Certificates
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
- name: Generate SSL Certificates
|
|
run: |
|
|
sudo apt-get update && sudo apt-get install -y mkcert libnss3-tools
|
|
mkdir -p certs
|
|
mkcert -install
|
|
mkcert -cert-file certs/localhost.pem -key-file certs/localhost-key.pem localhost 127.0.0.1 ::1
|
|
|
|
- name: Cache certificates
|
|
uses: actions/cache/save@v4
|
|
with:
|
|
path: certs
|
|
key: certs-${{ runner.os }}-${{ github.sha }}
|
|
|
|
frontend:
|
|
name: Frontend CI
|
|
runs-on: ubuntu-latest
|
|
needs: setup-environment
|
|
defaults:
|
|
run:
|
|
working-directory: ./frontend
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
- uses: oven-sh/setup-bun@v2
|
|
|
|
- name: Restore certificates
|
|
uses: actions/cache/restore@v4
|
|
with:
|
|
path: certs
|
|
key: certs-${{ runner.os }}-${{ github.sha }}
|
|
|
|
- name: Install dependencies
|
|
run: bun install --frozen-lockfile
|
|
|
|
- name: Code Quality
|
|
run: |
|
|
cp ../.env.example ../.env
|
|
bun run check
|
|
|
|
- name: Type Check & Build
|
|
run: bun run build
|
|
|
|
- name: Unit Tests
|
|
run: bun run test
|
|
|
|
backend:
|
|
name: Backend CI
|
|
runs-on: ubuntu-latest
|
|
needs: setup-environment
|
|
services:
|
|
postgres:
|
|
image: postgres:16-alpine
|
|
env:
|
|
POSTGRES_DB: ${{ env.DB_NAME }}
|
|
POSTGRES_USER: ${{ env.DB_USER }}
|
|
POSTGRES_PASSWORD: ${{ env.DB_PASSWORD }}
|
|
ports:
|
|
- 5442:5432
|
|
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
|
|
defaults:
|
|
run:
|
|
working-directory: ./backend
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
- name: Install uv
|
|
uses: astral-sh/setup-uv@v5
|
|
with:
|
|
enable-cache: true
|
|
cache-dependency-glob: "backend/uv.lock"
|
|
|
|
- name: Restore certificates
|
|
uses: actions/cache/restore@v4
|
|
with:
|
|
path: certs
|
|
key: certs-${{ runner.os }}-${{ github.sha }}
|
|
|
|
- name: Lint & Test
|
|
run: |
|
|
cp ../.env.example ../.env
|
|
uv sync
|
|
|
|
if [ "$GITEA_ACTIONS" = "true" ]; then
|
|
export DB_HOST="postgres"
|
|
export DB_PORT="5432"
|
|
else
|
|
export DB_HOST="127.0.0.1"
|
|
export DB_PORT="5442"
|
|
fi
|
|
|
|
uv run ruff check
|
|
uv run python manage.py test
|
|
|
|
e2e:
|
|
name: E2E Tests
|
|
runs-on: ubuntu-latest
|
|
needs: setup-environment
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Restore Certificates
|
|
uses: actions/cache/restore@v4
|
|
with:
|
|
path: certs
|
|
key: certs-${{ runner.os }}-${{ github.sha }}
|
|
|
|
- name: Setup Tools
|
|
uses: astral-sh/setup-uv@v5
|
|
|
|
- uses: oven-sh/setup-bun@v2
|
|
|
|
|
|
- name: Cache Playwright
|
|
id: playwright-cache
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: ~/.cache/ms-playwright
|
|
key: ${{ runner.os }}-playwright-${{ hashFiles('frontend/bun.lock') }}
|
|
|
|
- name: Install Dependencies
|
|
run: |
|
|
(cd frontend && bun install)
|
|
if [ "${{ steps.playwright-cache.outputs.cache-hit }}" != "true" ]; then
|
|
(cd frontend && bun x playwright install --with-deps)
|
|
fi
|
|
|
|
- name: Run E2E
|
|
run: |
|
|
cp .env.e2e.example .env.e2e
|
|
chmod +x ./scripts/run-e2e.sh
|
|
./scripts/run-e2e.sh
|
|
env:
|
|
CI: "true"
|
|
|
|
- name: Upload Playwright Report
|
|
if: always()
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: playwright-report
|
|
path: frontend/playwright-report/
|
|
retention-days: 10
|
|
|
|
- name: Print Backend Logs on Failure
|
|
if: failure()
|
|
run: cat tmp/logs/backend.log || true
|