# This yml is used by these pipelines and triggers: 
# NOTE: the triggers are defined in the Azure DevOps UI as they are too complex
#
# - dotnet-source-build (public)
#   https://dev.azure.com/dnceng-public/public/_build?definitionId=240
#   - PR: ultralite build
#   - CI: release/* only, every batched commit, full build
#   - Schedule: main only, full build
#
# - dotnet-unified-build (public)
#   https://dev.azure.com/dnceng-public/public/_build?definitionId=278
#   - PR: lite build
#   - CI: release/* only, every batched commit, full build
#   - Schedule: main only, full build
#
# - dotnet-source-build (internal)
#   https://dev.azure.com/dnceng/internal/_build?definitionId=1219
#   - PR: ultralite build
#   - CI: release/* and internal/release/* only, every batched commit, full build
#   - Schedule: main only, full build
#
# - dotnet-source-build-lite (internal)
#   https://dev.azure.com/dnceng/internal/_build?definitionId=1299
#   - PR: release/* and main, lite build, on-demand trigger
#   - CI: main only, every batched commit, lite build
#
# - dotnet-unified-build (internal)
#   https://dev.azure.com/dnceng/internal/_build?definitionId=1330
#   - PR: lite build
#   - CI: release/*, internal/release/* and main, every batched commit, full build

variables:
# enable source-only build for pipelines that contain the -source-build string
- name: isSourceOnlyBuild
  value: ${{ contains(variables['Build.DefinitionName'], '-source-build') }}

- name: isSourceOnlyBuildLite
  value: ${{ contains(variables['Build.DefinitionName'], '-source-build-lite') }}

- name: isScheduleTrigger
  value: ${{ eq(variables['Build.Reason'], 'Schedule') }}

- name: isPRTrigger
  value: ${{ eq(variables['Build.Reason'], 'PullRequest') }}

- template: /eng/common/templates-official/variables/pool-providers.yml@self

resources:
  repositories:
  - repository: 1ESPipelineTemplates
    type: git
    name: 1ESPipelineTemplates/1ESPipelineTemplates
    ref: refs/tags/release

extends:
  template: v1/1ES.Official.PipelineTemplate.yml@1ESPipelineTemplates
  parameters:
    sdl:
      sourceAnalysisPool:
        name: $(DncEngInternalBuildPool)
        image: 1es-windows-2022
        os: windows

      codeql:
        compiled:
          enabled: true
        # Runs analysis in the SDL stage and not every job
        # https://eng.ms/docs/cloud-ai-platform/devdiv/one-engineering-system-1es/1es-docs/1es-pipeline-templates/features/sdlanalysis/codeql#improving-codeql-performance
        runSourceLanguagesInSourceAnalysis: true

      baseline:
        baselineFile: $(Build.SourcesDirectory)\.config\guardian\.gdnbaselines

    stages:
    - ${{ if and(ne(variables.isPRTrigger, 'true'), eq(variables['System.TeamProject'], 'internal')) }}:
      - template: /eng/pipelines/templates/stages/vmr-scan.yml@self

    - template: /src/installer/eng/pipelines/templates/stages/vmr-build.yml@self
      parameters:
        isBuiltFromVmr: true
        isSourceOnlyBuild: ${{ variables.isSourceOnlyBuild }}
        ${{ if eq(variables.isScheduleTrigger, 'true') }}:
          scope: full
        ${{ elseif eq(variables.isSourceOnlyBuildLite, 'true') }}:
          scope: lite
        ${{ elseif and(eq(variables.isPRTrigger, 'true'), eq(variables.isSourceOnlyBuild, 'true')) }}:
          scope: ultralite
        ${{ elseif and(eq(variables.isPRTrigger, 'true'), ne(variables.isSourceOnlyBuild, 'true')) }}:
          scope: lite
        ${{ else }}:
          scope: full
