
jobs:
  - job:
    displayName: Daily vcpkg PR
    pool:
      name: azsdk-pool-mms-win-2019-general
      vmImage: MMS2019

    variables:
      # The branch in the azure-sdk/vcpkg repo that is updated daily with the
      # latest set of ports
      TargetPrBranch: release/azure-sdk-for-cpp-daily-verification

    steps:
      - checkout: self

      - template: /eng/pipelines/templates/steps/generate-daily-branch-name.yml

      - template: /eng/pipelines/templates/steps/vcpkg-clone.yml
        parameters:
          Workspace: $(Pipeline.Workspace)
          RepoOwner: azure-sdk

      - template: /eng/common/pipelines/templates/steps/set-default-branch.yml
        parameters:
          WorkingDirectory: $(Pipeline.Workspace)/vcpkg

      - pwsh: |
          Write-Host "git checkout $(DailyBranchName)"
          git checkout $(DailyBranchName)
          if ($LASTEXITCODE -ne 0) {
            Write-Error "Cannot check out $(DailyBranchName) LASTEXITCODE=$LASTEXITCODE"
          }

          Write-Host "##vso[task.setvariable variable=HasChanges]$true"
        workingDirectory: $(Pipeline.Workspace)/vcpkg
        displayName: Update vcpkg Daily Branch

      # This step will skip creating the PR if the PR already exists
      - template: /eng/common/pipelines/templates/steps/create-pull-request.yml
        parameters:
          # Force push so this recreates the $(TargetPrBranch)
          PushArgs: --force
          BaseBranchName: $(DefaultBranch)
          PRBranchName: $(TargetPrBranch)
          RepoOwner: Microsoft
          RepoName: vcpkg
          WorkingDirectory: $(Pipeline.Workspace)/vcpkg
          CommitMsg: Update with changes from $(DailyBranchName)
          PRTitle: "[DO NOT MERGE] Daily Azure SDK for C++ CI validation"
          PRBody: This is a long-lived draft PR should not be merged. Its branch is be updated periodically to validate the Azure SDK for C++ against the vcpkg CI.
          ScriptDirectory: $(System.DefaultWorkingDirectory)/eng/common/scripts
          OpenAsDraft: true
          SkipCheckingForChanges: true
