trigger:
  branches:
    include:
    - main
    - release/*
    - loc
  tags:
    include:
    - '*'
  paths:
    include:
    - '*'
    exclude:
    - .github/*
    - docs/*
    - src/Templates/*
    - CODE-OF-CONDUCT.md
    - CONTRIBUTING.md
    - LICENSE.TXT
    - PATENTS.TXT
    - README.md
    - SECURITY.md
    - THIRD-PARTY-NOTICES.TXT

pr:
  branches:
    include:
    - main
    - release/*
  paths:
    include:
    - '*'
    exclude:
    - .github/*
    - docs/*
    - src/Templates/*
    - CODE-OF-CONDUCT.md
    - CONTRIBUTING.md
    - LICENSE.TXT
    - PATENTS.TXT
    - README.md
    - SECURITY.md
    - THIRD-PARTY-NOTICES.TXT

variables:
  - template: /eng/pipelines/common/variables.yml
  - name: AgentPoolAccessToken
    value: $(botdeploy--azdo--token)

parameters:
  - name: provisionatorChannel
    displayName: 'Provisionator channel'
    type: string
    default: 'latest'           # Support for launching a build against a Provisionator PR (e.g., pr/[github-account-name]/[pr-number]) as a means to test in-progress Provisionator changes

  - name: BuildEverything
    type: boolean
    default: false

  - name: androidPool
    type: object
    default:
      name: $(androidTestsVmPool)
      vmImage: $(androidTestsVmImage)
      demands:
        - macOS.Name -equals Ventura
        - macOS.Architecture -equals x64

  - name: iosPool
    type: object
    default:
      name: $(iosTestsVmPool)
      vmImage: $(iosTestsVmImage)
      demands:
        - macOS.Name -equals Ventura
        - macOS.Architecture -equals x64
        - Agent.OSVersion -equals 13.5

  - name: catalystPool
    type: object
    default:
      name: $(macosTestsVmPool)
      vmImage: $(macosTestsVmImage)

  - name: windowsPool
    type: object
    default:
      name: $(windowsTestsVmPool)
      vmImage: $(windowsTestsVmImage)

resources:
  repositories:
    - repository: yaml-templates
      type: github
      name: xamarin/yaml-templates
      endpoint: xamarin
      ref: refs/heads/main

stages:

  - template: common/device-tests.yml
    parameters:
      androidPool: ${{ parameters.androidPool }}
      iosPool: ${{ parameters.iosPool }}
      catalystPool: ${{ parameters.catalystPool }}
      windowsPool: ${{ parameters.windowsPool }}
      agentPoolAccessToken: $(AgentPoolAccessToken)
      ${{ if or(parameters.BuildEverything, and(ne(variables['Build.Reason'], 'PullRequest'), eq(variables['System.TeamProject'], 'devdiv'))) }}:
        androidApiLevels: [ 33, 30, 29, 28, 27, 26, 25, 24, 23 ]
        iosVersions: [ 'simulator-16.4','simulator-15.5' ]
        catalystVersions: [ 'latest' ]
        windowsVersions: ['packaged', 'unpackaged']
        provisionatorChannel: ${{ parameters.provisionatorChannel }}
      ${{ if not(or(parameters.BuildEverything, and(ne(variables['Build.Reason'], 'PullRequest'), eq(variables['System.TeamProject'], 'devdiv')))) }}:
        androidApiLevels: [ 30, 23 ]
        iosVersions: [ 'simulator-16.4' ]
        catalystVersions: [ 'latest' ]
        windowsVersions: ['packaged', 'unpackaged']
        provisionatorChannel: ${{ parameters.provisionatorChannel }}
      projects:
        - name: essentials
          desc: Essentials
          androidApiLevelsExclude: [25] # Ignore for now API25 since the runs's are not stable
          windowsPackageId: 'com.microsoft.maui.essentials.devicetests'
          android: $(System.DefaultWorkingDirectory)/src/Essentials/test/DeviceTests/Essentials.DeviceTests.csproj
          ios: $(System.DefaultWorkingDirectory)/src/Essentials/test/DeviceTests/Essentials.DeviceTests.csproj
          catalyst: $(System.DefaultWorkingDirectory)/src/Essentials/test/DeviceTests/Essentials.DeviceTests.csproj
          windows: $(System.DefaultWorkingDirectory)/src/Essentials/test/DeviceTests/Essentials.DeviceTests.csproj
        - name: graphics
          desc: Graphics
          androidApiLevelsExclude: [25] # Ignore for now API25 since the runs's are not stable
          windowsPackageId: 'com.microsoft.maui.graphics.devicetests'
          android: $(System.DefaultWorkingDirectory)/src/Graphics/tests/DeviceTests/Graphics.DeviceTests.csproj
          ios: $(System.DefaultWorkingDirectory)/src/Graphics/tests/DeviceTests/Graphics.DeviceTests.csproj
          catalyst: $(System.DefaultWorkingDirectory)/src/Graphics/tests/DeviceTests/Graphics.DeviceTests.csproj
          windows: $(System.DefaultWorkingDirectory)/src/Graphics/tests/DeviceTests/Graphics.DeviceTests.csproj
        - name: core
          desc: Core
          androidApiLevelsExclude: [25] # Ignore for now API25 since the runs's are not stable
          windowsPackageId: 'com.microsoft.maui.core.devicetests'
          android: $(System.DefaultWorkingDirectory)/src/Core/tests/DeviceTests/Core.DeviceTests.csproj
          ios: $(System.DefaultWorkingDirectory)/src/Core/tests/DeviceTests/Core.DeviceTests.csproj
          catalyst: $(System.DefaultWorkingDirectory)/src/Core/tests/DeviceTests/Core.DeviceTests.csproj
          windows: $(System.DefaultWorkingDirectory)/src/Core/tests/DeviceTests/Core.DeviceTests.csproj
        - name: controls
          desc: Controls
          androidApiLevelsExclude: [27, 25] # Ignore for now API25 since the runs's are not stable
          windowsPackageId: 'com.microsoft.maui.controls.devicetests'
          android: $(System.DefaultWorkingDirectory)/src/Controls/tests/DeviceTests/Controls.DeviceTests.csproj
          ios: $(System.DefaultWorkingDirectory)/src/Controls/tests/DeviceTests/Controls.DeviceTests.csproj
          catalyst: $(System.DefaultWorkingDirectory)/src/Controls/tests/DeviceTests/Controls.DeviceTests.csproj
          windows: $(System.DefaultWorkingDirectory)/src/Controls/tests/DeviceTests/Controls.DeviceTests.csproj
        - name: blazorwebview
          desc: BlazorWebView
          androidApiLevelsExclude: [ 27, 26, 25, 24, 23, 22, 21 ] # BlazorWebView requires a recent version of Chrome
          windowsPackageId: 'Microsoft.Maui.MauiBlazorWebView.DeviceTests'
          android: $(System.DefaultWorkingDirectory)/src/BlazorWebView/tests/MauiDeviceTests/MauiBlazorWebView.DeviceTests.csproj
          ios: $(System.DefaultWorkingDirectory)/src/BlazorWebView/tests/MauiDeviceTests/MauiBlazorWebView.DeviceTests.csproj
          catalyst: $(System.DefaultWorkingDirectory)/src/BlazorWebView/tests/MauiDeviceTests/MauiBlazorWebView.DeviceTests.csproj
          windows: $(System.DefaultWorkingDirectory)/src/BlazorWebView/tests/MauiDeviceTests/MauiBlazorWebView.DeviceTests.csproj

