-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathwrite-summary-compare.sh
More file actions
executable file
·53 lines (45 loc) · 1.4 KB
/
write-summary-compare.sh
File metadata and controls
executable file
·53 lines (45 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env bash
set -euo pipefail
REPORT="${1:-comparison-report.json}"
BASE_REF="${BASE_REF:-base}"
HEAD_REF="${HEAD_REF:-head}"
SUMMARY_FILE="${GITHUB_STEP_SUMMARY:-/dev/stdout}"
if [[ ! -f "$REPORT" ]]; then
echo "No comparison report found, skipping summary."
exit 0
fi
# Sanitize user inputs for markdown injection
BASE_REF=$(tr -d '<>|`\n\r' <<<"$BASE_REF")
HEAD_REF=$(tr -d '<>|`\n\r' <<<"$HEAD_REF")
CURR=$(jq -r '.current_total' "$REPORT")
PREV=$(jq -r '.previous_total' "$REPORT")
DELTA=$(jq -r '.total_delta' "$REPORT")
{
echo "## Coverage Comparison: ${BASE_REF} vs ${HEAD_REF}"
echo ""
echo "| Ref | Coverage |"
echo "|-----|----------|"
echo "| ${BASE_REF} (base) | ${PREV}% |"
echo "| ${HEAD_REF} (head) | ${CURR}% |"
echo "| Delta | ${DELTA}% |"
echo ""
} >>"$SUMMARY_FILE"
DROPS=$(jq -r '.top_drops[:10][] | "| \(.package) | \(.previous)% | \(.current)% | \(.delta)% |"' "$REPORT" 2>/dev/null || true)
if [[ -n "$DROPS" ]]; then
{
echo "### Top Drops"
echo "| Package | Base | Head | Delta |"
echo "|---------|------|------|-------|"
echo "$DROPS"
} >>"$SUMMARY_FILE"
fi
GAINS=$(jq -r '.top_gains[:5][] | "| \(.package) | \(.previous)% | \(.current)% | +\(.delta)% |"' "$REPORT" 2>/dev/null || true)
if [[ -n "$GAINS" ]]; then
{
echo ""
echo "### Top Gains"
echo "| Package | Base | Head | Delta |"
echo "|---------|------|------|-------|"
echo "$GAINS"
} >>"$SUMMARY_FILE"
fi