name: PR-$(System.PullRequest.PullRequestNumber)-$(Date:yyyyMMdd)$(Rev:.rr)
trigger:
  # Batch merge builds together while a merge build is running
  batch: true
  branches:
    include:
    - master
    - release*
    - feature*
  paths:
    include:
    - /tools/install-powershell.sh
    - /tools/installpsh-amazonlinux.sh
    - /tools/installpsh-debian.sh
    - /tools/installpsh-osx.sh
    - /tools/installpsh-redhat.sh
    - /tools/installpsh-suse.sh
    - /tools/install-powershell.ps1
    - /.vsts-ci/install-ps.yml
pr:
  branches:
    include:
    - master
    - release*
    - feature*
  paths:
    include:
    - /tools/install-powershell.sh
    - /tools/installpsh-amazonlinux.sh
    - /tools/installpsh-debian.sh
    - /tools/installpsh-osx.sh
    - /tools/installpsh-redhat.sh
    - /tools/installpsh-suse.sh
    - /tools/install-powershell.ps1
    - /.vsts-ci/install-ps.yml

variables:
  DOTNET_CLI_TELEMETRY_OPTOUT: 1
  POWERSHELL_TELEMETRY_OPTOUT: 1

resources:
- repo: self
  clean: true
phases:
- template: templates/install-ps-phase.yml
  parameters:
    scriptName: sudo ./tools/install-powershell.sh
    jobName: InstallPowerShellUbuntu
    pool: Hosted Ubuntu 1604
    verification: |
      if ([Version]"$($PSVersionTable.PSVersion.Major).$($PSVersionTable.PSVersion.Minor).$($PSVersionTable.PSVersion.Patch)" -lt [version]"6.2.0")
      {
        throw "powershell was not upgraded: $($PSVersionTable.PSVersion)"
      }

- template: templates/install-ps-phase.yml
  parameters:
    scriptName: sudo ./tools/install-powershell.sh
    jobName: InstallPowerShellAmazonLinux
    pool: Hosted Ubuntu 1604
    container: pshorg/powershellcommunity-test-deps:amazonlinux-2.0
    verification: |
      if ([Version]"$($PSVersionTable.PSVersion.Major).$($PSVersionTable.PSVersion.Minor).$($PSVersionTable.PSVersion.Patch)" -lt [version]"6.2.0")
      {
        throw "powershell was not upgraded: $($PSVersionTable.PSVersion)"
      }

- template: templates/install-ps-phase.yml
  parameters:
    scriptName: sudo ./tools/installpsh-amazonlinux.sh
    jobName: InstallPSHAmazonLinux
    pool: Hosted Ubuntu 1604
    container: pshorg/powershellcommunity-test-deps:amazonlinux-2.0
    verification: |
      if ([Version]"$($PSVersionTable.PSVersion.Major).$($PSVersionTable.PSVersion.Minor).$($PSVersionTable.PSVersion.Patch)" -lt [version]"6.2.0")
      {
        throw "powershell was not upgraded: $($PSVersionTable.PSVersion)"
      }
    continueOnError: false

# TODO: add sudo to script and use image with sudo
- template: templates/install-ps-phase.yml
  parameters:
    scriptName: ./tools/install-powershell.sh
    jobName: InstallPowerShellCentOS
    pool: Hosted Ubuntu 1604
    container: mcr.microsoft.com/powershell/test-deps:centos-7
    
- template: templates/install-ps-phase.yml
  parameters:
    scriptName: ./tools/install-powershell.sh
    jobName: InstallPowerShellDebian9
    pool: Hosted Ubuntu 1604
    container: mcr.microsoft.com/powershell/test-deps:debian-9


# VSTS could not find pwsh in:
# mcr.microsoft.com/powershell:opensuse-42.3
# could not repo locally

# sudo is not needed on macOS
- template: templates/install-ps-phase.yml
  parameters:
    scriptName: ./tools/install-powershell.sh
    jobName: InstallPowerShellMacOS
    pool: Hosted macOS
    verification: |
      if ([Version]"$($PSVersionTable.PSVersion.Major).$($PSVersionTable.PSVersion.Minor).$($PSVersionTable.PSVersion.Patch)" -lt [version]"6.2.0")
      {
        # The script does not upgrade on  mac os https://github.com/PowerShell/PowerShell/issues/9322
        Write-Warning "powershell was not upgraded: $($PSVersionTable.PSVersion)"
      }

- template: templates/install-ps-phase.yml
  parameters:
    scriptName: pwsh -c ./tools/install-powershell.ps1 -AddToPath
    jobName: InstallPowerShellPS1Ubuntu
    pool: Hosted Ubuntu 1604
