Skip to content

Commit d518176

Browse files
authored
KAFKA-18500 Build PRs at HEAD commit (apache#18449)
The default checkout behavior for GitHub Actions is to use a special merge ref which is equivalent to the base branch with the PR merged into it. While this is crucial for checking compilation issues against trunk, it significantly diminishes our ability to use any build caching. This patch changes the JUnit test jobs to checkout the HEAD commit of the PR when building. The "Compile and Check" step still checks out the merge commit so we can keep that level of validation. Reviewers: Ismael Juma <[email protected]>, Chia-Ping Tsai <[email protected]>
1 parent 2154e55 commit d518176

File tree

2 files changed

+53
-5
lines changed

2 files changed

+53
-5
lines changed

.github/workflows/README.md

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,47 @@ Composite actions are a convenient way to reuse build logic, but they have
133133
some limitations.
134134

135135
- Cannot run more than one step in a composite action (see `workflow_call` instead)
136-
- Inputs can only be strings, no support for typed parameters. See: https://github.com/actions/runner/issues/2238
136+
- Inputs can only be strings, no support for typed parameters. See: https://github.com/actions/runner/issues/2238
137+
138+
## Troubleshooting
139+
140+
### Gradle Cache Misses
141+
142+
If your PR is running for longer than you would expect due to cache misses, there are a
143+
few things to check.
144+
145+
First, find the cache that was loaded into your PR build. This is found in the Setup Gradle
146+
output. Look for a line starting with "Restored Gradle User Home from cache key".
147+
For example,
148+
149+
```
150+
Restored Gradle User Home from cache key: gradle-home-v1|Linux-X64|test[188616818c9a3165053ef8704c27b28e]-5c20aa187aa8f51af4270d7d1b0db4963b0cd10b
151+
```
152+
153+
The last part of the cache key is the SHA of the commit on trunk where the cache
154+
was created. If that commit is not on your branch, it means your build loaded a
155+
cache that includes changes your PR does not yet have. This is a common way to
156+
have cache misses. To resolve this, update your PR with the latest cached trunk commit:
157+
158+
```commandline
159+
git fetch origin
160+
./committer-tools/update-cache.sh
161+
git merge trunk-cached
162+
```
163+
164+
then push your branch.
165+
166+
If your build seems to be using the correct cache, the next thing to check is for
167+
changes to task inputs. You can find this by locating the trunk Build Scan from
168+
the cache commit on trunk and comparing it with the build scan of your PR build.
169+
This is done in the Develocity UI using the two overlapping circles like `(A()B)`.
170+
This will show you differences in the task inputs for the two builds.
171+
172+
Finally, you can run your PR with extra cache debugging. Add this to the gradle invocation in
173+
[run-gradle/action.yml](../actions/run-gradle/action.yml).
174+
175+
```
176+
-Dorg.gradle.caching.debug=true
177+
```
178+
179+
This will dump out a lot of output, so you may also reduce the test target to one module.

.github/workflows/build.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ jobs:
3636
name: Configure Workflow
3737
outputs:
3838
is-draft: ${{ steps.check-draft-pr.outputs.is-draft }}
39-
test-catalog-days: ${{ steps.test-catalog.outputs.days }}
39+
test-catalog-days: ${{ steps.configure-outputs.outputs.days }}
40+
sha: ${{ steps.configure-outputs.outputs.sha }}
4041
steps:
4142
- name: Env
4243
run: printenv
@@ -48,13 +49,15 @@ jobs:
4849
github.event_name == 'pull_request' &&
4950
github.event.pull_request.draft
5051
run: echo "is-draft=true" >> "$GITHUB_OUTPUT"
51-
- name: Test Catalog Age
52-
id: test-catalog
52+
- name: Configure Outputs
53+
id: configure-outputs
5354
run: |
5455
if [ "${{ github.event_name }}" = "pull_request" ]; then
5556
echo "days=0" >> "$GITHUB_OUTPUT"
57+
echo "sha=${{ github.event.pull_request.head.sha }}" >> "$GITHUB_OUTPUT"
5658
else
5759
echo "days=7" >> "$GITHUB_OUTPUT"
60+
echo "sha=${{ github.sha }}" >> "$GITHUB_OUTPUT"
5861
fi
5962
6063
load-catalog:
@@ -108,7 +111,7 @@ jobs:
108111
validate:
109112
needs: [configure]
110113
runs-on: ubuntu-latest
111-
name: Compile and Check Java
114+
name: Compile and Check (Merge Ref)
112115
steps:
113116
- name: Env
114117
run: printenv
@@ -118,6 +121,7 @@ jobs:
118121
uses: actions/checkout@v4
119122
with:
120123
persist-credentials: false
124+
ref: ${{ github.sha }} # this is the default, just being explicit.
121125
- name: Setup Python
122126
uses: ./.github/actions/setup-python
123127
- name: Setup Gradle
@@ -189,6 +193,7 @@ jobs:
189193
uses: actions/checkout@v4
190194
with:
191195
persist-credentials: false
196+
ref: ${{ needs.configure.outputs.sha }}
192197
- name: Setup Python
193198
uses: ./.github/actions/setup-python
194199
- name: Setup Gradle

0 commit comments

Comments
 (0)