name: CI

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

jobs:
  build-and-test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - uses: actions/setup-node@v4
        with:
          node-version: "20"
          cache: "npm"
          cache-dependency-path: |
            backend/package-lock.json
            frontend/package-lock.json

      - name: Backend — install, build, test
        working-directory: backend
        env:
          CALENDAR_RUN_MOCK_DB: "1"
        run: |
          npm ci
          npm run build
          npm test

      - name: Frontend — install, build
        working-directory: frontend
        run: |
          npm ci
          npm run build
