parameters:
  - name: VSCODE_RELEASE
    type: boolean

steps:
  - template: ./common/checkout.yml@self

  - task: NodeTool@0
    inputs:
      versionSource: fromFile
      versionFilePath: .nvmrc

  - template: ./distro/download-distro.yml@self

  - script: node build/azure-pipelines/distro/mixin-quality.ts
    displayName: Mixin distro quality

  - task: AzureCLI@2
    displayName: Fetch secrets
    inputs:
      azureSubscription: vscode
      scriptType: pscore
      scriptLocation: inlineScript
      addSpnToEnvironment: true
      inlineScript: |
        Write-Host "##vso[task.setvariable variable=AZURE_TENANT_ID]$env:tenantId"
        Write-Host "##vso[task.setvariable variable=AZURE_CLIENT_ID]$env:servicePrincipalId"
        Write-Host "##vso[task.setvariable variable=AZURE_ID_TOKEN;issecret=true]$env:idToken"

  - script: npm ci
    workingDirectory: build
    displayName: Install build dependencies

  - pwsh: |
      $publishAuthTokens = (node build/azure-pipelines/common/getPublishAuthTokens.ts)
      Write-Host "##vso[task.setvariable variable=PUBLISH_AUTH_TOKENS;issecret=true]$publishAuthTokens"
    env:
      AZURE_TENANT_ID: "$(AZURE_TENANT_ID)"
      AZURE_CLIENT_ID: "$(AZURE_CLIENT_ID)"
      AZURE_ID_TOKEN: "$(AZURE_ID_TOKEN)"
    displayName: Get publish auth tokens

  - script: node build/azure-pipelines/common/releaseBuild.ts ${{ parameters.VSCODE_RELEASE }}
    displayName: Release build
    env:
      PUBLISH_AUTH_TOKENS: "$(PUBLISH_AUTH_TOKENS)"
