pool:
  vmImage: 'windows-2019'
  demands:
  - msbuild
  - visualstudio
  - vstest

steps:
- checkout: self
  submodules: true

- template: common-dotnet.yml@templates
- template: common-win.yml@templates

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

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

- task: PowerShell@2
  displayName: 'PreBuild Script'
  inputs:
    filePath: './devops/PreBuild.ps1'
    arguments: 'NLua NLua.nuspec'
    errorActionPreference: 'silentlyContinue'
    pwsh: true

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

- task: MSBuild@1
  displayName: 'Build .NET Core'
  inputs:
    solution: 'NLua.Core.sln'
    configuration: Release
    msbuildArguments: /restore

- task: DotNetCoreCLI@2
  displayName: 'dotnet vstest'
  inputs:
    command: custom
    custom: vstest
    arguments: '.\tests\build\netcore\bin\Release\netcoreapp3.1\NLuaTest.dll'

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

- task: VSTest@2
  displayName: 'VsTest - testAssemblies'
  inputs:
    testAssemblyVer2: '.\tests\build\net45\bin\Release\NLuaTest.dll'
    runSettingsFile: '.\tests\test.runsettings'
    platform: x64

- task: DownloadBuildArtifacts@0
  displayName: 'Download Build Xamarin.iOS'
  inputs:
    buildType: 'specific'
    project: 'NuGets'
    definition: 'NLua.Mac'
    specificBuildWithTriggering: true
    artifactName: Xamarin.iOS.NLua.dll

- task: DownloadBuildArtifacts@0
  displayName: 'Download Build Xamarin.Mac'
  inputs:
    buildType: 'specific'
    project: 'NuGets'
    definition: 'NLua.Mac'
    specificBuildWithTriggering: true
    artifactName: Xamarin.Mac.NLua.dll

- task: DownloadBuildArtifacts@0
  displayName: 'Download Build Xamarin.watchOS'
  inputs:
    buildType: 'specific'
    project: 'NuGets'
    definition: 'NLua.Mac'
    specificBuildWithTriggering: true
    artifactName: Xamarin.watchOS.NLua.dll

- task: DownloadBuildArtifacts@0
  displayName: 'Download Build Xamarin.tvOS'
  inputs:
    buildType: 'specific'
    project: 'NuGets'
    definition: 'NLua.Mac'
    specificBuildWithTriggering: true
    artifactName: Xamarin.tvOS.NLua.dll

- task: CopyFiles@2
  displayName: 'Copy Files to: lib/Release/xamarinios/'
  inputs:
    SourceFolder: '$(System.ArtifactsDirectory)\Xamarin.iOS.NLua.dll\'
    TargetFolder: lib/Release/xamarinios/

- task: CopyFiles@2
  displayName: 'Copy Files to: lib/Release/xamarinmac/'
  inputs:
    SourceFolder: '$(System.ArtifactsDirectory)\Xamarin.Mac.NLua.dll\'
    TargetFolder: lib/Release/xamarinmac/

- task: CopyFiles@2
  displayName: 'Copy Files to: lib/Release/xamarintvos/ '
  inputs:
    SourceFolder: '$(System.ArtifactsDirectory)\Xamarin.tvOS.NLua.dll\'
    TargetFolder: lib/Release/xamarintvos/

- task: CopyFiles@2
  displayName: 'Copy Files to: lib/Release/xamarinwatchos/'
  inputs:
    SourceFolder: '$(System.ArtifactsDirectory)\Xamarin.watchOS.NLua.dll\'
    TargetFolder: lib/Release/xamarinwatchos/

- script: 'nuget setapikey $(apikey)'
  displayName: 'Set NuGet API Key'

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

- script: 'rename *.nupkg NLua.nupkg'
  displayName: 'Rename Nuget Package'

- task: PublishBuildArtifacts@1
  displayName: 'Save NLua.nupkg Artifact'
  inputs:
    PathtoPublish: NLua.nupkg
    ArtifactName: NLua.nupkg

- task: PowerShell@2
  displayName: 'Publish NuGet'
  inputs:
    targetType: filePath
    filePath: ./devops/Publish.ps1
    arguments: NLua

- template: send-telegram.yml@templates
