@@ -326,21 +326,65 @@ 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+
359+ # Skip current run
360+ if [ "$RUN_ID" = "$CURRENT_RUN_ID" ]; then
361+ continue
362+ fi
363+
364+ # Extract base from branch name pattern {name}_base or {name}-base
365+ EXTRACTED_BASE=""
366+ if [[ "$HEAD_BRANCH" =~ \{[^}]+\}[_-](.+) ]]; then
367+ EXTRACTED_BASE="${BASH_REMATCH[1]}"
368+ fi
369+
370+ # Check if this run targets the same base branch
371+ if [ "$EXTRACTED_BASE" = "$BASE_BRANCH" ]; then
372+ echo "Found candidate run $RUN_ID from branch $HEAD_BRANCH (targets: $BASE_BRANCH)"
373+
374+ # Try to download artifact from this run
375+ if gh run download "$RUN_ID" --name kselftest-logs-x86_64 --dir output-previous 2>/dev/null; then
376+ echo "Successfully downloaded baseline from run $RUN_ID (branch: $HEAD_BRANCH)"
377+ echo "BASELINE_RUN_ID=$RUN_ID" >> $GITHUB_ENV
378+ echo "BASELINE_BRANCH=$HEAD_BRANCH" >> $GITHUB_ENV
379+ exit 0
380+ else
381+ echo "Run $RUN_ID has no kselftest artifacts or they expired"
382+ fi
383+ fi
384+ done < <(echo "$SUCCESSFUL_RUNS" | jq -c '.[]')
385+
386+ echo "::warning::No baseline test results found in recent successful runs targeting $BASE_BRANCH"
387+ echo "::notice::This may be the first run targeting this base branch, or artifacts have expired (7-day retention)"
344388 continue-on-error : true
345389 timeout-minutes : 3
346390
@@ -358,6 +402,9 @@ jobs:
358402
359403 # Check if baseline logs exist
360404 if ls output-previous/kselftests-*.log 1> /dev/null 2>&1; then
405+ # Get baseline source info
406+ BASELINE_SOURCE="${BASELINE_BRANCH:-last successful run}"
407+
361408 # Compare passing tests (ok)
362409 BEFORE_PASS=$(grep -a '^ok' output-previous/kselftests-*.log | wc -l || echo "0")
363410 AFTER_PASS=$(grep -a '^ok' output-current/kselftests-*.log | wc -l || echo "0")
@@ -367,7 +414,7 @@ jobs:
367414 AFTER_FAIL=$(grep -a '^not ok' output-current/kselftests-*.log | wc -l || echo "0")
368415
369416 echo "### Kselftest Comparison"
370- echo "Baseline (from ${{ steps.base_branch.outputs.base_branch }}): $BEFORE_PASS passing, $BEFORE_FAIL failing"
417+ echo "Baseline (from $BASELINE_SOURCE targeting $ {{ steps.base_branch.outputs.base_branch }}): $BEFORE_PASS passing, $BEFORE_FAIL failing"
371418 echo "Current (${{ github.ref_name }}): $AFTER_PASS passing, $AFTER_FAIL failing"
372419
373420 # Calculate differences
0 commit comments