Skip to content

Commit ee2b4f8

Browse files
slarsewoutersmeenk
authored andcommitted
chore: Add CI check for method/constructor Javadoc quality (INRIA#3907)
1 parent 59d2316 commit ee2b4f8

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed

.github/workflows/tests.yml

+4
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ jobs:
109109
name: Extra checks
110110
steps:
111111
- uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f # v2.3.4
112+
with:
113+
fetch-depth: 0
112114
- uses: actions/setup-java@8764a52df183aa0ccea74521dfd9d506ffc7a19a # v2.0.0
113115
with:
114116
java-version: 15
@@ -132,6 +134,8 @@ jobs:
132134
run: mv chore/logback.xml src/test/resources/
133135
- name: Run extra checks
134136
run: ./chore/ci-extra.sh
137+
- name: Run Javadoc quality check
138+
run: ./chore/ci-checkstyle-javadoc.sh
135139

136140
sorald-buildbreaker:
137141
runs-on: ubuntu-latest

chore/ci-checkstyle-javadoc.sh

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/bin/bash
2+
#
3+
# This script computes the amount of method Javadoc errors found by
4+
# checkstyle and compares with the master branch. If the amount of
5+
# errors have increased relative to master, it exits non-zero.
6+
#
7+
# WARNING: Running this script resets the state of the repository to the
8+
# latest commit, do NOT run this locally if you have any uncommitted changes.
9+
10+
set -o errexit
11+
set -o nounset
12+
set -o pipefail
13+
14+
COMPARE_BRANCH="master"
15+
JAVADOC_CHECKSTYLE_CONFIG="__SPOON_CI_checkstyle-javadoc.xml"
16+
17+
if [[ $(git branch --show-current) == "$COMPARE_BRANCH" ]]; then
18+
# nothing to compare, we're on the main branch
19+
exit 0
20+
fi
21+
22+
function cleanup() {
23+
rm "$JAVADOC_CHECKSTYLE_CONFIG"
24+
}
25+
26+
trap cleanup EXIT
27+
28+
function create_checkstyle_config() {
29+
echo '<?xml version="1.0"?>
30+
<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.2//EN" "http://www.puppycrawl.com/dtds/configuration_1_2.dtd">
31+
<module name="Checker">
32+
<module name="TreeWalker">
33+
<module name="JavadocMethod">
34+
<property name="scope" value="public"/>
35+
</module>
36+
</module>
37+
</module>' > "$JAVADOC_CHECKSTYLE_CONFIG"
38+
}
39+
40+
function compute_num_errors() {
41+
echo $(mvn -B checkstyle:check --fail-never -Dcheckstyle.config.location="$JAVADOC_CHECKSTYLE_CONFIG" \
42+
| grep -Po '(?<=There are )\d+(?= errors reported by Checkstyle)')
43+
}
44+
45+
function main() {
46+
cd "$(git rev-parse --show-toplevel)"
47+
48+
# compute compare score
49+
git checkout --force "$COMPARE_BRANCH" &> /dev/null
50+
create_checkstyle_config
51+
compare_num_errors=`compute_num_errors`
52+
53+
# compute current score
54+
git checkout --force - &> /dev/null
55+
create_checkstyle_config
56+
current_num_errors=`compute_num_errors`
57+
58+
echo "JAVADOC QUALITY SCORE (lower is better)
59+
Compare: $compare_num_errors
60+
Current: $current_num_errors
61+
"
62+
63+
if [[ -z $compare_num_errors ]]; then
64+
echo "Failed to compute compare score";
65+
exit 1;
66+
elif [[ -z $current_num_errors ]]; then
67+
echo "Failed to compute current score";
68+
exit 1;
69+
elif [[ $compare_num_errors < $current_num_errors ]]; then
70+
echo "Javadoc quality has deteriorated!"
71+
exit 1
72+
else
73+
echo "Javadoc quality has not deteriorated"
74+
fi
75+
}
76+
77+
main

0 commit comments

Comments
 (0)