Skip to content

Commit 8624aaa

Browse files
gnodetclaude
andcommitted
ci: always pass baseBranch explicitly to Scalpel and add diagnostics
Scalpel's auto-detection of GITHUB_BASE_REF via Maven system properties (env.GITHUB_BASE_REF) is fragile — it can fail in CI rerun contexts or with certain Maven wrapper configurations, causing the report to silently not be generated. Fix: always pass -Dscalpel.baseBranch=origin/${GITHUB_BASE_REF:-main} explicitly. Also add a git merge-base pre-check and improved diagnostics (tail of Scalpel log, broader grep) when the report is not found. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent b12c8bd commit 8624aaa

1 file changed

Lines changed: 16 additions & 6 deletions

File tree

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

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -256,13 +256,20 @@ runScalpelDetection() {
256256
# Strip the Maven "!:" prefix from each entry to get bare artifact IDs for Scalpel.
257257
local skip_downstream
258258
skip_downstream=$(echo "$EXCLUSION_LIST" | sed 's/!://g')
259-
local scalpel_args="-Dscalpel.enabled=true -Dscalpel.mode=report -Dscalpel.fullBuildTriggers= -Dscalpel.fetchBaseBranch=false -Dscalpel.excludePaths=.github/** -Dscalpel.skipTestsForDownstreamModules=${skip_downstream}"
260-
# For workflow_dispatch, GITHUB_BASE_REF may not be set
261-
if [ -z "${GITHUB_BASE_REF:-}" ]; then
262-
scalpel_args="$scalpel_args -Dscalpel.baseBranch=origin/main"
259+
# Always pass baseBranch explicitly — relying on Scalpel's env.GITHUB_BASE_REF
260+
# auto-detection is fragile across Maven wrappers and CI rerun contexts.
261+
local base_branch="origin/${GITHUB_BASE_REF:-main}"
262+
local scalpel_args="-Dscalpel.enabled=true -Dscalpel.mode=report -Dscalpel.fullBuildTriggers= -Dscalpel.fetchBaseBranch=false -Dscalpel.baseBranch=${base_branch} -Dscalpel.excludePaths=.github/** -Dscalpel.skipTestsForDownstreamModules=${skip_downstream}"
263+
264+
# Verify merge base is reachable before running Scalpel
265+
if ! git merge-base HEAD "${base_branch}" >/dev/null 2>&1; then
266+
echo " WARNING: merge base between HEAD and ${base_branch} is not reachable"
267+
echo " HEAD=$(git rev-parse HEAD 2>/dev/null), ${base_branch}=$(git rev-parse ${base_branch} 2>/dev/null || echo 'NOT FOUND')"
268+
scalpel_failure_reason="Merge base not reachable between HEAD and ${base_branch} (shallow clone too shallow?)"
269+
return
263270
fi
264271

265-
echo " Scalpel: running mvn validate (report mode)..."
272+
echo " Scalpel: running mvn validate (report mode, base=${base_branch})..."
266273
./mvnw -B -q validate $scalpel_args ${MAVEN_EXTRA_ARGS:-} -l /tmp/scalpel-validate.log 2>/dev/null || {
267274
echo " WARNING: Scalpel detection failed (exit $?), skipping"
268275
grep -i "scalpel" /tmp/scalpel-validate.log 2>/dev/null | head -5 || true
@@ -274,7 +281,10 @@ runScalpelDetection() {
274281
local report="target/scalpel-report.json"
275282
if [ ! -f "$report" ]; then
276283
echo " WARNING: Scalpel report not found at $report"
277-
grep -i "scalpel" /tmp/scalpel-validate.log 2>/dev/null | head -5 || true
284+
echo " Scalpel log (last 10 lines):"
285+
tail -10 /tmp/scalpel-validate.log 2>/dev/null || true
286+
echo " Scalpel-specific messages:"
287+
grep -i "scalpel\|merge.base\|JGit\|no changes" /tmp/scalpel-validate.log 2>/dev/null | head -10 || true
278288
scalpel_failure_reason="Scalpel report not found (merge-base may be unreachable in shallow clone)"
279289
return
280290
fi

0 commit comments

Comments
 (0)