parameters:
  - name: VSCODE_ARCH
    type: string
  - name: VSCODE_CIBUILD
    type: boolean
  - 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: macOS_${{ parameters.VSCODE_ARCH }}
    displayName: macOS (${{ 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-macos-$(VSCODE_ARCH)-$(System.JobAttempt)
            displayName: "Publish Crash Reports"
            sbomEnabled: false
            isProduction: false
            condition: failed()
          - output: pipelineArtifact
            targetPath: $(Build.SourcesDirectory)/node_modules
            artifactName: node-modules-macos-$(VSCODE_ARCH)-$(System.JobAttempt)
            displayName: "Publish Node Modules"
            sbomEnabled: false
            isProduction: false
            condition: failed()
          - output: pipelineArtifact
            targetPath: $(Build.SourcesDirectory)/.build/logs
            artifactName: logs-macos-$(VSCODE_ARCH)-$(System.JobAttempt)
            displayName: "Publish Log Files"
            sbomEnabled: false
            isProduction: false
            condition: succeededOrFailed()
        - output: pipelineArtifact
          ${{ if eq(parameters.VSCODE_ARCH, 'x64') }}:
            targetPath: $(Build.ArtifactStagingDirectory)/out/vscode_client_darwin_$(VSCODE_ARCH)_archive/VSCode-darwin.zip
          ${{ if eq(parameters.VSCODE_ARCH, 'arm64') }}:
            targetPath: $(Build.ArtifactStagingDirectory)/out/vscode_client_darwin_$(VSCODE_ARCH)_archive/VSCode-darwin-arm64.zip
          artifactName: vscode_client_darwin_$(VSCODE_ARCH)_archive
          displayName: Publish client archive
          sbomBuildDropPath: $(Build.ArtifactStagingDirectory)/VSCode-darwin-$(VSCODE_ARCH)
          sbomPackageName: "VS Code macOS $(VSCODE_ARCH)"
          sbomPackageVersion: $(Build.SourceVersion)
        - output: pipelineArtifact
          targetPath: $(Build.ArtifactStagingDirectory)/out/vscode_server_darwin_$(VSCODE_ARCH)_archive/vscode-server-darwin-$(VSCODE_ARCH).zip
          artifactName: vscode_server_darwin_$(VSCODE_ARCH)_archive
          displayName: Publish server archive
          sbomBuildDropPath: $(Agent.BuildDirectory)/vscode-server-darwin-$(VSCODE_ARCH)
          sbomPackageName: "VS Code macOS $(VSCODE_ARCH) Server"
          sbomPackageVersion: $(Build.SourceVersion)
        - output: pipelineArtifact
          targetPath: $(Build.ArtifactStagingDirectory)/out/vscode_web_darwin_$(VSCODE_ARCH)_archive/vscode-server-darwin-$(VSCODE_ARCH)-web.zip
          artifactName: vscode_web_darwin_$(VSCODE_ARCH)_archive
          displayName: Publish web server archive
          sbomBuildDropPath: $(Agent.BuildDirectory)/vscode-server-darwin-$(VSCODE_ARCH)-web
          sbomPackageName: "VS Code macOS $(VSCODE_ARCH) Web"
          sbomPackageVersion: $(Build.SourceVersion)
        - output: pipelineArtifact
          targetPath: $(Build.ArtifactStagingDirectory)/out/vscode_client_darwin_$(VSCODE_ARCH)_dmg/VSCode-darwin-$(VSCODE_ARCH).dmg
          artifactName: vscode_client_darwin_$(VSCODE_ARCH)_dmg
          displayName: Publish client DMG
          sbomBuildDropPath: $(Build.ArtifactStagingDirectory)/VSCode-darwin-$(VSCODE_ARCH)
          sbomPackageName: "VS Code macOS $(VSCODE_ARCH)"
          sbomPackageVersion: $(Build.SourceVersion)
    steps:
      - template: ./steps/product-build-darwin-compile.yml@self
        parameters:
          VSCODE_ARCH: ${{ parameters.VSCODE_ARCH }}
          VSCODE_CIBUILD: ${{ parameters.VSCODE_CIBUILD }}
          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 }}
