Skip to content

Commit 483729f

Browse files
[3.12] GH-133410: Use commit hashes for change detection (gh-133416) (#133426)
GH-133410: Use commit hashes for change detection (gh-133416) (cherry picked from commit d530e74) Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
1 parent aeb3a6f commit 483729f

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

.github/workflows/reusable-context.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ jobs:
9797
run: python Tools/build/compute-changes.py
9898
env:
9999
GITHUB_DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
100+
CCF_TARGET_REF: ${{ github.base_ref || github.event.repository.default_branch }}
101+
CCF_HEAD_REF: ${{ github.event.pull_request.head.sha || github.sha }}
100102

101103
- name: Compute hash for config cache key
102104
id: config-hash

Tools/build/compute-changes.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,10 @@ class Outputs:
5656

5757

5858
def compute_changes() -> None:
59-
target_branch, head_branch = git_branches()
60-
if target_branch and head_branch:
59+
target_branch, head_ref = git_refs()
60+
if target_branch and head_ref:
6161
# Getting changed files only makes sense on a pull request
62-
files = get_changed_files(
63-
f"origin/{target_branch}", f"origin/{head_branch}"
64-
)
62+
files = get_changed_files(target_branch, head_ref)
6563
outputs = process_changed_files(files)
6664
else:
6765
# Otherwise, just run the tests
@@ -89,15 +87,15 @@ def compute_changes() -> None:
8987
write_github_output(outputs)
9088

9189

92-
def git_branches() -> tuple[str, str]:
93-
target_branch = os.environ.get("GITHUB_BASE_REF", "")
94-
target_branch = target_branch.removeprefix("refs/heads/")
95-
print(f"target branch: {target_branch!r}")
90+
def git_refs() -> tuple[str, str]:
91+
target_ref = os.environ.get("CCF_TARGET_REF", "")
92+
target_ref = target_ref.removeprefix("refs/heads/")
93+
print(f"target ref: {target_ref!r}")
9694

97-
head_branch = os.environ.get("GITHUB_HEAD_REF", "")
98-
head_branch = head_branch.removeprefix("refs/heads/")
99-
print(f"head branch: {head_branch!r}")
100-
return target_branch, head_branch
95+
head_ref = os.environ.get("CCF_HEAD_REF", "")
96+
head_ref = head_ref.removeprefix("refs/heads/")
97+
print(f"head ref: {head_ref!r}")
98+
return f"origin/{target_ref}", head_ref
10199

102100

103101
def get_changed_files(

0 commit comments

Comments
 (0)