1+ # This workflow should enforce monotonically increasing comment coverage
2+
3+ on : [pull_request]
4+
5+ name : Comment Coverage
6+
7+ # env:
8+ # CARGO_TERM_COLOR: always
9+
10+ jobs :
11+ check-lint-build-stable :
12+ name : Comment Coverage (stable)
13+ runs-on : ubuntu-latest
14+ timeout-minutes : 20
15+ steps :
16+ - name : Install Protoc
17+ uses : arduino/setup-protoc@v2
18+
19+ - name : Install latest stable toolchain
20+ uses : actions-rs/toolchain@v1
21+ with :
22+ profile : minimal
23+ toolchain : stable
24+ components : rustfmt, clippy
25+ override : true
26+ target : x86_64-pc-windows-gnu
27+
28+ - name : Rust Cache
29+ uses : Swatinem/rust-cache@v2.5.1
30+
31+ - name : Checkout PR branch
32+ uses : actions/checkout@v2
33+
34+ - name : Missing docs warnings (PR)
35+ id : missing_docs_warnings_pr
36+ run : |
37+ # use a random EOF, as per GitHub security recommendations
38+ EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
39+ WARNINGS=$(\
40+ cargo -q clippy --message-format=short -- \
41+ -Aclippy::all \
42+ -Wclippy::missing_errors_doc \
43+ -Wclippy::missing_panics_doc \
44+ -Wclippy::missing_safety_doc \
45+ -Wclippy::missing_docs_in_private_items \
46+ -Wmissing_docs \
47+ 2>&1)
48+ echo "$WARNINGS"
49+ AWKSTR='/warning: `.+` \(lib\) generated [0-9]+ warnings?/ { print $3 ": " $7 }'
50+ WARNINGS=$(echo "$WARNINGS" | awk -F"[\` ]" "$AWKSTR" | sort)
51+ echo "PR_WARNINGS<<$EOF" >> "$GITHUB_OUTPUT"
52+ echo "$WARNINGS" >> "$GITHUB_OUTPUT"
53+ echo "$EOF" >> "$GITHUB_OUTPUT"
54+
55+ - name : Checkout target branch
56+ uses : actions/checkout@v2
57+ with :
58+ ref : ${{ github.base_ref }}
59+
60+ - name : Missing docs warnings (Target)
61+ id : missing_docs_warnings_target
62+ run : |
63+ # use a random EOF, as per GitHub security recommendations
64+ EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
65+ WARNINGS=$(\
66+ cargo -q clippy --message-format=short -- \
67+ -Aclippy::all \
68+ -Wclippy::missing_errors_doc \
69+ -Wclippy::missing_panics_doc \
70+ -Wclippy::missing_safety_doc \
71+ -Wclippy::missing_docs_in_private_items \
72+ -Wmissing_docs \
73+ 2>&1)
74+ echo "$WARNINGS"
75+ AWKSTR='/warning: `.+` \(lib\) generated [0-9]+ warnings?/ { print $3 ": " $7 }'
76+ WARNINGS=$(echo "$WARNINGS" | awk -F"[\` ]" "$AWKSTR" | sort)
77+ echo "TARGET_WARNINGS<<$EOF" >> "$GITHUB_OUTPUT"
78+ echo "$WARNINGS" >> "$GITHUB_OUTPUT"
79+ echo "$EOF" >> "$GITHUB_OUTPUT"
80+
81+ - name : Compare comment coverage
82+ run : |
83+ PR_WARNINGS="${{steps.missing_docs_warnings_pr.outputs.PR_WARNINGS}}"
84+ TARGET_WARNINGS="${{ steps.missing_docs_warnings_target.outputs.TARGET_WARNINGS }}"
85+ readarray -t missing_docs_warnings_pr_arr <<< "$PR_WARNINGS"
86+ readarray -t missing_docs_warnings_target_arr <<< "$TARGET_WARNINGS"
87+ for pr_warnings_line in "${missing_docs_warnings_pr_arr[@]}"
88+ do
89+ # Extract the libname and number of warnings from the line
90+ IFS=': ' read -r libname nwarnings_pr <<< "$pr_warnings_line"
91+ # Look for the libname in the target warnings
92+ target_warning_line=""
93+ for target_warnings_line in "${missing_docs_warnings_target_arr[@]}"
94+ do
95+ if [[ $target_warnings_line == "$libname:"* ]]; then
96+ target_warning_line=$target_warnings_line
97+ break
98+ fi
99+ done
100+
101+ if [ -z "$target_warning_line" ]
102+ then
103+ echo "New warnings found for \`${libname}\`"
104+ exit 1
105+ fi
106+
107+ # Find the number of warnings for the target branch
108+ IFS=': ' read -r _ nwarnings_target <<< "$target_warning_line"
109+
110+ # Compare the values
111+ if [ "$nwarnings_target" -gt "$nwarnings_pr" ]
112+ then
113+ echo "Too many warnings for \`${libname}\` (${nwarnings_pr}): must be less than $nwarnings_target"
114+ exit 1
115+ fi
116+ done
0 commit comments