pool:
  name: Hosted macOS
  demands: msbuild

steps:

# Azure DevOps hosted pool is still using an old version of Xamarin.iOS, 
# so we will use the previous major version of Xcode
- task: CmdLine@2
  displayName: 'Provisioning Xamarin.iOS'
  inputs:
    script: 'cd ~;
            curl -O https://download.visualstudio.microsoft.com/download/pr/87a0582e-09b0-499a-852a-6d963e614afb/b101ede139bd8ad0a5d4c2f0077c3ca4/xamarin.ios-12.14.0.110.pkg;
            sudo installer -pkg ~/xamarin.ios-12.14.0.110.pkg -target /'

# Print the current version of Xamarin.iOS
- task: CmdLine@2
  displayName: 'Show Xamarin.iOS Version'
  inputs:
    script: '/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/bin/mtouch --version'

- task: NuGetCommand@2
  displayName: 'NuGet restore'
  inputs:
    restoreSolution: NLua.sln

- task: NuGetCommand@2
  displayName: 'NuGet restore'
  inputs:
    restoreSolution: NLua.Mac.sln

- script: 'brew update'
  displayName: 'Brew Update'

- script: 'brew install gitversion --ignore-dependencies'
  displayName: 'Install GitVersion'

- task: PowerShell@2
  displayName: 'PowerShell Script'
  inputs:
    targetType: filePath
    filePath: ./devops/PreBuild.ps1
    arguments: 'NLua NLua.nuspec'

- task: MSBuild@1
  displayName: 'Build solution NLua.sln'
  inputs:
    solution: NLua.sln
    configuration: Release

- task: MSBuild@1
  displayName: 'Build solution NLua.Mac.sln'
  inputs:
    solution: NLua.Mac.sln
    configuration: Release

- script: 'mono packages/NUnit.ConsoleRunner.3.10.0/tools/nunit3-console.exe ./tests/build/net45/bin/Release/NLuaTest.dll --result=TEST-Result-Mac.xml'
  displayName: 'Run OSX tests'

- task: PublishTestResults@2
  displayName: 'Publish Mac Test Results TEST-Result-Mac.xml'
  inputs:
    testResultsFormat: NUnit
    testResultsFiles: 'TEST-Result-Mac.xml'

- task: MSBuild@1
  displayName: 'Run iOS tests'
  inputs:
    solution: tests/build/xamarinios/NLuaTest.XamariniOS.csproj
    platform: iPhoneSimulator
    configuration: Release
    msbuildArguments: '/t:RunSimulatorTests'

- task: PublishTestResults@2
  displayName: 'Publish iOS Test Results TEST-Result-iOS.xml'
  inputs:
    testResultsFormat: NUnit
    testResultsFiles: 'tests/build/xamarinios/TEST-Result-Xamarin.iOS.xml'

- task: MSBuild@1
  displayName: 'Run tvOS tests'
  inputs:
    solution: tests/build/xamarintvos/NLuaTest.XamarinTVOS.csproj
    platform: iPhoneSimulator
    configuration: Release
    msbuildArguments: '/t:RunSimulatorTests'

- task: PublishTestResults@2
  displayName: 'Publish tvOS Test Results TEST-Result-tvOS.xml'
  inputs:
    testResultsFormat: NUnit
    testResultsFiles: 'tests/build/xamarintvos/TEST-Result-Xamarin.TVOS.xml'

- task: PublishBuildArtifacts@1
  displayName: 'Publish Artifact: Xamarin.iOS.NLua.dll'
  inputs:
    PathtoPublish: lib/Release/xamarinios/NLua.dll
    ArtifactName: Xamarin.iOS.NLua.dll

- task: PublishBuildArtifacts@1
  displayName: 'Publish Artifact: Xamarin.tvOS.NLua.dll'
  inputs:
    PathtoPublish: lib/Release/xamarintvos/NLua.dll
    ArtifactName: Xamarin.tvOS.NLua.dll

- task: PublishBuildArtifacts@1
  displayName: 'Publish Artifact: Xamarin.watchOS.NLua.dll'
  inputs:
    PathtoPublish: lib/Release/xamarinwatchos/NLua.dll
    ArtifactName: Xamarin.watchOS.NLua.dll

- task: PublishBuildArtifacts@1
  displayName: 'Publish Artifact: Xamarin.Mac.NLua.dll'
  inputs:
    PathtoPublish: lib/Release/xamarinmac/NLua.dll
    ArtifactName: Xamarin.Mac.NLua.dll

- task: TriggerBuild@3
  displayName: 'Trigger a new build of NLua.Windows'
  inputs:
    buildDefinition: 'NLua.Windows'
    ignoreSslCertificateErrors: true
    useSameSourceVersion: true
    password: '$(myToken)'

- task: SendTelegramNotification@0
  condition: in(variables['Agent.JobStatus'], 'SucceededWithIssues')
  inputs:
    botToken: '$(botToken)'
    chats: '$(chatId)'
    taskStatus: false
    message: |
            ⚠️ <b>Warning!</b>  <a href="$(Build.Repository.Uri)">$(Build.DefinitionName)</a> (<code>$(Build.SourceBranchName)</code>)
            <pre>$(Build.SourceVersion)</pre>
            $(Build.SourceVersionMessage) by $(Build.QueuedBy)

- task: SendTelegramNotification@0
  condition: in(variables['Agent.JobStatus'], 'Failed')
  inputs:
    botToken: '$(botToken)'
    chats: '$(chatId)'
    taskStatus: false
    buildQueuedBy: false
    message: |
            ❌ <b>Fail!</b>  <a href="$(Build.Repository.Uri)">$(Build.DefinitionName)</a> (<code>$(Build.SourceBranchName)</code>)
            <pre>$(Build.SourceVersion)</pre>
            $(Build.SourceVersionMessage) by $(Build.QueuedBy)

- task: SendTelegramNotification@0
  condition: in(variables['Agent.JobStatus'], 'Succeeded')
  inputs:
    botToken: '$(botToken)'
    chats: '$(chatId)'
    taskStatus: false
    buildQueuedBy: false
    message: |
            ✅ <b>Success!</b>  <a href="$(Build.Repository.Uri)">$(Build.DefinitionName)</a> (<code>$(Build.SourceBranchName)</code>)
            <pre>$(Build.SourceVersion)</pre>
            $(Build.SourceVersionMessage) by $(Build.QueuedBy)

# 