# Shared template: Authenticode sign DLLs, pack NuGet packages, sign NuGet packages.
# Requires the calling pipeline to define variables:
#   $(appRegistrationTenantId), $(authenticodeSignId), $(nugetSignId), $(folderPath), $(buildConfiguration)

steps:
  - task: EsrpCodeSigning@5
    displayName: 'Authenticode Sign DLLs'
    inputs:
      ConnectedServiceName: 'TeamsESRP-CP-230012'
      AppRegistrationTenantId: '$(appRegistrationTenantId)'
      AppRegistrationClientId: '$(authenticodeSignId)'
      AuthSignCertName: '$(authenticodeSignId)'
      EsrpClientId: '$(authenticodeSignId)'
      AuthAKVName: esrp-teams
      UseMSIAuthentication: true
      FolderPath: '$(folderPath)'
      Pattern: 'Libraries/**/*.dll'
      UseMinimatch: true
      signConfigType: 'inlineSignParams'
      inlineOperation: |
        [
          {
              "KeyCode": "CP-230012",
              "OperationCode": "SigntoolSign",
              "Parameters": {
                  "OpusName": "Microsoft",
                  "OpusInfo": "http://www.microsoft.com",
                  "FileDigest": "/fd \"SHA256\"",
                  "PageHash": "/NPH",
                  "TimeStamp": "/tr \"http://rfc3161.gtm.corp.microsoft.com/TSS/HttpTspServer\" /td sha256"
              },
              "ToolName": "sign",
              "ToolVersion": "1.0"
          },
          {
            "KeyCode": "CP-230012",
            "OperationCode": "SigntoolVerify",
            "Parameters": {},
            "ToolName": "sign",
            "ToolVersion": "1.0"
          }
        ]
      SessionTimeout: '60'
      MaxConcurrency: '50'
      MaxRetryAttempts: '5'

  - task: DotNetCoreCLI@2
    displayName: 'Pack NuGet Packages'
    inputs:
      command: pack
      packagesToPack: '$(folderPath)/Libraries/**/*.csproj'
      packDestination: '$(Build.ArtifactStagingDirectory)'
      includeSymbols: false
      nobuild: true
      configuration: '$(buildConfiguration)'
      arguments: '/p:SymbolPackageFormat=snupkg'

  - task: EsrpCodeSigning@5
    displayName: 'Sign NuGet Packages'
    inputs:
      ConnectedServiceName: 'TeamsESRP-CP-401405'
      AppRegistrationTenantId: '$(appRegistrationTenantId)'
      AppRegistrationClientId: '$(nugetSignId)'
      AuthSignCertName: '$(nugetSignId)'
      EsrpClientId: '$(nugetSignId)'
      AuthAKVName: esrp-teams
      UseMSIAuthentication: true
      FolderPath: '$(Build.ArtifactStagingDirectory)'
      Pattern: |
        *.nupkg
        *.snupkg
      UseMinimatch: true
      signConfigType: 'inlineSignParams'
      inlineOperation: |
        [
          {
            "KeyCode": "CP-401405",
            "OperationCode": "NuGetSign",
            "ToolName": "sign",
            "ToolVersion": "1.0",
            "Parameters": {}
          },
          {
            "KeyCode": "CP-401405",
            "OperationCode": "NuGetVerify",
            "Parameters": {},
            "ToolName": "sign",
            "ToolVersion": "1.0"
          }
        ]
      SessionTimeout: '20'
      MaxConcurrency: '50'
      MaxRetryAttempts: '5'
      PendingAnalysisWaitTimeoutMinutes: '5'
