Skip to content

Commit

Permalink
YETUS-1145. add rstcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
aw-was-here committed Apr 29, 2022
1 parent 171aada commit b577952
Show file tree
Hide file tree
Showing 5 changed files with 202 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ Language Support, Licensing, and more:
* [Perl::Critic](plugins/perlcritic)
* [pylint](plugins/pylint)
* [revive](plugins/revive)
* [rstcheck](plugins/rstcheck)
* [rubocop](plugins/rubocop)
* [shellcheck](plugins/shellcheck)
* [SpotBugs](plugins/spotbugs)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!---
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->

# Name

rstcheck

# Category

Test

# Description

Runs [rstcheck](https://github.com/myint/rstcheck) when a reStructuredText (.rst) file is found.

# Environment Variables

None

# Options

| Option | Notes |
|:---------|:------|
| `--rstcheck=<file>` | path to `rstcheck` executable if it is not on the path |

# Docker Notes

None

# Developer Notes

None
147 changes: 147 additions & 0 deletions precommit/src/main/shell/plugins.d/rstcheck.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
#!/usr/bin/env bash
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# SHELLDOC-IGNORE

add_test_type rstcheck

RSTCHECK_TIMER=0

RSTCHECK=${RSTCHECK:-$(command -v rstcheck 2>/dev/null)}

function rstcheck_usage
{
yetus_add_option "--rstcheck=<file>" "path to rstcheck executable"
}

function rstcheck_parse_args
{
local i

for i in "$@"; do
case ${i} in
--rstcheck=*)
RSTCHECK=${i#*=}
delete_parameter "${i}"
;;
esac
done
}

function rstcheck_filefilter
{
local filename=$1

if [[ ${filename} =~ \.rst$ ]]; then
add_test rstcheck
fi
}

function rstcheck_precheck
{
if ! verify_command rstcheck "${RSTCHECK}"; then
add_vote_table_v2 0 rstcheck "" "rstcheck was not available."
delete_test rstcheck
return 0
fi
}

function rstcheck_exec
{
declare i
declare repostatus=$1
declare output="${PATCH_DIR}/${repostatus}-rstcheck-result.txt"

pushd "${BASEDIR}" >/dev/null || return 1

for i in "${CHANGED_FILES[@]}"; do
if [[ ${i} =~ \.rst$ ]]; then
if [[ -f ${i} ]]; then
"${RSTCHECK}" "${i}" >> "${output}" 2>&1
fi
fi
done

popd >/dev/null || return 1
return 0
}

function rstcheck_preapply
{
declare i

if ! verify_needed_test rstcheck; then
return 0
fi

big_console_header "rstcheck plugin: ${PATCH_BRANCH}"

start_clock

rstcheck_exec branch

RSTCHECK_TIMER=$(stop_clock)
return 0
}

## @description Wrapper to call error_calcdiffs
## @audience private
## @stability evolving
## @replaceable no
## @param branchlog
## @param patchlog
## @return differences
function rstcheck_calcdiffs
{
error_calcdiffs "$@"
}

function rstcheck_postapply
{
if ! verify_needed_test rstcheck; then
return 0
fi

big_console_header "rstcheck plugin: ${BUILDMODE}"

start_clock

# add our previous elapsed to our new timer
# by setting the clock back
offset_clock "${RSTCHECK_TIMER}"

rstcheck_exec patch

# shellcheck disable=SC2016
RSTCHECK_VERSION=$("${RSTCHECK}" --version | "${AWK}" '{print $NF}')
add_version_data rstcheck "${RSTCHECK_VERSION}"

root_postlog_compare \
rstcheck \
"${PATCH_DIR}/branch-rstcheck-result.txt" \
"${PATCH_DIR}/patch-rstcheck-result.txt"
}

function rstcheck_postcompile
{
declare repostatus=$1

if [[ "${repostatus}" = branch ]]; then
rstcheck_preapply
else
rstcheck_postapply
fi
}
2 changes: 2 additions & 0 deletions precommit/src/main/shell/test-patch-docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ ARG PY3_ASTROID_VERSION=2.11.2
ARG PY3_CODESPELL_VERSION=2.1.0
ARG PY3_DETECT_SECRETS=1.2.0
ARG PY3_DOCKER_COMPOSE=1.29.2
ARG PY3_RSTCHECK_VERSION=5.0.0
ARG PY3_PYLINT_VERSION=2.13.4
ARG PY3_YAMLLINT_VERSION=1.26.3
# hadolint ignore=DL3008
Expand Down Expand Up @@ -350,6 +351,7 @@ RUN apt-get -q update && apt-get -q install --no-install-recommends -y \
detect-secrets==$PY3_DETECT_SECRETS \
docker-compose==$PY3_DOCKER_COMPOSE \
pylint==$PY3_PYLINT_VERSION \
rstcheck==$PY3_RSTCHECK_VERSION \
yamllint==$PY3_YAMLLINT_VERSION \
&& rm -rf /root/.cache \
&& mv /usr/local/bin/pylint /usr/local/bin/pylint3 \
Expand Down
4 changes: 4 additions & 0 deletions precommit/src/test/resources/i18n/∂.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
hello
=====

**Apache Yetus** is here!

0 comments on commit b577952

Please sign in to comment.