@@ -199,6 +199,11 @@ jobs:
199199 if : success() || failure()
200200
201201 steps :
202+ - name : Checkout kernel source
203+ uses : actions/checkout@v4
204+ with :
205+ fetch-depth : 0
206+
202207 - name : Download current kselftest logs
203208 uses : actions/download-artifact@v4
204209 with :
@@ -208,33 +213,62 @@ jobs:
208213 - name : Determine base branch for comparison
209214 id : base_branch
210215 run : |
211- # Determine base branch from the upstream tracking branch
212- BASE_BRANCH=$(git rev-parse --abbrev-ref --symbolic-full-name @{u} 2>/dev/null | sed 's|^origin/||' || echo "")
216+ BASE_BRANCH=""
213217
214- if [ -z "$BASE_BRANCH" ]; then
215- # Fallback: use merge-base to find the common ancestor branch
216- echo "No upstream tracking branch found, using merge-base to find parent branch"
217- for branch in lts-9.2 lts-9 main master; do
218- if git rev-parse origin/$branch >/dev/null 2>&1; then
219- MERGE_BASE=$(git merge-base HEAD origin/$branch 2>/dev/null || echo "")
220- if [ -n "$MERGE_BASE" ]; then
221- BASE_BRANCH=$branch
222- echo "Found common ancestor with origin/$branch"
223- break
218+ # For PRs, use the base branch directly
219+ if [ -n "${{ github.base_ref }}" ]; then
220+ BASE_BRANCH="${{ github.base_ref }}"
221+ echo "Using PR base branch: $BASE_BRANCH"
222+ else
223+ # For direct pushes, find the common ancestor branch
224+ echo "Not a PR, finding base branch via merge-base"
225+
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
230+
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/||')
233+
234+ # Skip if it's the current branch
235+ if [ "$branch_name" = "${{ github.ref_name }}" ]; then
236+ continue
237+ fi
238+
239+ MERGE_BASE=$(git merge-base HEAD "$remote_branch" 2>/dev/null || echo "")
240+
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")
245+
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
224250 fi
225251 fi
226252 done
253+
254+ if [ -n "$BEST_BRANCH" ]; then
255+ BASE_BRANCH=$BEST_BRANCH
256+ echo "Found common ancestor with $BASE_BRANCH (distance: $CLOSEST_DISTANCE commits)"
257+ fi
227258 fi
228259
229260 if [ -z "$BASE_BRANCH" ]; then
230- echo "WARNING: Could not determine base branch, defaulting to main"
231- BASE_BRANCH="main"
261+ echo "::warning::Could not determine base branch for comparison - no common ancestor found"
262+ echo "::warning::Kselftest comparison will be skipped"
263+ echo "base_branch=" >> $GITHUB_OUTPUT
264+ exit 0
232265 fi
233266
234267 echo "base_branch=$BASE_BRANCH" >> $GITHUB_OUTPUT
235268 echo "Base branch for comparison: $BASE_BRANCH"
236269
237270 - name : Download baseline kselftest logs from base branch
271+ if : steps.base_branch.outputs.base_branch != ''
238272 uses : dawidd6/action-download-artifact@v3
239273 with :
240274 workflow : kernel-build-and-test-x86_64.yml
@@ -250,6 +284,15 @@ jobs:
250284 - name : Compare test results
251285 id : comparison
252286 run : |
287+ # Check if we have a base branch to compare against
288+ if [ -z "${{ steps.base_branch.outputs.base_branch }}" ]; then
289+ echo "::warning::No base branch found for comparison"
290+ echo "::warning::Kselftest comparison will be skipped"
291+ echo "comparison_status=skipped" >> $GITHUB_OUTPUT
292+ echo "comparison_message=No base branch found - unable to determine merge target" >> $GITHUB_OUTPUT
293+ exit 0
294+ fi
295+
253296 # Check if baseline logs exist
254297 if ls output-previous/kselftests-*.log 1> /dev/null 2>&1; then
255298 # Compare passing tests (ok)
@@ -396,22 +439,48 @@ jobs:
396439 env :
397440 GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
398441 run : |
399- # Determine base branch from the upstream tracking branch
400- BASE_BRANCH=$(git rev-parse --abbrev-ref --symbolic-full-name @{u} 2>/dev/null | sed 's|^origin/||' || echo "")
442+ BASE_BRANCH=""
401443
402- if [ -z "$BASE_BRANCH" ]; then
403- # Fallback: use merge-base to find the common ancestor branch
404- echo "No upstream tracking branch found, using merge-base to find parent branch"
405- for branch in lts-9.2 lts-9 main master; do
406- if git rev-parse origin/$branch >/dev/null 2>&1; then
407- MERGE_BASE=$(git merge-base HEAD origin/$branch 2>/dev/null || echo "")
408- if [ -n "$MERGE_BASE" ]; then
409- BASE_BRANCH=$branch
410- echo "Found common ancestor with origin/$branch"
411- break
444+ # For PRs, use the base branch directly
445+ if [ -n "${{ github.base_ref }}" ]; then
446+ BASE_BRANCH="${{ github.base_ref }}"
447+ echo "Using PR base branch: $BASE_BRANCH"
448+ else
449+ # For direct pushes, find the common ancestor branch
450+ echo "Not a PR, finding base branch via merge-base"
451+
452+ # Get all remote branches and find the one with closest common ancestor
453+ CURRENT_COMMIT=$(git rev-parse HEAD)
454+ BEST_BRANCH=""
455+ CLOSEST_DISTANCE=999999
456+
457+ for remote_branch in $(git for-each-ref --format='%(refname:short)' refs/remotes/origin/ | grep -v 'HEAD\|PR-CHECKER'); do
458+ branch_name=$(echo "$remote_branch" | sed 's|^origin/||')
459+
460+ # Skip if it's the current branch
461+ if [ "$branch_name" = "${{ github.ref_name }}" ]; then
462+ continue
463+ fi
464+
465+ MERGE_BASE=$(git merge-base HEAD "$remote_branch" 2>/dev/null || echo "")
466+
467+ # Check if this branch shares history and isn't the current commit
468+ if [ -n "$MERGE_BASE" ] && [ "$MERGE_BASE" != "$CURRENT_COMMIT" ]; then
469+ # Calculate distance (number of commits) from merge-base to current HEAD
470+ DISTANCE=$(git rev-list --count ${MERGE_BASE}..HEAD 2>/dev/null || echo "999999")
471+
472+ # Find the branch with the shortest distance (most recent common ancestor)
473+ if [ "$DISTANCE" -lt "$CLOSEST_DISTANCE" ]; then
474+ CLOSEST_DISTANCE=$DISTANCE
475+ BEST_BRANCH=$branch_name
412476 fi
413477 fi
414478 done
479+
480+ if [ -n "$BEST_BRANCH" ]; then
481+ BASE_BRANCH=$BEST_BRANCH
482+ echo "Found common ancestor with $BASE_BRANCH (distance: $CLOSEST_DISTANCE commits)"
483+ fi
415484 fi
416485
417486 if [ -z "$BASE_BRANCH" ]; then
0 commit comments