###############################################################################################
#  Copyright (c) Microsoft Corporation. All rights reserved.
#  Licensed under the MIT License. See License.txt in the project root for license information.
###############################################################################################
name: $(Date:yyyyMMdd)$(Rev:.r)

trigger:
  batch: true
  branches:
    include:
      - main
pr: none

resources:
  repositories:
    - repository: templates
      type: github
      name: microsoft/vscode-engineering
      ref: main
      endpoint: Monaco

parameters:
  - name: quality
    displayName: Quality
    type: string
    default: latest
    values:
      - latest
      - next
  - name: publishTsconfigGen
    displayName: 🚀 Publish tsconfig-gen
    type: boolean
    default: false
  - name: publishTextDocument
    displayName: 🚀 Publish textDocument
    type: boolean
    default: false
  - name: publishTypes
    displayName: 🚀 Publish types
    type: boolean
    default: false
  - name: publishJsonrpc
    displayName: 🚀 Publish jsonrpc
    type: boolean
    default: false
  - name: publishProtocol
    displayName: 🚀 Publish protocol
    type: boolean
    default: false
  - name: publishServer
    displayName: 🚀 Publish server
    type: boolean
    default: false
  - name: publishClient
    displayName: 🚀 Publish client
    type: boolean
    default: false

extends:
  template: azure-pipelines/npm-package/pipeline.yml@templates
  parameters:
    npmPackages:
      - name: tsconfigGen
        generateNotice: true
        testPlatforms:
          - name: Linux
            nodeVersions:
              - 16.14.2
          - name: MacOS
            nodeVersions:
              - 16.14.2
          - name: Windows
            nodeVersions:
              - 16.14.2
        testSteps:
          - template: /build/azure-pipelines/templates/test-steps.yml@self
            parameters:
              package: tsconfig-gen
        buildSteps:
          - template: /build/azure-pipelines/templates/pack-steps.yml@self
            parameters:
              package: tsconfig-gen
        ghTagPrefix: release/tsconfigGen/
        tag: ${{ parameters.quality }}
        preReleaseTag: next
        preReleaseTagAddToLatest: true
        publishPackage: ${{ parameters.publishTsconfigGen }}
        workingDirectory: $(Build.SourcesDirectory)/tsconfig-gen

      - name: textDocument
        testPlatforms:
          - name: Linux
            nodeVersions:
              - 16.14.2
          - name: MacOS
            nodeVersions:
              - 16.14.2
          - name: Windows
            nodeVersions:
              - 16.14.2
        testSteps:
          - template: /build/azure-pipelines/templates/test-steps.yml@self
            parameters:
              package: textDocument
        buildSteps:
          - template: /build/azure-pipelines/templates/pack-steps.yml@self
            parameters:
              package: textDocument
        ghTagPrefix: release/textDocument/
        tag: ${{ parameters.quality }}
        preReleaseTag: next
        preReleaseTagAddToLatest: true
        publishPackage: ${{ parameters.publishTextDocument }}
        workingDirectory: $(Build.SourcesDirectory)/textDocument

      - name: types
        testPlatforms:
          - name: Linux
            nodeVersions:
              - 16.14.2
          - name: MacOS
            nodeVersions:
              - 16.14.2
          - name: Windows
            nodeVersions:
              - 16.14.2
        testSteps:
          - template: /build/azure-pipelines/templates/test-steps.yml@self
            parameters:
              package: types
        buildSteps:
          - template: /build/azure-pipelines/templates/pack-steps.yml@self
            parameters:
              package: types
        ghTagPrefix: release/types/
        tag: ${{ parameters.quality }}
        preReleaseTag: next
        preReleaseTagAddToLatest: true
        publishPackage: ${{ parameters.publishTypes }}
        workingDirectory: $(Build.SourcesDirectory)/types

      - name: jsonrpc
        testPlatforms:
          - name: Linux
            nodeVersions:
              - 16.14.2
          - name: MacOS
            nodeVersions:
              - 16.14.2
          - name: Windows
            nodeVersions:
              - 16.14.2
        testSteps:
          - template: /build/azure-pipelines/templates/test-steps.yml@self
            parameters:
              package: jsonrpc
        buildSteps:
          - template: /build/azure-pipelines/templates/pack-steps.yml@self
            parameters:
              package: jsonrpc
        ghTagPrefix: release/jsonrpc/
        tag: ${{ parameters.quality }}
        preReleaseTag: next
        preReleaseTagAddToLatest: true
        publishPackage: ${{ parameters.publishJsonrpc }}
        workingDirectory: $(Build.SourcesDirectory)/jsonrpc

      - name: protocol
        testPlatforms:
          - name: Linux
            nodeVersions:
              - 16.14.2
          - name: MacOS
            nodeVersions:
              - 16.14.2
          - name: Windows
            nodeVersions:
              - 16.14.2
        testSteps:
          - template: /build/azure-pipelines/templates/test-steps.yml@self
            parameters:
              package: protocol
        buildSteps:
          - template: /build/azure-pipelines/templates/pack-steps.yml@self
            parameters:
              package: protocol
        ghTagPrefix: release/protocol/
        tag: ${{ parameters.quality }}
        preReleaseTag: next
        preReleaseTagAddToLatest: true
        publishPackage: ${{ parameters.publishProtocol }}
        workingDirectory: $(Build.SourcesDirectory)/protocol

      - name: server
        testPlatforms:
          - name: Linux
            nodeVersions:
              - 16.14.2
          - name: MacOS
            nodeVersions:
              - 16.14.2
          - name: Windows
            nodeVersions:
              - 16.14.2
        testSteps:
          - template: /build/azure-pipelines/templates/test-steps.yml@self
            parameters:
              package: server
        buildSteps:
          - template: /build/azure-pipelines/templates/pack-steps.yml@self
            parameters:
              package: server
        ghTagPrefix: release/server/
        tag: ${{ parameters.quality }}
        preReleaseTag: next
        preReleaseTagAddToLatest: true
        publishPackage: ${{ parameters.publishServer }}
        workingDirectory: $(Build.SourcesDirectory)/server

      - name: client
        testPlatforms:
          - name: Linux
            nodeVersions:
              - 16.14.2
          - name: MacOS
            nodeVersions:
              - 16.14.2
          - name: Windows
            nodeVersions:
              - 16.14.2
        testSteps:
          - template: /build/azure-pipelines/templates/test-steps.yml@self
            parameters:
              package: client
        buildSteps:
          - template: /build/azure-pipelines/templates/pack-steps.yml@self
            parameters:
              package: client
        ghTagPrefix: release/client/
        tag: ${{ parameters.quality }}
        preReleaseTag: next
        preReleaseTagAddToLatest: true
        publishPackage: ${{ parameters.publishClient }}
        workingDirectory: $(Build.SourcesDirectory)/client