jobs:
- job: UpdateDepsFiles
  displayName: Update deps files
  pool:
    vmImage: windows-latest
  variables:
  - group: 'Azure Blob variable group'
  steps:
  - checkout: self
    clean: true

  - task: DownloadPipelineArtifact@2
    inputs:
      source: specific
      project: PowerShellCore
      pipeline: '696'
      preferTriggeringPipeline: true
      runVersion: latestFromBranch
      runBranch: '$(Build.SourceBranch)'
      artifact: finalResults
      patterns: '**/PowerShell*-win-x64.zip'
      path: '$(Pipeline.Workspace)/releasePipeline/finalResults'

  - task: DownloadPipelineArtifact@2
    inputs:
      source: specific
      project: PowerShellCore
      pipeline: '696'
      preferTriggeringPipeline: true
      runVersion: latestFromBranch
      runBranch: '$(Build.SourceBranch)'
      artifact: BuildInfoJson
      path: '$(Pipeline.Workspace)/releasePipeline/BuildInfoJson'

  - pwsh: |
      $fileName = (Get-Item "$ENV:PIPELINE_WORKSPACE/releasePipeline/BuildInfoJson/*.json").BaseName
      if ($fileName -notin 'stable','preview')
      {
        throw "Unexpected fileName: $fileName"
      }

      $vstsCommand = "vso[task.setvariable variable=BlobPrefix]$fileName"
      Write-Verbose -Verbose $vstsCommand
      Write-Host "##$vstsCommand"
    displayName: Determine container name

  - pwsh: |
      $zipFile = (Get-Item "$ENV:PIPELINE_WORKSPACE/releasePipeline/finalResults/PowerShell*-win-x64.zip")
      Expand-Archive -Path $zipFile -Destination "$ENV:PIPELINE_WORKSPACE/expanded"

      $pwshDepsFile = Get-Item "$ENV:PIPELINE_WORKSPACE/expanded/pwsh.deps.json"
      $vstsCommand = "vso[task.setvariable variable=FileToUpload]$pwshDepsFile"
      Write-Verbose -Verbose $vstsCommand
      Write-Host "##$vstsCommand"
    displayName: Determine file to upload

  - task: AzureFileCopy@2
    displayName: 'AzureBlob pwsh.deps.json file Copy'
    inputs:
      SourcePath: '$(FileToUpload)'
      azureSubscription: '$(AzureFileCopySubscription)'
      Destination: AzureBlob
      storage: '$(StorageAccount)'
      ContainerName: ps-deps-json
      blobPrefix: '$(BlobPrefix)'
