Skip to content

test: Display the test report summary under the workflow run for a PR. #451

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 31, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 40 additions & 7 deletions .github/workflows/test_report.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,20 @@ jobs:
run_id: ${{ github.event.workflow_run.id }}
path: artifacts

- name: Set Test Run URL
id: set_test_run_url
run: echo "test_run_url=${{ github.event.workflow_run.html_url }}" >> $GITHUB_OUTPUT

- name: Summarize Test Results as Markdown Table
id: summarize_test_results
run: |
sudo apt-get update -y
sudo apt-get install -y libxml2-utils
echo "## Unit Test Results Summary" >> $GITHUB_STEP_SUMMARY
echo "# This test report is a summary of the test run in workflow run: [${{ steps.set_test_run_url.outputs.test_run_url }}](${{ steps.set_test_run_url.outputs.test_run_url }})" >> $GITHUB_STEP_SUMMARY
echo "| Test Suite | Tests | Passed | Failed | Skipped | Duration |" >> $GITHUB_STEP_SUMMARY
echo "|------------|-------|--------|--------|---------|----------|" >> $GITHUB_STEP_SUMMARY
SUMMARY_FILE="${GITHUB_WORKSPACE}/summary.md"
echo "## Test Results Summary" > $SUMMARY_FILE
echo "### This test report is a summary of the test run in workflow run: [${{ steps.set_test_run_url.outputs.test_run_url }}](${{ steps.set_test_run_url.outputs.test_run_url }})" >> $SUMMARY_FILE
echo "| Test Suite | Tests | Passed | Failed | Skipped | Duration |" >> $SUMMARY_FILE
echo "|------------|-------|--------|--------|---------|----------|" >> $SUMMARY_FILE
total_tests=0
total_passed=0
total_failed=0
Expand All @@ -68,7 +74,7 @@ jobs:
# Debugging: Output values for each file
echo "Processing file: $file"
echo "Suite: $suite_name, Tests: $tests, Passed: $passed, Failed: $failed, Skipped: $skipped, Duration: $duration"
echo "| $suite_name | $tests | $passed | $failed | $skipped | ${duration}s |" >> $GITHUB_STEP_SUMMARY
echo "| $suite_name | $tests | $passed | $failed | $skipped | ${duration}s |" >> $SUMMARY_FILE
total_tests=$((total_tests + tests))
total_passed=$((total_passed + passed))
total_failed=$((total_failed + failed))
Expand All @@ -81,5 +87,32 @@ jobs:
echo "Total failed: $total_failed"
echo "Total skipped: $total_skipped"
echo "Total duration: $total_duration"
echo "|------------|-------|--------|--------|---------|----------|" >> $GITHUB_STEP_SUMMARY
echo "| **Total** | $total_tests | $total_passed | $total_failed | $total_skipped | ${total_duration}s |" >> $GITHUB_STEP_SUMMARY
echo "|------------|-------|--------|--------|---------|----------|" >> $SUMMARY_FILE
echo "| **Total** | $total_tests | $total_passed | $total_failed | $total_skipped | ${total_duration}s |" >> $SUMMARY_FILE

- name: Complete report test status
if: always()
id: report_test_status
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const path = process.env.SUMMARY_FILE_PATH;
const summaryContent = fs.readFileSync(path, 'utf-8');
console.log("Contents of the summary file:");
console.log(summaryContent);
const check_run = await github.rest.checks.create({
owner: context.repo.owner,
repo: context.repo.repo,
name: "Summarize test report",
head_sha: "${{ github.event.workflow_run.head_commit.id }}",
status: "completed",
conclusion: "${{ job.status }}",
output: {
title: "Test Summary",
summary: summaryContent
}
});
return check_run.data.id;
env:
SUMMARY_FILE_PATH: ${{ steps.summarize_test_results.outputs.summary_file }}
Loading