name: linkding CI

on:
  pull_request:
  push:
    branches:
      - master

jobs:
  unit_tests:
    name: Unit Tests
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: "3.13"
      - name: Install uv
        uses: astral-sh/setup-uv@v6
      - name: Set up Node
        uses: actions/setup-node@v4
        with:
          node-version: 20
          cache: 'npm'
      - name: Install Node dependencies
        run: npm ci
      - name: Setup Python environment
        run: |
          uv sync
          mkdir data
      - name: Run tests
        run: uv run pytest -n auto
  e2e_tests:
    name: E2E Tests
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: "3.13"
      - name: Install uv
        uses: astral-sh/setup-uv@v6
      - name: Set up Node
        uses: actions/setup-node@v4
        with:
          node-version: 20
          cache: 'npm'
      - name: Install Node dependencies
        run: npm ci
      - name: Setup Python environment
        run: |
          uv sync
          uv run playwright install chromium
          mkdir data
      - name: Run build
        run: |
          npm run build
          uv run manage.py collectstatic
      - name: Run tests
        run: uv run pytest bookmarks/tests_e2e -n auto -o "python_files=e2e_test_*.py"
      - name: Upload screenshots
        if: failure()
        uses: actions/upload-artifact@v4
        with:
          name: e2e-screenshots
          path: test-results/screenshots
