Skip to content

Commit 73a8203

Browse files
gnodetclaude
andcommitted
ci: use local git diff instead of GitHub API for incremental builds
Switch the grep-based incremental build script from fetching diffs via the GitHub REST API to using local git merge-base + diff. Both the grep script and Scalpel now share the same --deepen=200 fetch step, removing the GitHub API dependency for diff fetching. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 776b802 commit 73a8203

2 files changed

Lines changed: 13 additions & 21 deletions

File tree

.github/CI-ARCHITECTURE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ The shadow comparison section shows:
174174

175175
The script overrides `fullBuildTriggers` to empty (`-Dscalpel.fullBuildTriggers=`) because Scalpel's default (`.mvn/**`) would trigger a full build whenever `.mvn/extensions.xml` itself changes (e.g., Dependabot bumping Scalpel).
176176

177-
The base branch is pre-fetched by the CI workflow (`git fetch --deepen=200` + fetch of `origin/main`) rather than by Scalpel's built-in JGit fetch (`-Dscalpel.fetchBaseBranch=false`). This avoids JGit issues in shallow CI clones.
177+
The base branch is pre-fetched by the CI workflow (`git fetch --deepen=200` + fetch of `origin/main`). Both the grep-based script and Scalpel use this local git history to compute the merge-base and derive the changed-file diff — no GitHub API call is needed for diff fetching. Scalpel disables its built-in JGit fetch (`-Dscalpel.fetchBaseBranch=false`) to avoid JGit issues in shallow CI clones. The `--deepen=200` fetches only commit metadata (not file blobs), adding ~2-3 seconds to the job.
178178

179179
## Manual Integration Test Advisories
180180

.github/actions/incremental-build/incremental-build.sh

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -106,27 +106,19 @@ hasLabel() {
106106
"https://api.github.com/repos/${repository}/issues/${issueNumber}/labels" | jq -r '.[].name' | { grep -c "$label" || true; }
107107
}
108108

109-
# Fetch the PR diff from the GitHub API. Returns the full unified diff.
109+
# Compute the diff between the current HEAD and the base branch using local git.
110+
# Requires the base branch to be fetched (see pr-build-main.yml "Fetch base branch" step).
110111
fetchDiff() {
111-
local prId="$1"
112-
local repository="$2"
112+
local base_ref="${GITHUB_BASE_REF:-main}"
113+
local merge_base
114+
merge_base=$(git merge-base "origin/${base_ref}" HEAD 2>/dev/null) || true
113115

114-
local diff_output
115-
diff_output=$(curl -s -w "\n%{http_code}" \
116-
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
117-
-H "Accept: application/vnd.github.v3.diff" \
118-
"https://api.github.com/repos/${repository}/pulls/${prId}")
119-
120-
local http_code
121-
http_code=$(echo "$diff_output" | tail -n 1)
122-
local diff_body
123-
diff_body=$(echo "$diff_output" | sed '$d')
124-
125-
if [[ "$http_code" -lt 200 || "$http_code" -ge 300 || -z "$diff_body" ]]; then
126-
echo "WARNING: Failed to fetch PR diff (HTTP $http_code). Falling back to full build." >&2
116+
if [ -z "$merge_base" ]; then
117+
echo "WARNING: Could not find merge-base with origin/${base_ref}. Falling back to full build." >&2
127118
return
128119
fi
129-
echo "$diff_body"
120+
121+
git diff "${merge_base}" HEAD 2>/dev/null || true
130122
}
131123

132124
# ── POM dependency analysis (previously detect-dependencies) ───────────
@@ -556,11 +548,11 @@ main() {
556548
fi
557549
fi
558550

559-
# Fetch the diff (PR diff via API, or git diff for push builds)
551+
# Compute the diff using local git history (merge-base for PRs, HEAD~1 for push builds)
560552
local diff_body
561553
if [ -n "$prId" ]; then
562-
echo "Fetching PR #${prId} diff..."
563-
diff_body=$(fetchDiff "$prId" "$repository")
554+
echo "Computing diff against origin/${GITHUB_BASE_REF:-main}..."
555+
diff_body=$(fetchDiff)
564556
else
565557
echo "No PR ID, using git diff HEAD~1..."
566558
diff_body=$(git diff HEAD~1 2>/dev/null || true)

0 commit comments

Comments
 (0)