Readur/.github/workflows/test-e2e.yml

153 lines
3.9 KiB
YAML

name: E2E Tests
on:
push:
branches:
- master
- main
pull_request:
branches:
- master
- main
env:
CARGO_TERM_COLOR: always
jobs:
e2e-tests:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:17
env:
POSTGRES_USER: readur
POSTGRES_PASSWORD: readur
POSTGRES_DB: readur
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y \
tesseract-ocr \
tesseract-ocr-eng \
tesseract-ocr-spa \
tesseract-ocr-fra \
tesseract-ocr-deu \
tesseract-ocr-ita \
tesseract-ocr-por \
libtesseract-dev \
libleptonica-dev \
pkg-config \
libclang-dev \
ocrmypdf \
clang
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "22"
cache: "npm"
cache-dependency-path: frontend/package-lock.json
- name: Cache cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-
- name: Build backend
run: cargo build --release
env:
DATABASE_URL: postgres://readur:readur@localhost:5432/readur
RUST_BACKTRACE: 1
- name: Build frontend
working-directory: ./frontend
run: |
npm install
npm run build
- name: Start backend server
run: |
echo "Starting server with DATABASE_URL: $DATABASE_URL"
./target/release/readur > server.log 2>&1 &
echo $! > backend.pid
sleep 2
echo "Server started with PID: $(cat backend.pid)"
env:
DATABASE_URL: postgres://readur:readur@localhost:5432/readur
JWT_SECRET: test-secret-key
PORT: 8000
FRONTEND_PATH: ./frontend/dist
UPLOAD_PATH: ./uploads
WATCH_PATH: ./watch
RUST_BACKTRACE: 1
DEBUG: 1
- name: Wait for backend to be ready
run: |
for i in {1..30}; do
if curl -f http://localhost:8000/api/health > /dev/null 2>&1; then
echo "Backend is ready"
break
fi
echo "Waiting for backend... ($i/30)"
sleep 2
done
- name: Install Playwright browsers
working-directory: ./frontend
run: npx playwright install --with-deps
- name: Run frontend E2E tests
working-directory: ./frontend
run: npm run test:e2e
env:
VITE_API_URL: http://localhost:8000
PLAYWRIGHT_BASE_URL: http://localhost:8000
- name: Upload Playwright Test Results
uses: actions/upload-artifact@v4
if: always()
with:
name: playwright-results
path: |
frontend/test-results/
frontend/playwright-report/
retention-days: 30
- name: Print server logs on failure
if: failure()
run: |
echo "=== Server logs ==="
cat server.log || echo "No server logs found"
echo "=== End of server logs ==="
- name: Stop backend server
if: always()
run: |
if [ -f backend.pid ]; then
kill $(cat backend.pid) || true
rm backend.pid
fi