Skip to content

Commit a31e328

Browse files
Kselftest and Create PR optimizations
Signed-off-by: Shreeya Patel <spatel@ciq.com>
1 parent b3ac240 commit a31e328

File tree

1 file changed

+10
-47
lines changed

1 file changed

+10
-47
lines changed

.github/workflows/kernel-build-and-test-x86_64.yml

Lines changed: 10 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -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
@@ -223,12 +225,14 @@ jobs:
223225
# For direct pushes, find the common ancestor branch
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
228+
# Get all remote branches sorted by commit date (most recent first)
229+
# This ensures we check actively developed branches first
227230
CURRENT_COMMIT=$(git rev-parse HEAD)
228231
BEST_BRANCH=""
229232
CLOSEST_DISTANCE=999999
230233
231-
for remote_branch in $(git for-each-ref --format='%(refname:short)' refs/remotes/origin/ | grep -v 'HEAD\|PR-CHECKER'); do
234+
# Only check the 30 most recently updated branches for performance
235+
for remote_branch in $(git for-each-ref --sort=-committerdate --format='%(refname:short)' refs/remotes/origin/ | grep -v 'HEAD\|PR-CHECKER' | head -30); do
232236
branch_name=$(echo "$remote_branch" | sed 's|^origin/||')
233237
234238
# Skip if it's the current branch
@@ -368,7 +372,7 @@ jobs:
368372
- name: Checkout kernel source
369373
uses: actions/checkout@v4
370374
with:
371-
fetch-depth: 0
375+
fetch-depth: 50 # Shallow clone: enough for commit messages and logs
372376
token: ${{ secrets.GITHUB_TOKEN }}
373377

374378
- name: Download kernel compilation logs
@@ -442,52 +446,11 @@ jobs:
442446
env:
443447
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
444448
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
449+
# Reuse base branch from compare-results stage (already computed)
450+
BASE_BRANCH="${{ needs.compare-results.outputs.base_branch }}"
488451
489452
if [ -z "$BASE_BRANCH" ]; then
490-
echo "ERROR: Could not determine base branch for PR"
453+
echo "ERROR: Could not determine base branch for PR (compare-results did not find one)"
491454
exit 1
492455
fi
493456

0 commit comments

Comments
 (0)