# ASP.NET Core (.NET Framework)
# Build and test ASP.NET Core projects targeting the full .NET Framework.
# Add steps that publish symbols, save build artifacts, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core

trigger:
 branches:
    include:
    - main
 paths:
    include:
    - futurenhs.fileserver/*

variables:
  solution: 'FutureNHS-WOPI-FileServer.sln'
  buildPlatform: 'x64'
  buildConfiguration: 'Release'
  working-dir: 'futurenhs.fileserver/FileServer'

jobs:

- job: BuildFutureNHSFileServer
  displayName: 'Build and publish artifact for FutureNHS Fileserver'
  pool :
    vmImage: 'windows-latest'

  steps:
   - task: UseDotNet@2
     displayName: 'Set dotnet SDK to v7.0'
     inputs:
      packageType: 'sdk'
      version: '7.x'
      
   - task: NuGetToolInstaller@1
     inputs:
      versionSpec: 
      checkLatest: true

   - task: NuGetCommand@2
     inputs:
      command: 'restore'
      restoreSolution: '$(Build.SourcesDirectory)/$(working-dir)/*.sln'
      feedsToUse: 'select'
   - task: DotNetCoreCLI@2 
     displayName: 'Build dotnet'
     inputs:
      command: 'build'
      projects: '$(Build.SourcesDirectory)/$(working-dir)/*.sln'
      configuration: 'Release'

    # Run all tests with "/p:CollectCoverage=true /p:CoverletOutputFormat=cobertura" to generate the code coverage file
  # - task: DotNetCoreCLI@2
  #   displayName: Test
  #   inputs:
  #    command: test
  #    configuration: 'Release'
  #    arguments: '--collect:"XPlat Code Coverage"'
  #    projects: '$(Build.SourcesDirectory)/$(working-dir)/wopi-host-tests/FutureNHS-WOPI-Host-UnitTests/FutureNHS-WOPI-Host-UnitTests.csproj'
  #    workingDirectory: '$(Build.SourcesDirectory)/$(working-dir)'
  #    nobuild: true

  # - script: |
  #     dotnet tool install --global dotnet-reportgenerator-globaltool --version 4.5.8
  #     reportgenerator -reports:$(Agent.TempDirectory)/**/coverage.cobertura.xml -targetdir:$(Build.SourcesDirectory)/coverlet/reports -reporttypes:"Cobertura"
  #   displayName: Create Code coverage report

    # Publish the code coverage result (summary and web site)
    # The summary allows to view the coverage percentage in the summary tab
    # The web site allows to view which lines are covered directly in Azure Pipeline
  # - task: PublishCodeCoverageResults@1
  #   displayName: 'Publish code coverage'
  #   inputs:
  #    codeCoverageTool: Cobertura
  #    summaryFileLocation: '$(Build.SourcesDirectory)/coverlet/reports/Cobertura.xml'
  #    failIfCoverageEmpty: false # Optional
      
   - task: DotNetCoreCLI@2
     displayName: 'Publish FutureNHS Api'
     inputs:
      command: 'publish'
      configuration: 'Release'
      publishWebProjects: false
      projects: '$(Build.SourcesDirectory)/$(working-dir)/*.csproj'
      zipAfterPublish: false

   - task: CopyFiles@2
     displayName: 'Copy files for artifact'
     inputs:
      SourceFolder: '$(Build.SourcesDirectory)/$(working-dir)/bin/Debug/net7.0/publish'
      Contents: '**'
      TargetFolder: '$(Build.ArtifactStagingDirectory)'

   - task: PublishPipelineArtifact@1
     displayName: 'Publish artifact'
     inputs:
      targetPath: '$(Build.ArtifactStagingDirectory)'
      artifact: 'FNHSFileServer'
      publishLocation: 'pipeline'

- job: BuildFutureNHSCollabora
  displayName: 'Build and publish artifact for FutureNHS Collabora'
  pool :
    vmImage: 'ubuntu-18.04'
  steps:  
   - task: CopyFiles@2
     displayName: 'Copy files for Collabora artifact'
     inputs:
      SourceFolder: '$(Build.SourcesDirectory)/futurenhs.fileserver/wopi-client/Azure'
      Contents: '**'
      TargetFolder: '$(Build.ArtifactStagingDirectory)/Collabora'

   - task: PublishPipelineArtifact@1
     displayName: 'Publish Collabora artifact'
     inputs:
      targetPath: '$(Build.ArtifactStagingDirectory)/Collabora'
      artifact: 'FNHSCollabora'
      publishLocation: 'pipeline'