@@ -197,6 +197,8 @@ jobs:
197197 runs-on : kernel-build
198198 needs : test-kselftest
199199 if : success() || failure()
200+ outputs :
201+ base_branch : ${{ steps.base_branch.outputs.base_branch }}
200202
201203 steps :
202204 - name : Checkout kernel source
@@ -220,40 +222,53 @@ jobs:
220222 BASE_BRANCH="${{ github.base_ref }}"
221223 echo "Using PR base branch: $BASE_BRANCH"
222224 else
223- # For direct pushes, find the common ancestor branch
225+ # For direct pushes, try common base branches first (fast path)
224226 echo "Not a PR, finding base branch via merge-base"
225227
226- # Get all remote branches and find the one with closest common ancestor
227- CURRENT_COMMIT=$(git rev-parse HEAD)
228- BEST_BRANCH=""
229- CLOSEST_DISTANCE=999999
228+ # Try common base branches first (most likely candidates)
229+ for branch in test-stage-separation ciqlts9_2 main master; do
230+ if git rev-parse origin/$branch >/dev/null 2>&1; then
231+ MERGE_BASE=$(git merge-base HEAD origin/$branch 2>/dev/null || echo "")
232+ if [ -n "$MERGE_BASE" ] && [ "$MERGE_BASE" != "$(git rev-parse HEAD)" ]; then
233+ BASE_BRANCH=$branch
234+ DISTANCE=$(git rev-list --count ${MERGE_BASE}..HEAD 2>/dev/null || echo "0")
235+ echo "Found base branch: $BASE_BRANCH (distance: $DISTANCE commits)"
236+ break
237+ fi
238+ fi
239+ done
230240
231- for remote_branch in $(git for-each-ref --format='%(refname:short)' refs/remotes/origin/ | grep -v 'HEAD\|PR-CHECKER'); do
232- branch_name=$(echo "$remote_branch" | sed 's|^origin/||')
241+ # Fallback: if not found, search all branches (slower but comprehensive)
242+ if [ -z "$BASE_BRANCH" ]; then
243+ echo "Common branches not found, searching all branches..."
244+ CURRENT_COMMIT=$(git rev-parse HEAD)
245+ BEST_BRANCH=""
246+ CLOSEST_DISTANCE=999999
233247
234- # Skip if it's the current branch
235- if [ "$branch_name" = "${{ github.ref_name }}" ]; then
236- continue
237- fi
248+ for remote_branch in $(git for-each-ref --format='%(refname:short)' refs/remotes/origin/ | grep -v 'HEAD\|PR-CHECKER' | head -20); do
249+ branch_name=$(echo "$remote_branch" | sed 's|^origin/||')
250+
251+ # Skip if it's the current branch
252+ if [ "$branch_name" = "${{ github.ref_name }}" ]; then
253+ continue
254+ fi
238255
239- MERGE_BASE=$(git merge-base HEAD "$remote_branch" 2>/dev/null || echo "")
256+ MERGE_BASE=$(git merge-base HEAD "$remote_branch" 2>/dev/null || echo "")
240257
241- # Check if this branch shares history and isn't the current commit
242- if [ -n "$MERGE_BASE" ] && [ "$MERGE_BASE" != "$CURRENT_COMMIT" ]; then
243- # Calculate distance (number of commits) from merge-base to current HEAD
244- DISTANCE=$(git rev-list --count ${MERGE_BASE}..HEAD 2>/dev/null || echo "999999")
258+ if [ -n "$MERGE_BASE" ] && [ "$MERGE_BASE" != "$CURRENT_COMMIT" ]; then
259+ DISTANCE=$(git rev-list --count ${MERGE_BASE}..HEAD 2>/dev/null || echo "999999")
245260
246- # Find the branch with the shortest distance (most recent common ancestor)
247- if [ "$DISTANCE" -lt "$ CLOSEST_DISTANCE" ]; then
248- CLOSEST_DISTANCE=$DISTANCE
249- BEST_BRANCH=$branch_name
261+ if [ "$DISTANCE" -lt "$CLOSEST_DISTANCE" ]; then
262+ CLOSEST_DISTANCE=$DISTANCE
263+ BEST_BRANCH=$branch_name
264+ fi
250265 fi
251- fi
252- done
266+ done
253267
254- if [ -n "$BEST_BRANCH" ]; then
255- BASE_BRANCH=$BEST_BRANCH
256- echo "Found common ancestor with $BASE_BRANCH (distance: $CLOSEST_DISTANCE commits)"
268+ if [ -n "$BEST_BRANCH" ]; then
269+ BASE_BRANCH=$BEST_BRANCH
270+ echo "Found base branch: $BASE_BRANCH (distance: $CLOSEST_DISTANCE commits)"
271+ fi
257272 fi
258273 fi
259274
@@ -368,7 +383,7 @@ jobs:
368383 - name : Checkout kernel source
369384 uses : actions/checkout@v4
370385 with :
371- fetch-depth : 0
386+ fetch-depth : 50 # Shallow clone: enough for commit messages and logs
372387 token : ${{ secrets.GITHUB_TOKEN }}
373388
374389 - name : Download kernel compilation logs
@@ -442,52 +457,11 @@ jobs:
442457 env :
443458 GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
444459 run : |
445- BASE_BRANCH=""
446-
447- # For PRs, use the base branch directly
448- if [ -n "${{ github.base_ref }}" ]; then
449- BASE_BRANCH="${{ github.base_ref }}"
450- echo "Using PR base branch: $BASE_BRANCH"
451- else
452- # For direct pushes, find the common ancestor branch
453- echo "Not a PR, finding base branch via merge-base"
454-
455- # Get all remote branches and find the one with closest common ancestor
456- CURRENT_COMMIT=$(git rev-parse HEAD)
457- BEST_BRANCH=""
458- CLOSEST_DISTANCE=999999
459-
460- for remote_branch in $(git for-each-ref --format='%(refname:short)' refs/remotes/origin/ | grep -v 'HEAD\|PR-CHECKER'); do
461- branch_name=$(echo "$remote_branch" | sed 's|^origin/||')
462-
463- # Skip if it's the current branch
464- if [ "$branch_name" = "${{ github.ref_name }}" ]; then
465- continue
466- fi
467-
468- MERGE_BASE=$(git merge-base HEAD "$remote_branch" 2>/dev/null || echo "")
469-
470- # Check if this branch shares history and isn't the current commit
471- if [ -n "$MERGE_BASE" ] && [ "$MERGE_BASE" != "$CURRENT_COMMIT" ]; then
472- # Calculate distance (number of commits) from merge-base to current HEAD
473- DISTANCE=$(git rev-list --count ${MERGE_BASE}..HEAD 2>/dev/null || echo "999999")
474-
475- # Find the branch with the shortest distance (most recent common ancestor)
476- if [ "$DISTANCE" -lt "$CLOSEST_DISTANCE" ]; then
477- CLOSEST_DISTANCE=$DISTANCE
478- BEST_BRANCH=$branch_name
479- fi
480- fi
481- done
482-
483- if [ -n "$BEST_BRANCH" ]; then
484- BASE_BRANCH=$BEST_BRANCH
485- echo "Found common ancestor with $BASE_BRANCH (distance: $CLOSEST_DISTANCE commits)"
486- fi
487- fi
460+ # Reuse base branch from compare-results stage (already computed)
461+ BASE_BRANCH="${{ needs.compare-results.outputs.base_branch }}"
488462
489463 if [ -z "$BASE_BRANCH" ]; then
490- echo "ERROR: Could not determine base branch for PR"
464+ echo "ERROR: Could not determine base branch for PR (compare-results did not find one) "
491465 exit 1
492466 fi
493467
0 commit comments