trigger: none
pr: none

parameters:
- name: BlobPath
  displayName: 'Container relative blob path'
  type: string
  default: '<team>/java/<version>'
- name: ShouldPublish
  displayName: 'Should publish'
  type: boolean
  default: true

resources:
  repositories:
    - repository: azure-sdk-build-tools
      type: git
      name: internal/azure-sdk-build-tools
      ref: refs/tags/azure-sdk-build-tools_20230613.1

variables:
  BuildToolScripts: $(Pipeline.Workspace)/azure-sdk-build-tools/scripts
  Artifacts: $(Pipeline.Workspace)/artifacts
  EsrpArtifacts: $(Pipeline.Workspace)/packages-esrp

jobs:
- job: Signing
  pool:
    name: azsdk-pool-mms-win-2022-general
    vmImage: windows-2022
  steps:
  - checkout: azure-sdk-build-tools
    path: azure-sdk-build-tools

  - task: PowerShell@2
    displayName: 'Download packages from blob storage'
    inputs:
      targetType: filePath
      filePath: '$(BuildToolScripts)/copy-from-azuresdkpartnerdrops.ps1'
      arguments: '$(Artifacts) ${{ parameters.BlobPath }} $(azuresdkpartnerdrops-access-key)'

  - template: tools/java-esrp-signing/java-esrp-signing.yml@azure-sdk-build-tools
    parameters:
      ArtifactDirectory: $(Artifacts)

  - template: /eng/common/pipelines/templates/steps/publish-artifact.yml
    parameters:
      ArtifactName: packages-signed
      ArtifactPath: $(Artifacts)
- job: Release
  dependsOn: Signing
  pool:
    name: azsdk-pool-mms-win-2022-general
    vmImage: windows-2022
  steps:
  - checkout: self
    path: azure-sdk-for-java

  - checkout: azure-sdk-build-tools
    path: azure-sdk-build-tools

  - download: current
    displayName: Download Signed Artifacts
    artifact: packages-signed

  - template: tools/gpg/gpg.yml@azure-sdk-build-tools

  - template: /eng/pipelines/templates/steps/java-publishing.yml
    parameters:
      ArtifactDirectory: $(Pipeline.Workspace)/packages-signed
      OutputDirectory: $(EsrpArtifacts)
      Target: EsrpRelease
      BuildToolsPath: $(Pipeline.Workspace)/azure-sdk-build-tools
      JavaRepoRoot: $(Pipeline.Workspace)/azure-sdk-for-java
      ShouldPublish: ${{ parameters.ShouldPublish }}
      StageOnly: false

  - template: /eng/common/pipelines/templates/steps/publish-artifact.yml
    parameters:
      ArtifactName: packages-esrp-$(System.JobAttempt)
      ArtifactPath: $(EsrpArtifacts)
