DO NOT MERGE: testing code coverage CI #33
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) | |
# check that $0 is not getting a previous command output | |
ABCDEF="ABCDEF" | |
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" | |
echo "$WARNINGS0" | awk "${AWKSTR}" | |
- 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 |