name: Validate

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

permissions:
  contents: read

env:
  DOTNET_VERSION: 10.0.x
  SOLUTION_PATH: XFEExtension.slnx
  EXCLUDED_PROJECT_PATH: XFEExtension/XFEExtension.csproj

jobs:
  build:
    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: Prepare build solution
        shell: pwsh
        run: |
          [xml]$solution = Get-Content "${{ env.SOLUTION_PATH }}" -Raw
          $excludedProjectPath = "${{ env.EXCLUDED_PROJECT_PATH }}"
          $projects = @($solution.Solution.Project)

          foreach ($project in $projects) {
            if ($project.Path -eq $excludedProjectPath) {
              [void]$project.ParentNode.RemoveChild($project)
            }
          }

          $buildSolutionPath = Join-Path "${{ github.workspace }}" "build.filtered.slnx"
          $solution.Save($buildSolutionPath)
          "BUILD_SOLUTION_PATH=$buildSolutionPath" >> $env:GITHUB_ENV

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

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