name: Unit Tests
on:
  push:
    branches: [main]
    paths:
      - "backend/**"
  pull_request:
    branches: [main]
    paths:
      - "backend/**"

jobs:
  test-backend:
    permissions:
      contents: read
      actions: write
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5
      - uses: actions/setup-go@v6
        with:
          go-version-file: "backend/go.mod"
          cache-dependency-path: "backend/go.sum"
      - name: Install dependencies
        working-directory: backend
        run: |
          go get ./...
      - name: Run backend unit tests
        working-directory: backend
        run: |
          set -e -o pipefail
          go test -tags=exclude_frontend -v ./... | tee /tmp/TestResults.log
      - uses: actions/upload-artifact@v4
        if: always()
        with:
          name: backend-unit-tests
          path: /tmp/TestResults.log
          retention-days: 15
