Skip to content

Commit b577952

Browse files
committed
YETUS-1145. add rstcheck
1 parent 171aada commit b577952

5 files changed

Lines changed: 202 additions & 0 deletions

File tree

asf-site-src/source/documentation/in-progress/precommit/index.html.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ Language Support, Licensing, and more:
148148
* [Perl::Critic](plugins/perlcritic)
149149
* [pylint](plugins/pylint)
150150
* [revive](plugins/revive)
151+
* [rstcheck](plugins/rstcheck)
151152
* [rubocop](plugins/rubocop)
152153
* [shellcheck](plugins/shellcheck)
153154
* [SpotBugs](plugins/spotbugs)
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<!---
2+
Licensed to the Apache Software Foundation (ASF) under one
3+
or more contributor license agreements. See the NOTICE file
4+
distributed with this work for additional information
5+
regarding copyright ownership. The ASF licenses this file
6+
to you under the Apache License, Version 2.0 (the
7+
"License"); you may not use this file except in compliance
8+
with the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing,
13+
software distributed under the License is distributed on an
14+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
KIND, either express or implied. See the License for the
16+
specific language governing permissions and limitations
17+
under the License.
18+
-->
19+
20+
# Name
21+
22+
rstcheck
23+
24+
# Category
25+
26+
Test
27+
28+
# Description
29+
30+
Runs [rstcheck](https://github.com/myint/rstcheck) when a reStructuredText (.rst) file is found.
31+
32+
# Environment Variables
33+
34+
None
35+
36+
# Options
37+
38+
| Option | Notes |
39+
|:---------|:------|
40+
| `--rstcheck=<file>` | path to `rstcheck` executable if it is not on the path |
41+
42+
# Docker Notes
43+
44+
None
45+
46+
# Developer Notes
47+
48+
None
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
#!/usr/bin/env bash
2+
# Licensed to the Apache Software Foundation (ASF) under one or more
3+
# contributor license agreements. See the NOTICE file distributed with
4+
# this work for additional information regarding copyright ownership.
5+
# The ASF licenses this file to You under the Apache License, Version 2.0
6+
# (the "License"); you may not use this file except in compliance with
7+
# the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# SHELLDOC-IGNORE
18+
19+
add_test_type rstcheck
20+
21+
RSTCHECK_TIMER=0
22+
23+
RSTCHECK=${RSTCHECK:-$(command -v rstcheck 2>/dev/null)}
24+
25+
function rstcheck_usage
26+
{
27+
yetus_add_option "--rstcheck=<file>" "path to rstcheck executable"
28+
}
29+
30+
function rstcheck_parse_args
31+
{
32+
local i
33+
34+
for i in "$@"; do
35+
case ${i} in
36+
--rstcheck=*)
37+
RSTCHECK=${i#*=}
38+
delete_parameter "${i}"
39+
;;
40+
esac
41+
done
42+
}
43+
44+
function rstcheck_filefilter
45+
{
46+
local filename=$1
47+
48+
if [[ ${filename} =~ \.rst$ ]]; then
49+
add_test rstcheck
50+
fi
51+
}
52+
53+
function rstcheck_precheck
54+
{
55+
if ! verify_command rstcheck "${RSTCHECK}"; then
56+
add_vote_table_v2 0 rstcheck "" "rstcheck was not available."
57+
delete_test rstcheck
58+
return 0
59+
fi
60+
}
61+
62+
function rstcheck_exec
63+
{
64+
declare i
65+
declare repostatus=$1
66+
declare output="${PATCH_DIR}/${repostatus}-rstcheck-result.txt"
67+
68+
pushd "${BASEDIR}" >/dev/null || return 1
69+
70+
for i in "${CHANGED_FILES[@]}"; do
71+
if [[ ${i} =~ \.rst$ ]]; then
72+
if [[ -f ${i} ]]; then
73+
"${RSTCHECK}" "${i}" >> "${output}" 2>&1
74+
fi
75+
fi
76+
done
77+
78+
popd >/dev/null || return 1
79+
return 0
80+
}
81+
82+
function rstcheck_preapply
83+
{
84+
declare i
85+
86+
if ! verify_needed_test rstcheck; then
87+
return 0
88+
fi
89+
90+
big_console_header "rstcheck plugin: ${PATCH_BRANCH}"
91+
92+
start_clock
93+
94+
rstcheck_exec branch
95+
96+
RSTCHECK_TIMER=$(stop_clock)
97+
return 0
98+
}
99+
100+
## @description Wrapper to call error_calcdiffs
101+
## @audience private
102+
## @stability evolving
103+
## @replaceable no
104+
## @param branchlog
105+
## @param patchlog
106+
## @return differences
107+
function rstcheck_calcdiffs
108+
{
109+
error_calcdiffs "$@"
110+
}
111+
112+
function rstcheck_postapply
113+
{
114+
if ! verify_needed_test rstcheck; then
115+
return 0
116+
fi
117+
118+
big_console_header "rstcheck plugin: ${BUILDMODE}"
119+
120+
start_clock
121+
122+
# add our previous elapsed to our new timer
123+
# by setting the clock back
124+
offset_clock "${RSTCHECK_TIMER}"
125+
126+
rstcheck_exec patch
127+
128+
# shellcheck disable=SC2016
129+
RSTCHECK_VERSION=$("${RSTCHECK}" --version | "${AWK}" '{print $NF}')
130+
add_version_data rstcheck "${RSTCHECK_VERSION}"
131+
132+
root_postlog_compare \
133+
rstcheck \
134+
"${PATCH_DIR}/branch-rstcheck-result.txt" \
135+
"${PATCH_DIR}/patch-rstcheck-result.txt"
136+
}
137+
138+
function rstcheck_postcompile
139+
{
140+
declare repostatus=$1
141+
142+
if [[ "${repostatus}" = branch ]]; then
143+
rstcheck_preapply
144+
else
145+
rstcheck_postapply
146+
fi
147+
}

precommit/src/main/shell/test-patch-docker/Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ ARG PY3_ASTROID_VERSION=2.11.2
317317
ARG PY3_CODESPELL_VERSION=2.1.0
318318
ARG PY3_DETECT_SECRETS=1.2.0
319319
ARG PY3_DOCKER_COMPOSE=1.29.2
320+
ARG PY3_RSTCHECK_VERSION=5.0.0
320321
ARG PY3_PYLINT_VERSION=2.13.4
321322
ARG PY3_YAMLLINT_VERSION=1.26.3
322323
# hadolint ignore=DL3008
@@ -350,6 +351,7 @@ RUN apt-get -q update && apt-get -q install --no-install-recommends -y \
350351
detect-secrets==$PY3_DETECT_SECRETS \
351352
docker-compose==$PY3_DOCKER_COMPOSE \
352353
pylint==$PY3_PYLINT_VERSION \
354+
rstcheck==$PY3_RSTCHECK_VERSION \
353355
yamllint==$PY3_YAMLLINT_VERSION \
354356
&& rm -rf /root/.cache \
355357
&& mv /usr/local/bin/pylint /usr/local/bin/pylint3 \
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
hello
2+
=====
3+
4+
**Apache Yetus** is here!

0 commit comments

Comments
 (0)