parameters:
  - name: VSCODE_ARCH
    type: string
  - name: VSCODE_CIBUILD
    type: boolean
  - name: VSCODE_QUALITY
    type: string
  - name: VSCODE_RUN_ELECTRON_TESTS
    type: boolean
    default: false
  - name: VSCODE_RUN_BROWSER_TESTS
    type: boolean
    default: false
  - name: VSCODE_RUN_REMOTE_TESTS
    type: boolean
    default: false

jobs:
  - job: Windows_${{ parameters.VSCODE_ARCH }}
    displayName: Windows (${{ upper(parameters.VSCODE_ARCH) }})
    timeoutInMinutes: 90
    variables:
      VSCODE_ARCH: ${{ parameters.VSCODE_ARCH }}
      BUILDS_API_URL: $(System.CollectionUri)$(System.TeamProject)/_apis/build/builds/$(Build.BuildId)/
    templateContext:
      outputParentDirectory: $(Build.ArtifactStagingDirectory)/out
      outputs:
        - ${{ if or(eq(parameters.VSCODE_RUN_ELECTRON_TESTS, true), eq(parameters.VSCODE_RUN_BROWSER_TESTS, true), eq(parameters.VSCODE_RUN_REMOTE_TESTS, true)) }}:
          - output: pipelineArtifact
            targetPath: $(Build.SourcesDirectory)/.build/crashes
            artifactName: crash-dump-windows-$(VSCODE_ARCH)-$(System.JobAttempt)
            displayName: Publish Crash Reports
            sbomEnabled: false
            isProduction: false
            condition: failed()
          - output: pipelineArtifact
            targetPath: $(Build.SourcesDirectory)/node_modules
            artifactName: node-modules-windows-$(VSCODE_ARCH)-$(System.JobAttempt)
            displayName: Publish Node Modules
            sbomEnabled: false
            isProduction: false
            condition: failed()
          - output: pipelineArtifact
            targetPath: $(Build.SourcesDirectory)/.build/logs
            artifactName: logs-windows-$(VSCODE_ARCH)-$(System.JobAttempt)
            displayName: Publish Log Files
            sbomEnabled: false
            isProduction: false
            condition: succeededOrFailed()
        - output: pipelineArtifact
          targetPath: $(Build.ArtifactStagingDirectory)/out/system-setup/VSCodeSetup-$(VSCODE_ARCH)-$(VSCODE_VERSION).exe
          artifactName: vscode_client_win32_$(VSCODE_ARCH)_setup
          displayName: Publish system setup
          sbomBuildDropPath: $(Agent.BuildDirectory)/VSCode-win32-$(VSCODE_ARCH)
          sbomPackageName: "VS Code Windows $(VSCODE_ARCH) System Setup"
          sbomPackageVersion: $(Build.SourceVersion)
        - output: pipelineArtifact
          targetPath: $(Build.ArtifactStagingDirectory)/out/user-setup/VSCodeUserSetup-$(VSCODE_ARCH)-$(VSCODE_VERSION).exe
          artifactName: vscode_client_win32_$(VSCODE_ARCH)_user-setup
          displayName: Publish user setup
          sbomBuildDropPath: $(Agent.BuildDirectory)/VSCode-win32-$(VSCODE_ARCH)
          sbomPackageName: "VS Code Windows $(VSCODE_ARCH) User Setup"
          sbomPackageVersion: $(Build.SourceVersion)
        - output: pipelineArtifact
          targetPath: $(Build.ArtifactStagingDirectory)/out/archive/VSCode-win32-$(VSCODE_ARCH)-$(VSCODE_VERSION).zip
          artifactName: vscode_client_win32_$(VSCODE_ARCH)_archive
          displayName: Publish archive
          sbomBuildDropPath: $(Agent.BuildDirectory)/VSCode-win32-$(VSCODE_ARCH)
          sbomPackageName: "VS Code Windows $(VSCODE_ARCH)"
          sbomPackageVersion: $(Build.SourceVersion)
        - output: pipelineArtifact
          targetPath: $(Build.ArtifactStagingDirectory)/out/server/vscode-server-win32-$(VSCODE_ARCH).zip
          artifactName: vscode_server_win32_$(VSCODE_ARCH)_archive
          displayName: Publish server archive
          sbomBuildDropPath: $(Agent.BuildDirectory)/vscode-server-win32-$(VSCODE_ARCH)
          sbomPackageName: "VS Code Windows $(VSCODE_ARCH) Server"
          sbomPackageVersion: $(Build.SourceVersion)
        - output: pipelineArtifact
          targetPath: $(Build.ArtifactStagingDirectory)/out/web/vscode-server-win32-$(VSCODE_ARCH)-web.zip
          artifactName: vscode_web_win32_$(VSCODE_ARCH)_archive
          displayName: Publish web server archive
          sbomBuildDropPath: $(Agent.BuildDirectory)/vscode-server-win32-$(VSCODE_ARCH)-web
          sbomPackageName: "VS Code Windows $(VSCODE_ARCH) Web"
          sbomPackageVersion: $(Build.SourceVersion)
      sdl:
        suppression:
          suppressionFile: $(Build.SourcesDirectory)\.config\guardian\.gdnsuppress
    steps:
      - template: ./steps/product-build-win32-compile.yml@self
        parameters:
          VSCODE_ARCH: ${{ parameters.VSCODE_ARCH }}
          VSCODE_CIBUILD: ${{ parameters.VSCODE_CIBUILD }}
          VSCODE_QUALITY: ${{ parameters.VSCODE_QUALITY }}
          VSCODE_RUN_ELECTRON_TESTS: ${{ parameters.VSCODE_RUN_ELECTRON_TESTS }}
          VSCODE_RUN_BROWSER_TESTS: ${{ parameters.VSCODE_RUN_BROWSER_TESTS }}
          VSCODE_RUN_REMOTE_TESTS: ${{ parameters.VSCODE_RUN_REMOTE_TESTS }}
