Skip to content

Commit a86943c

Browse files
committed
comment coverage
1 parent f23f8d0 commit a86943c

1 file changed

Lines changed: 102 additions & 0 deletions

File tree

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
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+
cargo -q clippy --message-format=short -- \
38+
-Aclippy::all \
39+
-Wclippy::missing_errors_doc \
40+
-Wclippy::missing_panics_doc \
41+
-Wclippy::missing_safety_doc \
42+
-Wclippy::missing_docs_in_private_items \
43+
-Wmissing_docs \
44+
2>&1 \
45+
| awk -F"[\` ]" \
46+
'/warning: `.+?` \(lib\) generated [0-9]+ warning[s]?/ { print $3 ": " $7 }' \
47+
| sort
48+
49+
- name: Checkout target branch
50+
uses: actions/checkout@v2
51+
with:
52+
ref: ${{ github.base_ref }}
53+
54+
- name: Missing docs warnings (Target)
55+
id: missing_docs_warnings_target
56+
run: |
57+
cargo -q clippy --message-format=short -- \
58+
-Aclippy::all \
59+
-Wclippy::missing_errors_doc \
60+
-Wclippy::missing_panics_doc \
61+
-Wclippy::missing_safety_doc \
62+
-Wclippy::missing_docs_in_private_items \
63+
-Wmissing_docs \
64+
2>&1 \
65+
| awk -F"[\` ]" \
66+
'/warning: `.+?` \(lib\) generated [0-9]+ warning[s]?/ { print $3 ": " $7 }' \
67+
| sort
68+
69+
- name: Compare comment coverage
70+
run: |
71+
IFS=$'\n' read -rd '' -a missing_docs_warnings_pr_arr <<< "${{steps.missing_docs_warnings_pr.outcome}}"
72+
IFS=$'\n' read -rd '' -a missing_docs_warnings_target_arr <<< "${{steps.missing_docs_warnings_target.outcome}}"
73+
for pr_warnings_line in "${missing_docs_warnings_pr_arr[@]}"
74+
do
75+
# Extract the libname and number of warnings from the line
76+
IFS=': ' read -r libname nwarnings_pr <<< "$pr_warnings_line"
77+
# Look for the libname in the target warnings
78+
target_warning_line=""
79+
for target_warnings_line in "${missing_docs_warnings_target_arr[@]}"
80+
do
81+
if [[ $target_warnings_line == "$libname:"* ]]; then
82+
target_warning_line=$target_warnings_line
83+
break
84+
fi
85+
done
86+
87+
if [ -z "$target_warning_line" ]
88+
then
89+
echo "New warnings found for \`${libname}\`"
90+
exit 1
91+
fi
92+
93+
# Find the number of warnings for the target branch
94+
IFS=': ' read -r _ nwarnings_target <<< "$target_warning_line"
95+
96+
# Compare the values
97+
if [ "$nwarnings_target" -ge "$nwarnings_pr" ]
98+
then
99+
echo "Too many warnings for \`${libname}\` (${nwarnings_pr}): must be less than $nwarnings_target"
100+
exit 1
101+
fi
102+
done

0 commit comments

Comments
 (0)