name: Validate

on:
  push:
    branches:
      - master
      - main
  pull_request:

permissions:
  contents: read

env:
  DOTNET_VERSION: 10.0.x
  SOLUTION_PATH: XFEExtension.NetCore.XUnit.slnx
  TEST_PROJECT: XFEExtension.NetCore.XUnit.Test/XFEExtension.NetCore.XUnit.Test.csproj

jobs:
  test:
    runs-on: windows-latest

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

      - name: Setup .NET
        uses: actions/setup-dotnet@v4
        with:
          dotnet-version: ${{ env.DOTNET_VERSION }}

      - name: Restore
        run: dotnet restore ${{ env.SOLUTION_PATH }}

      - name: Build
        run: dotnet build ${{ env.SOLUTION_PATH }} --configuration Release --no-restore -p:GeneratePackageOnBuild=false -p:ContinuousIntegrationBuild=true

      - name: Run self-tests
        run: dotnet run --project ${{ env.TEST_PROJECT }} --configuration Release --no-build -- --artifacts "${{ runner.temp }}/xfe-test-artifacts"

      - name: Run benchmark smoke test
        if: runner.os == 'Windows'
        run: dotnet run --project ${{ env.TEST_PROJECT }} --configuration Release --no-build -- --benchmarks --quick --artifacts "${{ runner.temp }}/xfe-benchmark-artifacts"

      - name: Upload reports
        if: always()
        uses: actions/upload-artifact@v4
        with:
          name: reports-${{ runner.os }}
          path: ${{ runner.temp }}/xfe-*-artifacts
          if-no-files-found: warn
