-
Notifications
You must be signed in to change notification settings - Fork 2
134 lines (120 loc) · 4.67 KB
/
comment_coverage.yaml
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# This workflow should enforce monotonically increasing comment coverage
on: [pull_request]
name: Comment Coverage
env:
CARGO_TERM_COLOR: always
jobs:
check-lint-build-stable:
name: Comment Coverage (stable)
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- name: Install Protoc
uses: arduino/setup-protoc@v2
- name: Install latest stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
components: rustfmt, clippy
override: true
target: x86_64-pc-windows-gnu
- name: Rust Cache
uses: Swatinem/[email protected]
- name: Checkout PR branch
uses: actions/checkout@v2
#- name: Missing docs warnings (PR)
# id: missing_docs_warnings_pr
# run: |
# cargo -q clippy --message-format=short -- \
# -Aclippy::all \
# -Wclippy::missing_errors_doc \
# -Wclippy::missing_panics_doc \
# -Wclippy::missing_safety_doc \
# -Wclippy::missing_docs_in_private_items \
# -Wmissing_docs \
# 2>&1 \
# | awk -F"[\` ]" \
# '/warning: `.+?` \(lib\) generated [0-9]+ warning[s]?/ { print $3 ": " $7 }' \
# | sort \
# | echo
- name: Checkout target branch
uses: actions/checkout@v2
with:
ref: ${{ github.base_ref }}
- name: Missing docs warnings (Target)
id: missing_docs_warnings_target
run: |
# use a random EOF, as per GitHub security recommendations
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
WARNINGS0=$(\
cargo -q clippy --message-format=short -- \
-Aclippy::all \
-Wclippy::missing_errors_doc \
-Wclippy::missing_panics_doc \
-Wclippy::missing_safety_doc \
-Wclippy::missing_docs_in_private_items \
-Wmissing_docs \
2>&1)
AWKSTR='/warning: `.+`/ { print $0 }'
WARNINGS1=$(echo "$WARNINGS0" | awk "$AWKSTR")
WARNINGS="$(\
cargo -q clippy --message-format=short -- \
-Aclippy::all \
-Wclippy::missing_errors_doc \
-Wclippy::missing_panics_doc \
-Wclippy::missing_safety_doc \
-Wclippy::missing_docs_in_private_items \
-Wmissing_docs \
2>&1 \
| awk -F"[\` ]" \
'/warning: `.+` \(lib\) generated [0-9]+ warnings?/ { print $3 ": " $7 }' \
| sort)"
echo "TARGET_WARNINGS<<$EOF" >> "$GITHUB_OUTPUT"
echo "$WARNINGS" >> "$GITHUB_OUTPUT"
echo "$EOF" >> "$GITHUB_OUTPUT"
echo "abc"
echo "${WARNINGS}"
echo "$WARNINGS"
WARNINGS="ABCDEF"
echo "${WARNINGS}"
echo "$WARNINGS"
echo "${WARNINGS0}"
echo "$AWKSTR"
echo "${WARNINGS1}"
echo "0000"
- name: Compare comment coverage
run: |
echo "test abc"
echo "${{ env.target_warnings }}"
echo "${{ env.TARGET_WARNINGS }}"
echo "${{ steps.missing_docs_warnings_target.outputs.TARGET_WARNINGS }}"
IFS=$'\n' read -rd '' -a missing_docs_warnings_pr_arr <<< "${{steps.missing_docs_warnings_pr.outcome}}"
IFS=$'\n' read -rd '' -a missing_docs_warnings_target_arr <<< "${{steps.missing_docs_warnings_target.outcome}}"
for pr_warnings_line in "${missing_docs_warnings_pr_arr[@]}"
do
# Extract the libname and number of warnings from the line
IFS=': ' read -r libname nwarnings_pr <<< "$pr_warnings_line"
# Look for the libname in the target warnings
target_warning_line=""
for target_warnings_line in "${missing_docs_warnings_target_arr[@]}"
do
if [[ $target_warnings_line == "$libname:"* ]]; then
target_warning_line=$target_warnings_line
break
fi
done
if [ -z "$target_warning_line" ]
then
echo "New warnings found for \`${libname}\`"
exit 1
fi
# Find the number of warnings for the target branch
IFS=': ' read -r _ nwarnings_target <<< "$target_warning_line"
# Compare the values
if [ "$nwarnings_target" -ge "$nwarnings_pr" ]
then
echo "Too many warnings for \`${libname}\` (${nwarnings_pr}): must be less than $nwarnings_target"
exit 1
fi
done