@@ -373,7 +373,7 @@ jobs:
373373 echo "base_branch=$BASE_BRANCH" >> $GITHUB_OUTPUT
374374 echo "Base branch for comparison: $BASE_BRANCH"
375375
376- - name : Download baseline kselftest logs from last successful run targeting same base
376+ - name : Download baseline kselftest logs from last merged PR targeting same base
377377 if : steps.base_branch.outputs.base_branch != ''
378378 env :
379379 GH_TOKEN : ${{ steps.generate_token_compare.outputs.token }}
@@ -382,11 +382,11 @@ jobs:
382382 BASE_BRANCH="${{ steps.base_branch.outputs.base_branch }}"
383383 CURRENT_RUN_ID="${{ github.run_id }}"
384384
385- echo "Searching for baseline from last successful run targeting base branch: $BASE_BRANCH"
385+ echo "Searching for baseline from last merged PR targeting base branch: $BASE_BRANCH"
386386 echo "Current run ID: $CURRENT_RUN_ID (will be excluded from search)"
387387
388388 # Get last 50 successful workflow runs (cast a wider net to find PRs targeting this base)
389- # We need to check each run to see if it targets the same base branch
389+ # We need to check each run to see if it targets the same base branch AND was merged
390390 SUCCESSFUL_RUNS=$(gh run list \
391391 --workflow kernel-build-and-test-multiarch.yml \
392392 --status success \
@@ -417,36 +417,51 @@ jobs:
417417
418418 # Check if this run targets the same base branch
419419 if [ "$EXTRACTED_BASE" = "$BASE_BRANCH" ]; then
420- echo "Found candidate run $RUN_ID from branch $HEAD_BRANCH (targets: $BASE_BRANCH)"
421-
422- # Get the most recent artifact with this name (in case of reruns/duplicates)
423- # gh run download always picks the first artifact, which may be from an incomplete run
424- ARTIFACT_ID=$(gh api "repos/${{ github.repository }}/actions/runs/$RUN_ID/artifacts" \
425- --jq ".artifacts[] | select(.name == \"kselftest-logs-${{ matrix.arch }}\" and .expired == false) | .id" \
426- | tail -1)
427-
428- if [ -n "$ARTIFACT_ID" ]; then
429- echo "Downloading artifact ID $ARTIFACT_ID (most recent with name kselftest-logs-${{ matrix.arch }})"
430- mkdir -p output-previous
431- if gh api "repos/${{ github.repository }}/actions/artifacts/$ARTIFACT_ID/zip" > /tmp/baseline-artifact.zip 2>/dev/null && \
432- unzip -q /tmp/baseline-artifact.zip -d output-previous 2>/dev/null; then
433- echo "Successfully downloaded baseline from run $RUN_ID (branch: $HEAD_BRANCH, created: $CREATED_AT)"
434- rm -f /tmp/baseline-artifact.zip
435- echo "BASELINE_RUN_ID=$RUN_ID" >> $GITHUB_ENV
436- echo "BASELINE_BRANCH=$HEAD_BRANCH" >> $GITHUB_ENV
437- exit 0
420+ # Check if the PR from this branch was merged and actually targets the expected base branch
421+ PR_INFO=$(gh pr list --head "$HEAD_BRANCH" --base "$BASE_BRANCH" --state merged --json number,mergedAt,baseRefName --jq '.[0]' 2>/dev/null || echo "")
422+
423+ if [ -n "$PR_INFO" ] && [ "$PR_INFO" != "null" ]; then
424+ BASE_REF=$(echo "$PR_INFO" | jq -r '.baseRefName')
425+ if [ -z "$BASE_REF" ] || [ "$BASE_REF" = "null" ] || [ "$BASE_REF" != "$BASE_BRANCH" ]; then
426+ echo "Merged PR for branch $HEAD_BRANCH does not target expected base $BASE_BRANCH (actual base: ${BASE_REF:-unknown}), skipping run $RUN_ID"
427+ continue
428+ fi
429+
430+ PR_NUMBER=$(echo "$PR_INFO" | jq -r '.number')
431+ MERGED_AT=$(echo "$PR_INFO" | jq -r '.mergedAt')
432+ echo "Found merged PR #$PR_NUMBER from branch $HEAD_BRANCH (merged: $MERGED_AT, targets: $BASE_REF)"
433+
434+ # Get the most recent artifact with this name (in case of reruns/duplicates)
435+ ARTIFACT_ID=$(gh api "repos/${{ github.repository }}/actions/runs/$RUN_ID/artifacts" \
436+ --jq ".artifacts[] | select(.name == \"kselftest-logs-${{ matrix.arch }}\" and .expired == false) | .id" \
437+ | tail -1)
438+
439+ if [ -n "$ARTIFACT_ID" ]; then
440+ echo "Downloading artifact ID $ARTIFACT_ID (most recent with name kselftest-logs-${{ matrix.arch }})"
441+ mkdir -p output-previous
442+ if gh api "repos/${{ github.repository }}/actions/artifacts/$ARTIFACT_ID/zip" > /tmp/baseline-artifact.zip 2>/dev/null && \
443+ unzip -q /tmp/baseline-artifact.zip -d output-previous 2>/dev/null; then
444+ echo "Successfully downloaded baseline from merged PR #$PR_NUMBER (run $RUN_ID, branch: $HEAD_BRANCH)"
445+ rm -f /tmp/baseline-artifact.zip
446+ echo "BASELINE_RUN_ID=$RUN_ID" >> $GITHUB_ENV
447+ echo "BASELINE_BRANCH=$HEAD_BRANCH" >> $GITHUB_ENV
448+ echo "BASELINE_PR=$PR_NUMBER" >> $GITHUB_ENV
449+ exit 0
450+ else
451+ echo "Failed to download or extract artifact $ARTIFACT_ID"
452+ rm -f /tmp/baseline-artifact.zip
453+ fi
438454 else
439- echo "Failed to download or extract artifact $ARTIFACT_ID"
440- rm -f /tmp/baseline-artifact.zip
455+ echo "Run $RUN_ID has no kselftest artifacts for ${{ matrix.arch }} or they expired"
441456 fi
442457 else
443- echo "Run $RUN_ID has no kselftest artifacts for ${{ matrix.arch }} or they expired "
458+ echo "Branch $HEAD_BRANCH was not merged, skipping run $RUN_ID "
444459 fi
445460 fi
446461 done < <(echo "$SUCCESSFUL_RUNS" | jq -c '.[]')
447462
448- echo "::warning::No baseline test results found in recent successful runs targeting $BASE_BRANCH"
449- echo "::notice::This may be the first run targeting this base branch, or artifacts have expired (7-day retention)"
463+ echo "::warning::No baseline test results found from merged PRs targeting $BASE_BRANCH"
464+ echo "::notice::This may be the first merged PR targeting this base branch, or artifacts have expired (7-day retention)"
450465 continue-on-error : true
451466 timeout-minutes : 3
452467
0 commit comments