name: Test PR (server)

on:
  pull_request:
    branches:
      - "**"
    tags-ignore:
      - v*
    paths:
      - ".github/workflows/test-pr-server.yml"
      - "server/**"

jobs:
  test_and_format_check_go:
    runs-on: ubuntu-latest

    defaults:
      run:
        working-directory: server

    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-go@v5

      - name: go test all packages
        run: go test ./...

      - name: gofmt test
        run: |
          outp=$(gofmt -l .)
          if [ -n "$outp" ]; then
            echo "Need to fix formatting!"
            echo "$outp"
            exit 1
          else
            echo "Everything looks formatted"
            exit 0
          fi
