https://github.com/python/cpython/commit/483729fbc639e6c9913908a3f9218f16a1f68433
commit: 483729fbc639e6c9913908a3f9218f16a1f68433
branch: 3.12
author: Miss Islington (bot) <31488909+miss-isling...@users.noreply.github.com>
committer: Yhg1s <tho...@python.org>
date: 2025-05-06T01:48:34+02:00
summary:

[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 d530e74e444fc483f6d2077f701160e55d3003d8)

Co-authored-by: Adam Turner <9087854+aa-tur...@users.noreply.github.com>

files:
M .github/workflows/reusable-context.yml
M Tools/build/compute-changes.py

diff --git a/.github/workflows/reusable-context.yml 
b/.github/workflows/reusable-context.yml
index 73e036a146f5d4..73dc254edc5fbc 100644
--- a/.github/workflows/reusable-context.yml
+++ b/.github/workflows/reusable-context.yml
@@ -97,6 +97,8 @@ jobs:
       run: python Tools/build/compute-changes.py
       env:
         GITHUB_DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
+        CCF_TARGET_REF: ${{ github.base_ref || 
github.event.repository.default_branch }}
+        CCF_HEAD_REF: ${{ github.event.pull_request.head.sha || github.sha }}
 
     - name: Compute hash for config cache key
       id: config-hash
diff --git a/Tools/build/compute-changes.py b/Tools/build/compute-changes.py
index b3be7df2dba6d0..cfdd55fd1925fd 100644
--- a/Tools/build/compute-changes.py
+++ b/Tools/build/compute-changes.py
@@ -56,12 +56,10 @@ class Outputs:
 
 
 def compute_changes() -> None:
-    target_branch, head_branch = git_branches()
-    if target_branch and head_branch:
+    target_branch, head_ref = git_refs()
+    if target_branch and head_ref:
         # Getting changed files only makes sense on a pull request
-        files = get_changed_files(
-            f"origin/{target_branch}", f"origin/{head_branch}"
-        )
+        files = get_changed_files(target_branch, head_ref)
         outputs = process_changed_files(files)
     else:
         # Otherwise, just run the tests
@@ -89,15 +87,15 @@ def compute_changes() -> None:
     write_github_output(outputs)
 
 
-def git_branches() -> tuple[str, str]:
-    target_branch = os.environ.get("GITHUB_BASE_REF", "")
-    target_branch = target_branch.removeprefix("refs/heads/")
-    print(f"target branch: {target_branch!r}")
+def git_refs() -> tuple[str, str]:
+    target_ref = os.environ.get("CCF_TARGET_REF", "")
+    target_ref = target_ref.removeprefix("refs/heads/")
+    print(f"target ref: {target_ref!r}")
 
-    head_branch = os.environ.get("GITHUB_HEAD_REF", "")
-    head_branch = head_branch.removeprefix("refs/heads/")
-    print(f"head branch: {head_branch!r}")
-    return target_branch, head_branch
+    head_ref = os.environ.get("CCF_HEAD_REF", "")
+    head_ref = head_ref.removeprefix("refs/heads/")
+    print(f"head ref: {head_ref!r}")
+    return f"origin/{target_ref}", head_ref
 
 
 def get_changed_files(

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-le...@python.org
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: arch...@mail-archive.com

Reply via email to