name: Continuous Integration - Windows

on: [push, pull_request]

jobs:
  build:
    name: "Visual Studio ${{ matrix.platform }} ${{ matrix.configuration }}"
    runs-on: windows-latest
    strategy:
      fail-fast: false
      matrix:
        configuration: [Release, Debug]
        platform: [x64, x86]

    steps:
    - uses: actions/checkout@v1

    - name: Build
      run: |
        $vswhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
        $msbuild = & "$vswhere" -latest -requires Microsoft.Component.MSBuild -find MSBuild\**\Bin\MSBuild.exe | select-object -first 1
        $options = @( `
          '-property:Configuration=${{ matrix.configuration }}', `
          '-property:Platform=${{ matrix.platform }}', `
          '-maxcpucount', `
          '-verbosity:minimal' `
        )
        & $msbuild Builder.sln $options
        if (-not $?) { throw "Build failed" }
        & $msbuild Source\Tools\Updater\Updater.csproj $options
        if (-not $?) { throw "Build failed" }

    - name: Test Files Presence
      run: |
        $files = @( `
          'Build\Builder.exe', `
          'Build\BuilderNative.dll', `
          'Build\Plugins\AutomapMode.dll', `
          'Build\Plugins\BuilderEffects.dll', `
          'Build\Plugins\BuilderModes.dll', `
          'Build\Plugins\ColorPicker.dll', `
          'Build\Plugins\CommentsPanel.dll', `
          'Build\Plugins\NodesViewer.dll', `
          'Build\Plugins\SoundPropagationMode.dll', `
          'Build\Plugins\StairSectorBuilder.dll', `
          'Build\Plugins\TagExplorer.dll', `
          'Build\Plugins\TagRange.dll', `
          'Build\Plugins\ThreeDFloorMode.dll', `
          'Build\Plugins\VisplaneExplorer.dll', `
          'Build\Updater.exe' `
        )
        foreach($file in $files)
        {
          if (!(Test-Path -Path $file -PathType Leaf))
          {
            Write-Output "ERROR: File $file is missing"
            exit 1
          }
        }

    - name: Prepare Package
      run: |
        # Delete unwanted files
        Remove-Item Build\Setup -recurse

    - name: Upload Package
      uses: actions/upload-artifact@v1
      with:
        path: Build
        name: "vs_${{ matrix.platform }}_${{ matrix.configuration }}"
