name: Server Build

on:
  push:
    branches:
      - main
    paths:
      - "Cargo.toml"
      - "Cargo.lock"
      - "src/**"
      - "crates/**"
      - ".github/workflows/server-build.yml"
  pull_request:
    branches:
      - main
    paths:
      - "Cargo.toml"
      - "Cargo.lock"
      - "src/**"
      - "crates/**"
      - ".github/workflows/server-build.yml"
  workflow_dispatch:

env:
  CARGO_TERM_COLOR: always

jobs:
  server-build:
    name: Build Rust Server
    runs-on: ubuntu-latest
    timeout-minutes: 30
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Setup Rust toolchain
        uses: dtolnay/rust-toolchain@stable

      - name: Cache Rust artifacts
        uses: Swatinem/rust-cache@v2

      - name: Build server binary
        run: cargo build --bin server --features server --locked

      - name: Compile server tests
        run: cargo test --bin server --features server --no-run --locked
