# This Yaml Document has been converted by ESAI Yaml Pipeline Conversion Tool.
# Please make sure to check all the converted content, it is your team's responsibility to make sure that the pipeline is still valid and functions as expected.
# This pipeline will be extended to the OneESPT template
# The pool section has been filled with placeholder values, replace the pool section with your hosted pool, os, and image name. If you are using a Linux image, you must specify an additional windows image for SDL: https://eng.ms/docs/cloud-ai-platform/devdiv/one-engineering-system-1es/1es-docs/1es-pipeline-templates/features/sdlanalysis/overview#how-to-specify-a-windows-pool-for-the-sdl-source-analysis-stage
# This publishes to https://www.npmjs.com/package/@microsoft/microsoft-graph-types

name: $(BuildDefinitionName)_$(SourceBranchName)_$(Date:yyyyMMdd)$(Rev:.r)
trigger:
  branches:
    include:
    - main
  paths:
    include:
    - microsoft-graph.d.ts
  tags:
    include:
      - '*'

pr: none

variables:
  package_name_v1_0: 'microsoft-graph-types'

resources:
  repositories:
  - repository: 1ESPipelineTemplates
    type: git
    name: 1ESPipelineTemplates/1ESPipelineTemplates
    ref: refs/tags/release

extends:
  template: v1/1ES.Official.PipelineTemplate.yml@1ESPipelineTemplates
  parameters:
    pool:
      name: Azure-Pipelines-1ESPT-ExDShared
      image: windows-latest
      os: windows
    customBuildTags:
    - ES365AIMigrationTooling
    stages:
    - stage: build
      jobs:
      - job: build_v1_0_typings
        displayName: Pack v1.0 typings
        templateContext:
          outputs:
          - output: pipelineArtifact
            displayName: 'Publish Artifact drop'
            targetPath: '$(Build.ArtifactStagingDirectory)'
            artifactName: build-drop
        steps:
        - checkout: self
          displayName: checkout main

        - task: UseNode@1
          displayName: 'Install Node.js'
          inputs:
            version: '22.x'

        - script: npm ci
          displayName: 'Install npm dependencies'
          workingDirectory: '$(Build.SourcesDirectory)'

        # Pack and stage Beta TypeScript package
        - script: npm pack --pack-destination=$(Build.ArtifactStagingDirectory)
          displayName: 'Generate npm package $(package_name_v1_0)'
          workingDirectory: '$(Build.SourcesDirectory)' 


    - stage: deploy
      displayName: 'Deploy v1.0 Typings'
      # This condition deploys on successful CI runs for success builds and also allows for manual deployments from an arbitrary branch
      condition: succeeded()
      dependsOn: 
        - build
      jobs:
        - deployment: deploy_npm
          pool:
            name: Azure-Pipelines-1ESPT-ExDShared
            os: windows
            image: windows-latest
          dependsOn: []
          environment: msgraph-npm-org

          templateContext:
              type: releaseJob
              isProduction: true
              inputs:
                - input: pipelineArtifact
                  artifactName: build-drop
                  targetPath: '$(Build.ArtifactStagingDirectory)/npm'          

          strategy:
            runOnce:
              deploy:
                steps:
                - task: EsrpRelease@9
                  displayName: 'Publish V1.0 NPM package via ESRP Release'
                  inputs:
                    connectedservicename: "Federated DevX ESRP Managed Identity Connection"
                    usemanagedidentity: false
                    keyvaultname: 'akv-prod-eastus'
                    authcertname: 'ReferenceLibraryPrivateCert'
                    signcertname: 'ReferencePackagePublisherCertificate'
                    clientid: '65035b7f-7357-4f29-bf25-c5ee5c3949f8'
                    intent: 'PackageDistribution'
                    contenttype: 'npm'
                    contentsource: 'Folder'
                    folderlocation: '$(Build.ArtifactStagingDirectory)/npm'
                    owners: 'mmainer@microsoft.com,mowen@microsoft.com,gavinbarron@microsoft.com'
                    approvers: 'mmainer@microsoft.com,christiano@microsoft.com,mowen@microsoft.com,lramosvea@microsoft.com,gavinbarron@microsoft.com'
                    serviceendpointurl: 'https://api.esrp.microsoft.com'
                    mainpublisher: 'ESRPRELPACMAN'
                    domaintenantid: 'cdc5aeea-15c5-4db6-b079-fcadd2505dc2'