forked from nlohmann/json
-
Notifications
You must be signed in to change notification settings - Fork 6
81 lines (62 loc) · 2.37 KB
/
coverage_gate.yml
File metadata and controls
81 lines (62 loc) · 2.37 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
name: Coverage Gate
on:
workflow_call:
inputs:
artifact_id:
description: "Artifact name for the coverage-gate result"
required: true
type: string
jobs:
coverage_gate:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Download coverage HTML artifact
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
with:
name: code-coverage-report
path: coverage_html
- name: Debug list coverage files
run: |
echo "=== coverage_html contents ==="
ls -R coverage_html
- name: Enforce coverage threshold
run: |
THRESHOLD=99.19
echo "=== Extracting line coverage for 'Lines:' from index.html ==="
HEADER_BLOCK=$(grep -A1 'Lines:' coverage_html/index.html || true)
echo "$HEADER_BLOCK"
LINE_COV=$(echo "$HEADER_BLOCK" | grep -oE "[0-9]+(\.[0-9]+)?" | head -n1 || true)
echo "Extracted Line coverage: '${LINE_COV}'"
if [ -z "$LINE_COV" ]; then
echo "Could not extract line coverage for 'Lines:' from index.html"
exit 1
fi
COMPARE=$(awk -v cov="$LINE_COV" -v thr="$THRESHOLD" 'BEGIN { if (cov < thr) print "lt"; else print "ge"; }')
if [ "$COMPARE" = "lt" ]; then
echo "Coverage below threshold, failing job."
exit 1
fi
echo "Coverage is above threshold."
- name: Create coverage-gate result
if: always()
run: |
mkdir -p coverage_gate
THRESHOLD=99.19
LINE_COV=""
if [ -f coverage_html/index.html ]; then
HEADER_BLOCK=$(grep -A1 'Lines:' coverage_html/index.html || true)
LINE_COV=$(echo "$HEADER_BLOCK" | grep -oE "[0-9]+(\.[0-9]+)?" | head -n1 || true)
fi
{
echo "status=${{ job.status }}"
echo "line_coverage=${LINE_COV}"
echo "threshold=${THRESHOLD}"
} > coverage_gate/coverage_gate.txt
- name: Upload coverage-gate artifact
if: always()
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: ${{ inputs.artifact_id }}
path: coverage_gate/coverage_gate.txt