name: Build and Test

on:
  pull_request:
    branches:
      - main

jobs:
  build:
    runs-on: ubuntu-latest

    container:
      image: fedora:latest

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Set up C++ environment
        run: |
          dnf install -y gcc gcc-c++ cmake make

      - name: Install SDL2 dependencies
        run: |
          dnf install -y SDL2 SDL2-devel SDL2_image SDL2_image-devel SDL2_ttf SDL2_ttf-devel SDL2_net SDL2_net-devel SDL2_mixer SDL2_mixer-devel

      - name: Clean build directory
        run: rm -rf build

      - name: Create build directory
        run: mkdir build

      - name: Configure CMake
        run: cmake -S . -B build -DCMAKE_BUILD_TYPE=Release

      - name: Build project
        run: cmake --build build -- -j $(nproc)

      - name: Check for warnings and errors
        run: |
          if grep -i "warning\|error" build/compile_commands.json; then
            echo "Build contains warnings or errors"
            exit 1
          fi