parameters:
  - name: NPM_ARCH
    type: string
  - name: VSCODE_ARCH
    type: string
  - name: VSCODE_CIBUILD
    type: boolean
  - name: VSCODE_QUALITY
    type: string
  - name: VSCODE_BUILD_LINUX_SNAP
    type: boolean
    default: false
  - 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
  - name: VSCODE_RUN_CHECKS
    type: boolean
    default: false

jobs:
  - job: Linux_${{ parameters.VSCODE_ARCH }}
    displayName: Linux (${{ upper(parameters.VSCODE_ARCH) }})
    timeoutInMinutes: 90
    variables:
      DISPLAY: ":10"
      BUILDS_API_URL: $(System.CollectionUri)$(System.TeamProject)/_apis/build/builds/$(Build.BuildId)/
      NPM_ARCH: ${{ parameters.NPM_ARCH }}
      VSCODE_ARCH: ${{ parameters.VSCODE_ARCH }}
    templateContext:
      sdl:
        binskim:
          analyzeTargetGlob: '$(Agent.BuildDirectory)/VSCode-linux-$(VSCODE_ARCH)/**/*.node;$(Agent.BuildDirectory)/vscode-server-linux-$(VSCODE_ARCH)/**/*.node;$(Agent.BuildDirectory)/vscode-server-linux-$(VSCODE_ARCH)-web/**/*.node'
          preReleaseVersion: '4.3.1'
      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-linux-$(VSCODE_ARCH)-$(System.JobAttempt)
            displayName: Publish Crash Reports
            sbomEnabled: false
            isProduction: false
            condition: failed()
          - output: pipelineArtifact
            targetPath: $(Build.SourcesDirectory)/node_modules
            artifactName: node-modules-linux-$(VSCODE_ARCH)-$(System.JobAttempt)
            displayName: Publish Node Modules
            sbomEnabled: false
            isProduction: false
            condition: failed()
          - output: pipelineArtifact
            targetPath: $(Build.SourcesDirectory)/.build/logs
            artifactName: logs-linux-$(VSCODE_ARCH)-$(System.JobAttempt)
            displayName: Publish Log Files
            sbomEnabled: false
            isProduction: false
            condition: succeededOrFailed()
        - output: pipelineArtifact
          targetPath: $(Build.ArtifactStagingDirectory)/out/client/$(CLIENT_ARCHIVE_NAME)
          artifactName: vscode_client_linux_$(VSCODE_ARCH)_archive-unsigned
          displayName: Publish client archive
          sbomBuildDropPath: $(Agent.BuildDirectory)/VSCode-linux-$(VSCODE_ARCH)
          sbomPackageName: "VS Code Linux $(VSCODE_ARCH) (unsigned)"
          sbomPackageVersion: $(Build.SourceVersion)
        - output: pipelineArtifact
          targetPath: $(Build.ArtifactStagingDirectory)/out/server/vscode-server-linux-$(VSCODE_ARCH).tar.gz
          artifactName: vscode_server_linux_$(VSCODE_ARCH)_archive-unsigned
          displayName: Publish server archive
          sbomBuildDropPath: $(Agent.BuildDirectory)/vscode-server-linux-$(VSCODE_ARCH)
          sbomPackageName: "VS Code Linux $(VSCODE_ARCH) Server"
          sbomPackageVersion: $(Build.SourceVersion)
        - output: pipelineArtifact
          targetPath: $(Build.ArtifactStagingDirectory)/out/web/vscode-server-linux-$(VSCODE_ARCH)-web.tar.gz
          artifactName: vscode_web_linux_$(VSCODE_ARCH)_archive-unsigned
          displayName: Publish web server archive
          sbomBuildDropPath: $(Agent.BuildDirectory)/vscode-server-linux-$(VSCODE_ARCH)-web
          sbomPackageName: "VS Code Linux $(VSCODE_ARCH) Web"
          sbomPackageVersion: $(Build.SourceVersion)
        - output: pipelineArtifact
          targetPath: $(Build.ArtifactStagingDirectory)/out/deb/$(DEB_PACKAGE_NAME)
          artifactName: vscode_client_linux_$(VSCODE_ARCH)_deb-package
          displayName: Publish deb package
          sbomBuildDropPath: .build/linux/deb
          sbomPackageName: "VS Code Linux $(VSCODE_ARCH) DEB"
          sbomPackageVersion: $(Build.SourceVersion)
        - output: pipelineArtifact
          targetPath: $(Build.ArtifactStagingDirectory)/out/rpm/$(RPM_PACKAGE_NAME)
          artifactName: vscode_client_linux_$(VSCODE_ARCH)_rpm-package
          displayName: Publish rpm package
          sbomBuildDropPath: .build/linux/rpm
          sbomPackageName: "VS Code Linux $(VSCODE_ARCH) RPM"
          sbomPackageVersion: $(Build.SourceVersion)
        - ${{ if eq(parameters.VSCODE_BUILD_LINUX_SNAP, true) }}:
          - output: pipelineArtifact
            targetPath: $(Build.ArtifactStagingDirectory)/out/snap/$(SNAP_PACKAGE_NAME)
            artifactName: vscode_client_linux_$(VSCODE_ARCH)_snap
            displayName: Publish snap package
            sbomBuildDropPath: $(SNAP_EXTRACTED_PATH)
            sbomPackageName: "VS Code Linux $(VSCODE_ARCH) SNAP"
            sbomPackageVersion: $(Build.SourceVersion)
    steps:
      - template: ./steps/product-build-linux-compile.yml@self
        parameters:
          VSCODE_ARCH: ${{ parameters.VSCODE_ARCH }}
          VSCODE_CIBUILD: ${{ parameters.VSCODE_CIBUILD }}
          VSCODE_QUALITY: ${{ parameters.VSCODE_QUALITY }}
          VSCODE_BUILD_LINUX_SNAP: ${{ parameters.VSCODE_BUILD_LINUX_SNAP }}
          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 }}
          VSCODE_RUN_CHECKS: ${{ parameters.VSCODE_RUN_CHECKS }}
