From f43cd44d4ba1d6c540b1682214baa7ec893fb5e5 Mon Sep 17 00:00:00 2001 From: Johannes Pein Date: Sat, 12 Sep 2026 11:10:11 +0200 Subject: [PATCH] fix: simplify coverage summary generation, apply action lint --- .github/workflows/rust-coverage.yml | 11 +------- scripts/coverage/coverage_per_file.sh | 15 ----------- scripts/coverage/coverage_report.sh | 39 +++++++++++++++++++++++++++ scripts/coverage/coverage_summary.sh | 15 ----------- 4 files changed, 40 insertions(+), 40 deletions(-) delete mode 100755 scripts/coverage/coverage_per_file.sh create mode 100644 scripts/coverage/coverage_report.sh delete mode 100755 scripts/coverage/coverage_summary.sh diff --git a/.github/workflows/rust-coverage.yml b/.github/workflows/rust-coverage.yml index 120e1cc..aba1569 100644 --- a/.github/workflows/rust-coverage.yml +++ b/.github/workflows/rust-coverage.yml @@ -55,13 +55,4 @@ jobs: # Convert the generated coverage report into overall and per-file summaries and add them to the GitHub job summary - name: Coverage summary - run: | - echo "### Test Coverage Report" >> $GITHUB_STEP_SUMMARY - echo "" >> $GITHUB_STEP_SUMMARY - ./.shared/scripts/coverage/coverage_summary.sh < /tmp/coverage.json >> $GITHUB_STEP_SUMMARY - echo "" >> $GITHUB_STEP_SUMMARY - echo "
Per-file coverage" >> $GITHUB_STEP_SUMMARY - echo "" >> $GITHUB_STEP_SUMMARY - ./.shared/scripts/coverage/coverage_per_file.sh < /tmp/coverage.json >> $GITHUB_STEP_SUMMARY - echo "" >> $GITHUB_STEP_SUMMARY - echo "
" >> $GITHUB_STEP_SUMMARY \ No newline at end of file + run: ./.shared/scripts/coverage/coverage_report.sh < /tmp/coverage.json >> "$GITHUB_STEP_SUMMARY" \ No newline at end of file diff --git a/scripts/coverage/coverage_per_file.sh b/scripts/coverage/coverage_per_file.sh deleted file mode 100755 index ab533cc..0000000 --- a/scripts/coverage/coverage_per_file.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env bash -# Converts cargo-llvm-cov JSON output (stdin) into a per-file Markdown coverage table. -# Usage: cargo llvm-cov --json ... | ./scripts/coverage/coverage_per_file.sh - -set -euo pipefail - -jq -r ' - "| File | Lines | Functions | Regions | Line Coverage |", - "| ---- | ----: | --------: | ------: | -----------: |", - (.data[0].files | sort_by(-.summary.lines.percent) | .[] | - .filename as $f | - .summary | - "| \($f | split("/") | .[-3:] | join("/")) | \(.lines.covered)/\(.lines.count) | \(.functions.covered)/\(.functions.count) | \(.regions.covered)/\(.regions.count) | \(.lines.percent * 100 | round / 100)% |" - ) -' \ No newline at end of file diff --git a/scripts/coverage/coverage_report.sh b/scripts/coverage/coverage_report.sh new file mode 100644 index 0000000..c715023 --- /dev/null +++ b/scripts/coverage/coverage_report.sh @@ -0,0 +1,39 @@ +#!/bin/bash +# Generate coverage report in markdown format from cargo-llvm-cov JSON output. +# Reads cargo-llvm-cov JSON output from stdin and outputs markdown to stdout +# Usage: cargo llvm-cov --json ... | ./scripts/coverage/coverage_report.sh + + +set -euo pipefail + +echo "### Test Coverage Report" +echo "" + +# Overall coverage summary +jq -r ' + .data[0].totals | + "| Metric | Covered | Total | Coverage |", + "| ------ | ------: | ----: | -------: |", + "| Lines | \(.lines.covered) | \(.lines.count) | \(.lines.percent * 100 | round / 100)% |", + "| Functions | \(.functions.covered) | \(.functions.count) | \(.functions.percent * 100 | round / 100)% |", + "| Regions | \(.regions.covered) | \(.regions.count) | \(.regions.percent * 100 | round / 100)% |", + "| Instantiations | \(.instantiations.covered) | \(.instantiations.count) | \(.instantiations.percent * 100 | round / 100)% |" +' + +echo "" +echo "
Per-file coverage" +echo "" + +# Per-file coverage table +jq -r ' + "| File | Lines | Functions | Regions | Line Coverage |", + "| ---- | ----: | --------: | ------: | -----------: |", + (.data[0].files | sort_by(-.summary.lines.percent) | .[] | + .filename as $f | + .summary | + "| \($f | split("/") | .[-3:] | join("/")) | \(.lines.covered)/\(.lines.count) | \(.functions.covered)/\(.functions.count) | \(.regions.covered)/\(.regions.count) | \(.lines.percent * 100 | round / 100)% |" + ) +' + +echo "" +echo "
" diff --git a/scripts/coverage/coverage_summary.sh b/scripts/coverage/coverage_summary.sh deleted file mode 100755 index e5beea2..0000000 --- a/scripts/coverage/coverage_summary.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env bash -# Converts cargo-llvm-cov JSON output (stdin) into a Markdown summary table. -# Usage: cargo llvm-cov --json --summary-only ... | ./scripts/coverage/coverage_summary.sh - -set -euo pipefail - -jq -r ' - .data[0].totals | - "| Metric | Covered | Total | Coverage |", - "| ------ | ------: | ----: | -------: |", - "| Lines | \(.lines.covered) | \(.lines.count) | \(.lines.percent * 100 | round / 100)% |", - "| Functions | \(.functions.covered) | \(.functions.count) | \(.functions.percent * 100 | round / 100)% |", - "| Regions | \(.regions.covered) | \(.regions.count) | \(.regions.percent * 100 | round / 100)% |", - "| Instantiations | \(.instantiations.covered) | \(.instantiations.count) | \(.instantiations.percent * 100 | round / 100)% |" -' \ No newline at end of file