name: Unittests

on:
  pull_request:
    paths:
      - "server/**"
  push:
    branches:
      - main
    paths:
      - "server/**"

jobs:
  pytest:
    runs-on: ubuntu-latest
    concurrency:
      group: pytest-${{ github.ref }}
      cancel-in-progress: true
    services:
      redis:
        image: redis:6
        ports:
          - 6379:6379
    steps:
      - uses: actions/checkout@v4
      - name: Install uv
        uses: astral-sh/setup-uv@v6
        with:
          enable-cache: true
          working-directory: server
      - name: Tests
        run: |
          cd server
          uv run -m pytest -v tests

  docker-amd64:
    runs-on: linux-amd64
    concurrency:
      group: docker-amd64-${{ github.ref }}
      cancel-in-progress: true
    steps:
      - uses: actions/checkout@v4
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3
      - name: Build AMD64
        uses: docker/build-push-action@v6
        with:
          context: server
          platforms: linux/amd64
          cache-from: type=gha,scope=amd64
          cache-to: type=gha,mode=max,scope=amd64
          github-token: ${{ secrets.GHA_CACHE_TOKEN }}

  docker-arm64:
    runs-on: linux-arm64
    concurrency:
      group: docker-arm64-${{ github.ref }}
      cancel-in-progress: true
    steps:
      - uses: actions/checkout@v4
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3
      - name: Build ARM64
        uses: docker/build-push-action@v6
        with:
          context: server
          platforms: linux/arm64
          cache-from: type=gha,scope=arm64
          cache-to: type=gha,mode=max,scope=arm64
          github-token: ${{ secrets.GHA_CACHE_TOKEN }}
