Skip to content

Commit 5279b9d

Browse files
Fix kselftest base branch comparing
Signed-off-by: Shreeya Patel <spatel@ciq.com>
1 parent f0b148d commit 5279b9d

File tree

1 file changed

+78
-18
lines changed

1 file changed

+78
-18
lines changed

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

Lines changed: 78 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -205,33 +205,64 @@ jobs:
205205
name: kselftest-logs-x86_64
206206
path: output-current
207207

208-
- name: Download previous kselftest logs
208+
- name: Determine base branch for comparison
209+
id: base_branch
210+
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 "")
213+
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
224+
fi
225+
fi
226+
done
227+
fi
228+
229+
if [ -z "$BASE_BRANCH" ]; then
230+
echo "WARNING: Could not determine base branch, defaulting to main"
231+
BASE_BRANCH="main"
232+
fi
233+
234+
echo "base_branch=$BASE_BRANCH" >> $GITHUB_OUTPUT
235+
echo "Base branch for comparison: $BASE_BRANCH"
236+
237+
- name: Download baseline kselftest logs from base branch
209238
uses: dawidd6/action-download-artifact@v3
210239
with:
211240
workflow: kernel-build-and-test-x86_64.yml
212241
name: kselftest-logs-x86_64
213242
path: output-previous
214-
branch: ${{ github.ref_name }}
243+
branch: ${{ steps.base_branch.outputs.base_branch }}
215244
workflow_conclusion: success
216245
search_artifacts: true
217246
skip_unpack: false
218247
if_no_artifact_found: warn
219248
continue-on-error: true
220249

221250
- name: Compare test results
251+
id: comparison
222252
run: |
223-
if [ -f output-previous/kselftests-*.log ]; then
253+
# Check if baseline logs exist
254+
if ls output-previous/kselftests-*.log 1> /dev/null 2>&1; then
224255
# Compare passing tests (ok)
225-
BEFORE_PASS=$(grep -a '^ok' output-previous/kselftests-*.log | wc -l)
226-
AFTER_PASS=$(grep -a '^ok' output-current/kselftests-*.log | wc -l)
256+
BEFORE_PASS=$(grep -a '^ok' output-previous/kselftests-*.log | wc -l || echo "0")
257+
AFTER_PASS=$(grep -a '^ok' output-current/kselftests-*.log | wc -l || echo "0")
227258
228259
# Compare failing tests (not ok)
229-
BEFORE_FAIL=$(grep -a '^not ok' output-previous/kselftests-*.log | wc -l)
230-
AFTER_FAIL=$(grep -a '^not ok' output-current/kselftests-*.log | wc -l)
260+
BEFORE_FAIL=$(grep -a '^not ok' output-previous/kselftests-*.log | wc -l || echo "0")
261+
AFTER_FAIL=$(grep -a '^not ok' output-current/kselftests-*.log | wc -l || echo "0")
231262
232-
echo "### Kselftest Comparison (Branch: ${{ github.ref_name }})"
233-
echo "Passing tests: $BEFORE_PASS -> $AFTER_PASS"
234-
echo "Failing tests: $BEFORE_FAIL -> $AFTER_FAIL"
263+
echo "### Kselftest Comparison"
264+
echo "Baseline (from ${{ steps.base_branch.outputs.base_branch }}): $BEFORE_PASS passing, $BEFORE_FAIL failing"
265+
echo "Current (${{ github.ref_name }}): $AFTER_PASS passing, $AFTER_FAIL failing"
235266
236267
# Calculate differences
237268
PASS_DIFF=$((AFTER_PASS - BEFORE_PASS))
@@ -255,21 +286,39 @@ jobs:
255286
256287
if [ $REGRESSION -eq 1 ]; then
257288
echo "::error::Test regression exceeds acceptable threshold of 3 tests"
289+
echo "comparison_status=failed" >> $GITHUB_OUTPUT
290+
echo "comparison_message=Regression detected: Pass diff: $PASS_DIFF, Fail diff: $FAIL_DIFF (threshold: ±3)" >> $GITHUB_OUTPUT
258291
exit 1
259292
else
260293
echo "::notice::Test results within acceptable range (threshold: ±3 tests)"
294+
echo "comparison_status=passed" >> $GITHUB_OUTPUT
295+
echo "comparison_message=Baseline: $BEFORE_PASS passing, $BEFORE_FAIL failing | Current: $AFTER_PASS passing, $AFTER_FAIL failing" >> $GITHUB_OUTPUT
261296
fi
262297
else
263-
echo "::warning::No previous successful test results found for branch ${{ github.ref_name }}, skipping comparison"
298+
echo "::warning::No baseline test results found for branch ${{ steps.base_branch.outputs.base_branch }}"
299+
echo "::notice::Cannot compare against base branch - artifacts may not exist or have expired (7-day retention)"
300+
echo "::notice::Skipping comparison - PR will still be created with warning"
301+
echo "comparison_status=skipped" >> $GITHUB_OUTPUT
302+
echo "comparison_message=No baseline results available from ${{ steps.base_branch.outputs.base_branch }}" >> $GITHUB_OUTPUT
264303
fi
265304
266305
create-pr:
267306
name: Create Pull Request
268307
runs-on: kernel-build
269308
needs: [build, boot, test-kselftest, compare-results]
270-
if: success()
309+
if: success() || failure()
271310

272311
steps:
312+
- name: Check if all stages passed
313+
run: |
314+
if [ "${{ needs.build.result }}" != "success" ] || \
315+
[ "${{ needs.boot.result }}" != "success" ] || \
316+
[ "${{ needs.test-kselftest.result }}" != "success" ]; then
317+
echo "One or more test stages failed, skipping PR creation"
318+
exit 1
319+
fi
320+
echo "All test stages passed, proceeding with PR creation"
321+
273322
- name: Checkout kernel source
274323
uses: actions/checkout@v4
275324
with:
@@ -376,15 +425,28 @@ jobs:
376425
377426
echo "Creating PR from ${{ github.ref_name }} to $BASE_BRANCH"
378427
428+
# Determine comparison status message
429+
COMPARISON_RESULT="${{ needs.compare-results.result }}"
430+
if [ "$COMPARISON_RESULT" = "success" ]; then
431+
COMPARISON_SECTION="### ✅ Test Comparison
432+
- Status: Passed - Within acceptable threshold (±3 tests)
433+
- Compared against: $BASE_BRANCH"
434+
else
435+
COMPARISON_SECTION="### ⚠️ Test Comparison
436+
- Status: Skipped
437+
- Reason: No baseline test results available from $BASE_BRANCH
438+
- **Note:** Manual review recommended to ensure no regressions"
439+
fi
440+
379441
# Create PR body
380-
cat > pr_body.md << 'EOF'
442+
cat > pr_body.md << EOF
381443
## Summary
382444
This PR has been automatically created after successful completion of all CI stages.
383445
384446
## Commit Message(s)
385-
```
447+
\`\`\`
386448
${{ steps.commit_msg.outputs.commit_message }}
387-
```
449+
\`\`\`
388450
389451
## Test Results
390452
@@ -403,9 +465,7 @@ jobs:
403465
- **Failed:** ${{ steps.stats.outputs.failed }}
404466
- [View kselftest logs](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})
405467
406-
### ✅ Test Comparison
407-
- Comparison against previous run: Within acceptable threshold (±3 tests)
408-
- Branch: ${{ github.ref_name }}
468+
$COMPARISON_SECTION
409469
410470
---
411471
🤖 This PR was automatically generated by GitHub Actions

0 commit comments

Comments
 (0)