# =============================================================================
# This pipeline (BotCore-CD) builds, tests, and packs the core/ project.
# PR trigger: next/* branches (all paths). CI trigger: next/* branches (core/** paths only).
# Pushes packages to internal preview feed on next/core branch.
# =============================================================================

pr:
  branches:
    include:
      - next/*
  paths:
    include:
      - core/**

trigger:
  branches:
    include:
    - next/*
  paths:
    include:
    - core/**

pool:
  vmImage: 'ubuntu-22.04'

stages:
- stage: Build_Test_Pack
  jobs:
  - job: BuildTestPack
    displayName: 'Build, Test, and Pack'
    steps:

      - task: UseDotNet@2
        displayName: 'Use .NET 8 SDK'
        inputs:
          packageType: 'sdk'
          version: '8.0.x'

      - task: UseDotNet@2
        displayName: 'Use .NET 10 SDK'
        inputs:
          packageType: 'sdk'
          version: '10.0.x'

      - script: dotnet restore 
        displayName: 'Restore'
        workingDirectory: '$(Build.SourcesDirectory)/core'

      - script: dotnet build --no-restore --configuration Release
        displayName: 'Build'
        workingDirectory: '$(Build.SourcesDirectory)/core'

      - script: dotnet test --no-build --configuration Release
        displayName: 'Test'
        workingDirectory: '$(Build.SourcesDirectory)/core'

      - script: dotnet pack --no-build -o $(Build.ArtifactStagingDirectory) /p:SymbolPackageFormat=snupkg --configuration Release
        displayName: 'Pack'
        workingDirectory: '$(Build.SourcesDirectory)/core'

      - task: NuGetCommand@2
        displayName: 'Push NuGet Packages'
        condition: eq(variables['PushToADOFeed'], true)
        inputs:
          command: push
          packagesToPush: '$(Build.ArtifactStagingDirectory)/*.nupkg'
          nuGetFeedType: internal
          publishVstsFeed: '$(System.TeamProject)/TeamsSDKPreviews'

      - task: PublishPipelineArtifact@1
        displayName: 'Publish NuGet Packages as Pipeline Artifact'
        inputs:
          targetPath: '$(Build.ArtifactStagingDirectory)'
          artifact: 'Packages'
          publishLocation: 'pipeline'