trigger: none
pr: none

extends: 
  template: /eng/pipelines/templates/stages/1es-redirect.yml
  parameters:
    stages: 
      - stage: Release

        jobs:
        - job: Build

          timeoutInMinutes: 30

          variables:
          - template: /eng/pipelines/variables/globals.yml
          - template: /eng/pipelines/variables/image.yml

          pool:
            name: $(LINUXPOOL)
            image: $(LINUXVMIMAGE)
            os: linux

          steps:
          - checkout: self
            submodules: true

          - task: NodeTool@0
            displayName: 'Install Node.js $(NodeVersion)'
            inputs:
              versionSpec: '$(NodeVersion)'

          - template: /eng/pipelines/steps/cache-maven-repository.yml
            parameters:
              JobType: 'Publish TypeSpec'

          - task: PowerShell@2
            retryCountOnTaskFailure: 1
            displayName: 'Build'
            inputs:
              pwsh: true
              filePath: Build-TypeSpec.ps1

          - task: PowerShell@2
            displayName: 'Get Package Version'
            inputs:
              targetType: 'inline'
              script: |
                $PACKAGE_VERSION = node -p -e "require('./typespec-extension/package.json').version"
                Write-Host("##vso[task.setvariable variable=PackageVersion]$PACKAGE_VERSION")

          - task: PowerShell@2
            displayName: 'Create GitHub Releases'
            inputs:
              filePath: eng/scripts/Create-Release.ps1
              arguments: >
                -releaseSha '$(Build.SourceVersion)'
                -tagName '@azure-tools/typespec-java_$(PackageVersion)'
                -title '@azure-tools/typespec-java_$(PackageVersion)'
                -releaseNotes '- Bug fix'
              pwsh: true
            timeoutInMinutes: 5
            env:
              GH_TOKEN: $(azuresdk-github-pat)

          - script: |
              npm config set //registry.npmjs.org/:_authToken=$(azure-sdk-npm-token)
              ls *.tgz | npm publish -0 --access public
              npm config delete //registry.npmjs.org/:_authToken
            displayName: 'Publish TypeSpec Java to NPM'
            workingDirectory: ./typespec-extension

          - template: /eng/pipelines/steps/cleanup-maven-local-cache.yml
