
jobs:
- job: ComponentRegistrationJob
  variables:
    - name: runCodesignValidationInjection
      value: false
    - name: NugetSecurityAnalysisWarningLevel
      value: none
  displayName: Component Registration
  condition: succeeded()

  pool:
    name: PowerShell1ES
    demands:
    - ImageOverride -equals MMS2019

  steps:
  - checkout: self
    clean: true

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

  - powershell: |
       docker container prune --force
       docker container ls --all --format '{{ json .ID }}' | ConvertFrom-Json | ForEach-Object {docker container rm --force --volumes $_}
    displayName: 'Remove all containers'
    # Cleanup is not critical it passes every time it runs
    continueOnError: true

  - powershell: |
       docker image ls --format '{{ json .}}'|ConvertFrom-Json| ForEach-Object {
           if($_.tag -eq '<none>')
           {
               $formatString = 'yyyy-MM-dd HH:mm:ss zz00'
               $createdAtString = $_.CreatedAt.substring(0,$_.CreatedAt.Length -4)
               $createdAt = [DateTime]::ParseExact($createdAtString, $formatString,[System.Globalization.CultureInfo]::InvariantCulture)
               if($createdAt -lt (Get-Date).adddays(-1))
               {
                    docker image rm $_.ID
               }
           }
       }
       exit 0
    displayName: 'Remove old images'
    # Cleanup is not critical it passes every time it runs
    continueOnError: true

  - powershell: |
       Write-verbose "--docker info---" -verbose
       docker info
       Write-verbose "--docker image ls---" -verbose
       docker image ls
       Write-verbose "--docker container ls --all---" -verbose
       docker container ls --all
    displayName: 'Capture Docker Info'
    # Diagnostics is not critical it passes every time it runs
    continueOnError: true

  - template: insert-nuget-config-azfeed.yml

  - powershell: |
       ./tools/releaseBuild/vstsbuild.ps1 -ReleaseTag $(ReleaseTagVar) -Name win-x64-component-registration
    displayName: 'Build Windows Universal - Component Registration'

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