From d36d87f11e8dedb454dbec86ff3c029c1276f58f Mon Sep 17 00:00:00 2001 From: Manuel de la Pena Date: Fri, 25 Mar 2022 11:38:52 -0400 Subject: [PATCH] [CI] Checkout the head ref rather than the merge or a reset, this should fix issues with the test selector. (#14496) --- tests/xharness/GitHub.cs | 4 ++-- tools/devops/automation/templates/build/build.yml | 8 +++++++- tools/devops/automation/templates/tests/build.yml | 8 +++++++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/tests/xharness/GitHub.cs b/tests/xharness/GitHub.cs index 06785a06a0..749a5a74b7 100644 --- a/tests/xharness/GitHub.cs +++ b/tests/xharness/GitHub.cs @@ -164,8 +164,8 @@ namespace Xharness { IEnumerable GetModifiedFilesLocally (int pullRequest) { - var base_commit = $"origin/pr/{pullRequest}/merge^"; - var head_commit = $"origin/pr/{pullRequest}/merge"; + var base_commit = $"origin/pull/{pullRequest}/merge^"; + var head_commit = $"origin/pull/{pullRequest}/merge"; harness.Log ("Fetching modified files for commit range {0}..{1}", base_commit, head_commit); diff --git a/tools/devops/automation/templates/build/build.yml b/tools/devops/automation/templates/build/build.yml index af36934169..36d0e61f95 100644 --- a/tools/devops/automation/templates/build/build.yml +++ b/tools/devops/automation/templates/build/build.yml @@ -52,7 +52,13 @@ steps: - ${{ if eq(variables['Build.Reason'], 'PullRequest') }}: - pwsh: | - git reset --hard HEAD^2 + git config remote.origin.fetch '+refs/pull/*:refs/remotes/origin/pull/*' + git fetch origin + $branch="$(Build.SourceBranch)".Replace("merge", "head") + $branch=$branch.Replace("refs", "origin") + Write-Host "Checking out branch $branch" + git checkout $branch + git branch -a displayName: "Undo Github merge" workingDirectory: $(System.DefaultWorkingDirectory)/xamarin-macios diff --git a/tools/devops/automation/templates/tests/build.yml b/tools/devops/automation/templates/tests/build.yml index 79ec21be85..91dbf17b39 100644 --- a/tools/devops/automation/templates/tests/build.yml +++ b/tools/devops/automation/templates/tests/build.yml @@ -54,7 +54,13 @@ steps: - ${{ if eq(variables['Build.Reason'], 'PullRequest') }}: - pwsh: | - git reset --hard HEAD^2 + git config remote.origin.fetch '+refs/pull/*:refs/remotes/origin/pull/*' + git fetch origin + $branch="$(Build.SourceBranch)".Replace("merge", "head") + $branch=$branch.Replace("refs", "origin") + Write-Host "Checking out branch $branch" + git checkout $branch + git branch -a displayName: "Undo Github merge" workingDirectory: $(System.DefaultWorkingDirectory)/xamarin-macios