parameters:
  - name: BuildConfiguration
    default: release
  - name: BuildPlatform
    default: any cpu
  - name: Architecture
    default: x64
  - name: parentJob
    default: ''

jobs:
- job: build_windows_${{ parameters.Architecture }}_${{ parameters.BuildConfiguration }}
  displayName: Build Windows - ${{ parameters.Architecture }} ${{ parameters.BuildConfiguration }}
  condition: succeeded()
  dependsOn: ${{ parameters.parentJob }}
  pool:
    vmImage: windows-latest
  variables:
    - name: runCodesignValidationInjection
      value: false
    - name: NugetSecurityAnalysisWarningLevel
      value: none
    - name: BuildConfiguration
      value: ${{ parameters.BuildConfiguration }}
    - name: BuildPlatform
      value: ${{ parameters.BuildPlatform }}
    - name: Architecture
      value: ${{ parameters.Architecture }}
    - name: DOTNET_SKIP_FIRST_TIME_EXPERIENCE
      value: 1

  steps:

  - checkout: self
    clean: true

  - template: SetVersionVariables.yml
    parameters:
      ReleaseTagVar: $(ReleaseTagVar)

  - template: cloneToOfficialPath.yml

  - template: /tools/releaseBuild/azureDevOps/templates/insert-nuget-config-azfeed.yml
    parameters:
      repoRoot: $(PowerShellRoot)

  - powershell: |

      $runtime = switch ($env:Architecture)
        {
          "x64" { "win7-x64" }
          "x86" { "win7-x86" }
          "arm" { "win-arm"}
          "arm64" { "win-arm64" }
          "fxdependent" { "fxdependent" }
          "fxdependentWinDesktop" { "fxdependent-win-desktop" }
        }

      $params = @{}
      if ($env:BuildConfiguration -eq 'minSize') {
        $params['ForMinimalSize'] = $true
      }

      tools/releaseBuild/Images/microsoft_powershell_windowsservercore/PowerShellPackage.ps1 -location '$(PowerShellRoot)' -destination '$(Build.ArtifactStagingDirectory)/Symbols_$(Architecture)' -Runtime $runtime -ReleaseTag '$(ReleaseTagVar)' -Symbols @params
    displayName: 'Build Windows Universal - $(Architecture)-$(BuildConfiguration) Symbols zip'

  - powershell: |
      $packageName = (Get-ChildItem '$(Build.ArtifactStagingDirectory)\Symbols_$(Architecture)').FullName
      $vstsCommandString = "vso[artifact.upload containerfolder=results;artifactname=results]$packageName"
      Write-Host ("sending " + $vstsCommandString)
      Write-Host "##$vstsCommandString"
    displayName: Upload symbols package

  - task: ms.vss-governance-buildtask.governance-build-task-component-detection.ComponentGovernanceComponentDetection@0
    displayName: 'Component Detection'
    inputs:
      sourceScanPath: '$(Build.SourcesDirectory)'
      snapshotForceEnabled: true
