@@ -326,21 +326,66 @@ jobs:
326326 echo "base_branch=$BASE_BRANCH" >> $GITHUB_OUTPUT
327327 echo "Base branch for comparison: $BASE_BRANCH"
328328
329- - name : Download baseline kselftest logs from base branch
329+ - name : Download baseline kselftest logs from last successful run targeting same base
330330 if : steps.base_branch.outputs.base_branch != ''
331- uses : dawidd6/action-download-artifact@v11
332- with :
333- workflow : kernel-build-and-test-x86_64.yml
334- name : kselftest-logs-x86_64
335- path : output-previous
336- branch : ${{ steps.base_branch.outputs.base_branch }}
337- workflow_conclusion : success
338- search_artifacts : true
339- skip_unpack : false
340- if_no_artifact_found : warn
341- # Only search the last 5 successful runs for better performance
342- run_number : ${{ github.run_number }}
343- search_depth : 5
331+ env :
332+ GH_TOKEN : ${{ steps.generate_token_compare.outputs.token }}
333+ run : |
334+ set +e # Don't exit on error, we handle it with continue-on-error
335+ BASE_BRANCH="${{ steps.base_branch.outputs.base_branch }}"
336+ CURRENT_RUN_ID="${{ github.run_id }}"
337+
338+ echo "Searching for baseline from last successful run targeting base branch: $BASE_BRANCH"
339+ echo "Current run ID: $CURRENT_RUN_ID (will be excluded from search)"
340+
341+ # Get last 50 successful workflow runs (cast a wider net to find PRs targeting this base)
342+ # We need to check each run to see if it targets the same base branch
343+ SUCCESSFUL_RUNS=$(gh run list \
344+ --workflow kernel-build-and-test-x86_64.yml \
345+ --status success \
346+ --limit 50 \
347+ --json databaseId,headBranch,createdAt)
348+
349+ if [ -z "$SUCCESSFUL_RUNS" ] || [ "$SUCCESSFUL_RUNS" = "[]" ]; then
350+ echo "::warning::No successful workflow runs found"
351+ exit 0
352+ fi
353+
354+ # Parse runs and check each one's base branch by examining branch name pattern
355+ while read -r run; do
356+ RUN_ID=$(echo "$run" | jq -r '.databaseId')
357+ HEAD_BRANCH=$(echo "$run" | jq -r '.headBranch')
358+ CREATED_AT=$(echo "$run" | jq -r '.createdAt')
359+
360+ # Skip current run
361+ if [ "$RUN_ID" = "$CURRENT_RUN_ID" ]; then
362+ continue
363+ fi
364+
365+ # Extract base from branch name pattern {name}_base or {name}-base
366+ EXTRACTED_BASE=""
367+ if [[ "$HEAD_BRANCH" =~ \{[^}]+\}[_-](.+) ]]; then
368+ EXTRACTED_BASE="${BASH_REMATCH[1]}"
369+ fi
370+
371+ # Check if this run targets the same base branch
372+ if [ "$EXTRACTED_BASE" = "$BASE_BRANCH" ]; then
373+ echo "Found candidate run $RUN_ID from branch $HEAD_BRANCH (targets: $BASE_BRANCH)"
374+
375+ # Try to download artifact from this run
376+ if gh run download "$RUN_ID" --name kselftest-logs-x86_64 --dir output-previous 2>/dev/null; then
377+ echo "Successfully downloaded baseline from run $RUN_ID (branch: $HEAD_BRANCH, created: $CREATED_AT)"
378+ echo "BASELINE_RUN_ID=$RUN_ID" >> $GITHUB_ENV
379+ echo "BASELINE_BRANCH=$HEAD_BRANCH" >> $GITHUB_ENV
380+ exit 0
381+ else
382+ echo "Run $RUN_ID has no kselftest artifacts or they expired"
383+ fi
384+ fi
385+ done < <(echo "$SUCCESSFUL_RUNS" | jq -c '.[]')
386+
387+ echo "::warning::No baseline test results found in recent successful runs targeting $BASE_BRANCH"
388+ echo "::notice::This may be the first run targeting this base branch, or artifacts have expired (7-day retention)"
344389 continue-on-error : true
345390 timeout-minutes : 3
346391
@@ -358,6 +403,9 @@ jobs:
358403
359404 # Check if baseline logs exist
360405 if ls output-previous/kselftests-*.log 1> /dev/null 2>&1; then
406+ # Get baseline source info
407+ BASELINE_SOURCE="${BASELINE_BRANCH:-last successful run}"
408+
361409 # Compare passing tests (ok)
362410 BEFORE_PASS=$(grep -a '^ok' output-previous/kselftests-*.log | wc -l || echo "0")
363411 AFTER_PASS=$(grep -a '^ok' output-current/kselftests-*.log | wc -l || echo "0")
@@ -367,7 +415,7 @@ jobs:
367415 AFTER_FAIL=$(grep -a '^not ok' output-current/kselftests-*.log | wc -l || echo "0")
368416
369417 echo "### Kselftest Comparison"
370- echo "Baseline (from ${{ steps.base_branch.outputs.base_branch }}): $BEFORE_PASS passing, $BEFORE_FAIL failing"
418+ echo "Baseline (from $BASELINE_SOURCE targeting $ {{ steps.base_branch.outputs.base_branch }}): $BEFORE_PASS passing, $BEFORE_FAIL failing"
371419 echo "Current (${{ github.ref_name }}): $AFTER_PASS passing, $AFTER_FAIL failing"
372420
373421 # Calculate differences
0 commit comments