name: PR

on:
  pull_request:

jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
      - uses: https://git.keligrubb.com/actions/checkout@v7

      - name: Setup Node.js
        uses: https://git.keligrubb.com/actions/setup-node@v7
        with:
          node-version: "24"
          cache: "npm"

      - name: Install dependencies
        run: npm ci

      - name: Run lint
        run: npm run lint

  test:
    runs-on: ubuntu-latest
    steps:
      - uses: https://git.keligrubb.com/actions/checkout@v7

      - name: Setup Node.js
        uses: https://git.keligrubb.com/actions/setup-node@v7
        with:
          node-version: "24"
          cache: "npm"

      - name: Install dependencies
        run: npm ci

      - name: Run tests
        run: npm run test

  e2e:
    runs-on: ubuntu-latest
    container:
      image: mcr.microsoft.com/playwright:v1.61.1-noble
    steps:
      - uses: https://git.keligrubb.com/actions/checkout@v7

      - name: Setup Node.js
        uses: https://git.keligrubb.com/actions/setup-node@v7
        with:
          node-version: "24"
          cache: "npm"

      - name: Install dependencies
        run: npm ci

      - name: Generate dev cert
        run: ./scripts/gen-dev-cert.sh

      - name: Run e2e tests
        run: npm run test:e2e
        env:
          NODE_TLS_REJECT_UNAUTHORIZED: "0"

  docker-build:
    runs-on: ubuntu-latest
    steps:
      - uses: https://git.keligrubb.com/actions/checkout@v7

      - name: Set Docker image tag
        id: image
        run: |
          REGISTRY="${GITHUB_SERVER_URL#https://}"
          REGISTRY="${REGISTRY#http://}"
          echo "tag=${REGISTRY}/${{ github.repository }}:latest" >> $GITHUB_OUTPUT

      - name: Set up Docker Buildx
        uses: https://git.keligrubb.com/actions/docker-setup-buildx-action@v4

      - name: Build (dry run)
        uses: https://git.keligrubb.com/actions/docker-build-push-action@v7
        env:
          # Keeps GITHUB_OUTPUT small; Gitea act-runner can choke on multiline
          # outputs when PR webhook payloads (e.g. Renovate bodies) are huge.
          DOCKER_BUILD_SUMMARY: "false"
          DOCKER_BUILD_RECORD_UPLOAD: "false"
        with:
          context: .
          push: false
          provenance: false
          sbom: false
          tags: ${{ steps.image.outputs.tag }}
