Skip to content

GH-133410: Use commit hashes for change detection #133416

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/reusable-context.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 11 additions & 13 deletions Tools/build/compute-changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
Loading