Skip to content

Commit 0aebeaf

Browse files
committed
change detection
1 parent 5d7cc6b commit 0aebeaf

File tree

2 files changed

+29
-15
lines changed

2 files changed

+29
-15
lines changed

.github/workflows/reusable-context.yml

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,18 @@ jobs:
6868
}}
6969
7070
- run: git remote -vvv
71-
- run: echo ${{ github.ref }}
72-
- run: echo ${{ github.repository }}
73-
- run: echo ${{ github.repository }}
74-
- run: echo ${{ github.event.pull_request.head.sha }}
75-
- run: echo ${{ env.GITHUB_HEAD_REF }}
71+
- run: git -P branch -v
72+
- run: git -P branch -r -v
73+
- run: echo ref= ${{ github.ref }}
74+
- run: echo sha= ${{ github.sha }}
75+
- run: echo repository= ${{ github.repository }}
76+
- run: echo event.pull_request.head.sha= ${{ github.event.pull_request.head.sha }}
77+
- run: echo head_ref= ${{ github.head_ref }}
78+
- run: echo base_ref= ${{ github.base_ref }}
79+
- run: echo env.GITHUB_HEAD_REF= ${{ env.GITHUB_HEAD_REF }}
80+
- run: echo $GITHUB_HEAD_REF
81+
- run: echo $GITHUB_BASE_REF
82+
- run: echo head sha or sha = ${{ github.event.pull_request.head.sha || github.sha }}
7683

7784
# Adapted from https://github.com/actions/checkout/issues/520#issuecomment-1167205721
7885
- name: Fetch commits to get branch diff
@@ -96,6 +103,8 @@ jobs:
96103
commits: ${{ github.event.pull_request.commits }}
97104
refspec_base: '+${{ github.event.pull_request.base.sha }}:remotes/origin/${{ github.event.pull_request.base.ref }}'
98105
refspec_pr: '+${{ github.event.pull_request.head.sha }}:remotes/origin/${{ github.event.pull_request.head.ref }}'
106+
- run: git -P branch -v
107+
- run: git -P branch -r -v
99108

100109
# We only want to run tests on PRs when related files are changed,
101110
# or when someone triggers a manual workflow run.
@@ -104,6 +113,8 @@ jobs:
104113
run: python Tools/build/compute-changes.py
105114
env:
106115
GITHUB_DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
116+
CCF_TARGET_REF: ${{ github.base_ref || github.event.repository.default_branch }}
117+
CCF_HEAD_REF: ${{ github.event.pull_request.head.sha || github.sha }}
107118

108119
- name: Compute hash for config cache key
109120
id: config-hash

Tools/build/compute-changes.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,7 @@ def compute_changes() -> None:
5959
target_branch, head_branch = git_branches()
6060
if target_branch and head_branch:
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_branch)
6563
outputs = process_changed_files(files)
6664
else:
6765
# Otherwise, just run the tests
@@ -90,14 +88,14 @@ def compute_changes() -> None:
9088

9189

9290
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}")
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(
@@ -109,6 +107,11 @@ def get_changed_files(
109107
changed_files_result = subprocess.run(
110108
args, stdout=subprocess.PIPE, check=True, encoding="utf-8"
111109
)
110+
print()
111+
print()
112+
print(changed_files_result.stdout.strip())
113+
print()
114+
print()
112115
changed_files = changed_files_result.stdout.strip().splitlines()
113116
return frozenset(map(Path, filter(None, map(str.strip, changed_files))))
114117

0 commit comments

Comments
 (0)