environment:
  PSVersion: 5
  BuildConfiguration: Release
  DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true # For faster CI builds
  matrix:
  - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
    PowerShellEdition: PowerShellCore
  - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
    PowerShellEdition: WindowsPowerShell
  - APPVEYOR_BUILD_WORKER_IMAGE: WMF 4
    PowerShellEdition: WindowsPowerShell
    PSVersion: 4
  - APPVEYOR_BUILD_WORKER_IMAGE: Ubuntu
    PowerShellEdition: PowerShellCore

# cache Nuget packages and dotnet CLI cache
cache:
  - '%USERPROFILE%\.nuget\packages -> appveyor.yml'

install:
  - ps:   if ($env:PowerShellEdition -eq 'WindowsPowerShell') { Import-Module .\tools\appveyor.psm1; Invoke-AppveyorInstall }
  - pwsh: if ($env:PowerShellEdition -eq 'PowerShellCore')    { Import-Module .\tools\appveyor.psm1; Invoke-AppveyorInstall }

build_script:
  - ps:   |
      if ( $env:PowerShellEdition -eq 'WindowsPowerShell' ) {
          Set-Location $env:APPVEYOR_BUILD_FOLDER
          if ( $env:PSVersion -eq "4" ) { # On WMF4: Also build for v3 to check it builds at least since we do not have a WMF3 image
             ./build.ps1 -Configuration "$env:BuildConfiguration" -PSVersion 3
          }
          ./build.ps1 -Configuration "$env:BuildConfiguration" -PSVersion "$env:PSVersion"
          ./PSCompatibilityCollector/build.ps1 -Configuration "$env:BuildConfiguration" -Framework 'net452'
      }
  - pwsh: |
      if ($env:PowerShellEdition -eq 'PowerShellCore') {
          Set-Location $env:APPVEYOR_BUILD_FOLDER
          ./build.ps1 -Configuration "$env:BuildConfiguration" -PSVersion 6
          ./PSCompatibilityCollector/build.ps1 -Configuration "$env:BuildConfiguration" -Framework 'netstandard2.0'
      }

test_script:
  - ps:   |
      if ($env:PowerShellEdition -eq 'WindowsPowerShell') {
          Invoke-AppveyorTest -CheckoutPath $env:APPVEYOR_BUILD_FOLDER
      }
  - pwsh: |
      if ($env:PowerShellEdition -eq 'PowerShellCore') {
          Import-Module .\tools\appveyor.psm1 # Appveyor does not persist pwsh sessions like it does for ps
          Invoke-AppveyorTest -CheckoutPath $env:APPVEYOR_BUILD_FOLDER
      }

# Upload the project along with test results as a zip archive
on_finish:
  - ps: Import-Module "${env:APPVEYOR_BUILD_FOLDER}\tools\appveyor.psm1"; Invoke-AppveyorFinish
