# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml

name: $(Year:yyyy).$(Month).$(DayOfMonth)$(Rev:.r)$(postfix)$(branchName) # NOTE: rev resets when the default retention period expires

trigger:
  branches:
    include:
    - '*'

pool:
  vmImage: ubuntu-latest # ubuntu-latest - set to windows-latest or another Windows vmImage for Windows builds

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'  

  ${{ if eq(variables['Build.SourceBranchName'], 'master') }}:
    branchName: ''
  ${{ elseif startsWith(variables['Build.SourceBranch'], 'refs/heads/') }}:
    branchName: $[ replace(replace(variables['Build.SourceBranch'], 'refs/heads/', ''), '/', '-' ) ]
  ${{ elseif startsWith(variables['Build.SourceBranch'], 'refs/pull/') }}:
    branchName: $[ replace(replace(variables['System.PullRequest.TargetBranch'], 'refs/heads/', ''), '/', '-' ) ]

  ${{ if eq(variables['branchName'], '') }}:
    postfix: ''
  ${{ else }}:
    postfix: '-'

steps:
- task: UseDotNet@2
  displayName: 'Set .net core version'
  inputs:
    version: '9.0.x'
   
- task: DotNetCoreCLI@2
  displayName: 'Nuget Restore'
  inputs:
    command: 'restore'
    feedsToUse: config
    projects: '**/*.csproj'
    nugetConfigPath: nuget.config

- task: DotNetCoreCLI@2
  inputs:
    command: 'build'
    arguments: '--configuration $(buildConfiguration)'
  displayName: 'dotnet build $(buildConfiguration)'

#Not going to run the tests in the build pipeline, they will be publishes as an artifact, then executed as part of the release pipeline.
# - task: DotNetCoreCLI@2
#   displayName: 'Run Tests'
#   continueOnError: true
#   inputs:
#     command: test
#     projects: '**/*/*.csproj'
#     arguments: '--configuration $(buildConfiguration)'

#  task: SpecFlowPlus@0
#   continueOnError: true
#   inputs:
#     generatorSource: 'TestAssembly'
#     testAssemblyFilePath: '**/bin/**/ESuite.UI.E2E.dll'
#     projectName: 'E-suite'
#     testExecutionJson: '**/TestExecution.json'
#     projectLanguage: 'en'
#     workItemUrlTemplate: 'https://sunbranding.visualstudio.com/e-suite/_workitems/edit/{id}'

- task: DotNetCoreCLI@2
  displayName: 'Publish ESuite.UI.E2E'
  inputs:
    command: publish
    projects: '**/*.csproj'
    publishWebProjects: false
    arguments: '--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)'
    zipAfterPublish: false

- task: PublishPipelineArtifact@1
  displayName: 'Publish'
  inputs:
    targetPath: $(Build.ArtifactStagingDirectory)
    artifactName: 'build'
    artifactType: 'pipeline'