parameters:
  LinuxImage: 'ubuntu-latest'
  RestoreBuildProjects: 'Jellyfin.Server/Jellyfin.Server.csproj'
  DotNetSdkVersion: 7.0.x

jobs:
  - job: Build
    displayName: Build
    strategy:
      matrix:
        Release:
          BuildConfiguration: Release
        Debug:
          BuildConfiguration: Debug
    pool:
      vmImage: '${{ parameters.LinuxImage }}'
    steps:
      - checkout: self
        clean: true
        submodules: true
        persistCredentials: true

      - task: UseDotNet@2
        displayName: 'Update DotNet'
        inputs:
          packageType: sdk
          version: ${{ parameters.DotNetSdkVersion }}

      - task: DotNetCoreCLI@2
        displayName: 'Publish Server'
        inputs:
          command: publish
          publishWebProjects: false
          projects: '${{ parameters.RestoreBuildProjects }}'
          arguments: '--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)'
          zipAfterPublish: false

      - task: PublishPipelineArtifact@1
        displayName: 'Publish Artifact Naming'
        condition: and(succeeded(), eq(variables['BuildConfiguration'], 'Release'))
        inputs:
          targetPath: '$(build.ArtifactStagingDirectory)/Jellyfin.Server/Emby.Naming.dll'
          artifactName: 'Jellyfin.Naming'

      - task: PublishPipelineArtifact@1
        displayName: 'Publish Artifact Controller'
        condition: and(succeeded(), eq(variables['BuildConfiguration'], 'Release'))
        inputs:
          targetPath: '$(build.ArtifactStagingDirectory)/Jellyfin.Server/MediaBrowser.Controller.dll'
          artifactName: 'Jellyfin.Controller'

      - task: PublishPipelineArtifact@1
        displayName: 'Publish Artifact Model'
        condition: and(succeeded(), eq(variables['BuildConfiguration'], 'Release'))
        inputs:
          targetPath: '$(build.ArtifactStagingDirectory)/Jellyfin.Server/MediaBrowser.Model.dll'
          artifactName: 'Jellyfin.Model'

      - task: PublishPipelineArtifact@1
        displayName: 'Publish Artifact Common'
        condition: and(succeeded(), eq(variables['BuildConfiguration'], 'Release'))
        inputs:
          targetPath: '$(build.ArtifactStagingDirectory)/Jellyfin.Server/MediaBrowser.Common.dll'
          artifactName: 'Jellyfin.Common'

      - task: PublishPipelineArtifact@1
        displayName: 'Publish Artifact Extensions'
        condition: and(succeeded(), eq(variables['BuildConfiguration'], 'Release'))
        inputs:
          targetPath: '$(build.ArtifactStagingDirectory)/Jellyfin.Server/Jellyfin.Extensions.dll'
          artifactName: 'Jellyfin.Extensions'
