name: Test content master against engine

on:
  push:
    branches: [master]
  pull_request:
    branches: [master]

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - name: Check out content
        uses: actions/checkout@v4.2.2
        with:
          repository: space-wizards/space-station-14
          submodules: recursive

      - name: Setup .NET Core
        uses: actions/setup-dotnet@v4.1.0
        with:
          dotnet-version: 10.0.x
      - name: Disable submodule autoupdate
        run: touch BuildChecker/DISABLE_SUBMODULE_AUTOUPDATE

      - name: Check out engine version
        run: |
          cd RobustToolbox
          git fetch origin ${{ github.sha }}
          git checkout FETCH_HEAD
          git submodule update --init --recursive
      - name: Replace global.json
        run: cp RobustToolbox/global.json .
      - name: Install dependencies
        run: dotnet restore
      - name: Build
        run: dotnet build --configuration DebugOpt --no-restore /m
      - name: Content.Tests
        shell: pwsh
        run: dotnet test --no-build --configuration DebugOpt Content.Tests/Content.Tests.csproj -- NUnit.ConsoleOut=0 NUnit.TestOutputXml="$(pwd)/test_results"
      - name: Content.IntegrationTests
        shell: pwsh
        run: |
          $env:DOTNET_gcServer=1
          dotnet test --no-build --configuration DebugOpt Content.IntegrationTests/Content.IntegrationTests.csproj -- NUnit.ConsoleOut=0 NUnit.MapWarningTo=Failed NUnit.TestOutputXml="logs" NUnit.WorkDirectory="$(pwd)/test_results"
      - name: Archive NUnit3 test results.
        if: always()
        uses: actions/upload-artifact@v4
        with:
          name: nunit3-results
          path: test_results/*
          retention-days: 7
