You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@yetus.apache.org by aw...@apache.org on 2018/12/13 16:11:36 UTC

[2/2] yetus git commit: YETUS-714. Support for yamllint

YETUS-714. Support for yamllint

Signed-off-by: Allen Wittenauer <aw...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/yetus/repo
Commit: http://git-wip-us.apache.org/repos/asf/yetus/commit/492a20e0
Tree: http://git-wip-us.apache.org/repos/asf/yetus/tree/492a20e0
Diff: http://git-wip-us.apache.org/repos/asf/yetus/diff/492a20e0

Branch: refs/heads/master
Commit: 492a20e05f3cd6283ac1b821d7068aa3b72268c0
Parents: 60745a0
Author: Allen Wittenauer <aw...@apache.org>
Authored: Sun Oct 21 09:55:29 2018 -0700
Committer: Allen Wittenauer <aw...@apache.org>
Committed: Thu Dec 13 08:07:19 2018 -0800

----------------------------------------------------------------------
 .hadolint.yaml                                  |   2 +-
 .rubocop.yml                                    |  15 ++
 asf-site-src/data/versions.yml                  |   1 +
 .../src/main/shell/test-patch-docker/Dockerfile |   4 +-
 .../src/main/shell/test-patch.d/yamllint.sh     | 164 +++++++++++++++++++
 5 files changed, 183 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/yetus/blob/492a20e0/.hadolint.yaml
----------------------------------------------------------------------
diff --git a/.hadolint.yaml b/.hadolint.yaml
index 6645586..3cdfb90 100644
--- a/.hadolint.yaml
+++ b/.hadolint.yaml
@@ -12,6 +12,6 @@
 # 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.
-
+---
 ignored:
   - DL3008

http://git-wip-us.apache.org/repos/asf/yetus/blob/492a20e0/.rubocop.yml
----------------------------------------------------------------------
diff --git a/.rubocop.yml b/.rubocop.yml
index 2fd1917..7858c99 100644
--- a/.rubocop.yml
+++ b/.rubocop.yml
@@ -1,3 +1,18 @@
+# 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.
+---
 Metrics/LineLength:
   Max: 100
 Metrics/MethodLength:

http://git-wip-us.apache.org/repos/asf/yetus/blob/492a20e0/asf-site-src/data/versions.yml
----------------------------------------------------------------------
diff --git a/asf-site-src/data/versions.yml b/asf-site-src/data/versions.yml
index e0f0d2a..068d1da 100644
--- a/asf-site-src/data/versions.yml
+++ b/asf-site-src/data/versions.yml
@@ -14,6 +14,7 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
+---
 releases:
   - '0.6.0'
   - '0.7.0'

http://git-wip-us.apache.org/repos/asf/yetus/blob/492a20e0/precommit/src/main/shell/test-patch-docker/Dockerfile
----------------------------------------------------------------------
diff --git a/precommit/src/main/shell/test-patch-docker/Dockerfile b/precommit/src/main/shell/test-patch-docker/Dockerfile
index 080e26c..981cb5f 100644
--- a/precommit/src/main/shell/test-patch-docker/Dockerfile
+++ b/precommit/src/main/shell/test-patch-docker/Dockerfile
@@ -144,7 +144,7 @@ RUN pip3 install -v pylint==2.1.1
 RUN mv /usr/local/bin/pylint /usr/local/bin/pylint3
 
 ######
-# Install python2 and pylint2
+# Install python, pylint2, and yamllint
 ######
 RUN apt-get -q update && apt-get -q install --no-install-recommends -y python \
     python2.7 \
@@ -155,7 +155,7 @@ RUN apt-get -q update && apt-get -q install --no-install-recommends -y python \
     python-dev \
     && apt-get clean \
     && rm -rf /var/lib/apt/lists/*
-RUN pip2 install -v pylint==1.9.2 python-dateutil==2.7.3
+RUN pip2 install -v pylint==1.9.2 python-dateutil==2.7.3 yamllint==1.12.1
 RUN mv /usr/local/bin/pylint /usr/local/bin/pylint2
 
 #####

http://git-wip-us.apache.org/repos/asf/yetus/blob/492a20e0/precommit/src/main/shell/test-patch.d/yamllint.sh
----------------------------------------------------------------------
diff --git a/precommit/src/main/shell/test-patch.d/yamllint.sh b/precommit/src/main/shell/test-patch.d/yamllint.sh
new file mode 100755
index 0000000..b3c4a5b
--- /dev/null
+++ b/precommit/src/main/shell/test-patch.d/yamllint.sh
@@ -0,0 +1,164 @@
+#!/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.
+
+# no public APIs here
+# SHELLDOC-IGNORE
+
+add_test_type yamllint
+
+YAMLLINT_TIMER=0
+YAMLLINT=${YAMLLINT:-$(command -v yamllint 2>/dev/null)}
+
+# files that are going to get yamllint'd
+YAMLLINT_CHECKFILES=()
+
+function yamllint_filefilter
+{
+  declare filename=$1
+
+  if [[ ${filename} =~ \.yaml$ ]] ||
+     [[ ${filename} =~ \.yml$ ]]; then
+    add_test yamllint
+    yetus_add_array_element YAMLLINT_CHECKFILES "${filename}"
+  fi
+}
+
+function yamllint_precheck
+{
+  if ! verify_command "yamllint" "${YAMLLINT}"; then
+    add_vote_table 0 yamllint "yamllint was not available."
+    delete_test yamllint
+  fi
+
+
+}
+
+function yamllint_logic
+{
+  declare repostatus=$1
+  declare i
+  declare fn
+  declare output
+
+  pushd "${BASEDIR}" >/dev/null || return 1
+
+  for i in "${YAMLLINT_CHECKFILES[@]}"; do
+    if [[ -f "${i}" ]]; then
+      fn=""
+      while read -r; do
+        if [[ -z "${fn}" ]]; then
+          fn=$REPLY
+        elif [[ -n "${REPLY}" ]]; then
+          # (space)line:col(space)error/warning(space)text
+          output=$(echo "${REPLY}" | awk '{$1=$1":"; $2=$2":"; print $0;}')
+          # fn:line:col:(space)error/warning:(space)text
+          echo "${fn}:${output}" >> "${PATCH_DIR}/${repostatus}-yamllint-result.txt"
+        fi
+      done < <("${YAMLLINT}" "${i}")
+    fi
+  done
+  popd > /dev/null || return 1
+}
+
+function yamllint_preapply
+{
+  if ! verify_needed_test yamllint; then
+    return 0
+  fi
+
+  big_console_header "yamllint plugin: ${PATCH_BRANCH}"
+
+  start_clock
+
+  yamllint_logic branch
+
+  # keep track of how much as elapsed for us already
+  YAMLLINT_TIMER=$(stop_clock)
+  return 0
+}
+
+function yamllint_calcdiffs
+{
+  column_calcdiffs "$@"
+}
+
+function yamllint_postapply
+{
+  declare i
+  declare numPrepatch
+  declare numPostpatch
+  declare diffPostpatch
+  declare fixedpatch
+  declare statstring
+
+  if ! verify_needed_test yamllint; then
+    return 0
+  fi
+
+  big_console_header "yamllint plugin: ${BUILDMODE}"
+
+  start_clock
+
+  # add our previous elapsed to our new timer
+  # by setting the clock back
+  offset_clock "${YAMLLINT_TIMER}"
+
+  yamllint_logic patch
+
+  calcdiffs \
+    "${PATCH_DIR}/branch-yamllint-result.txt" \
+    "${PATCH_DIR}/patch-yamllint-result.txt" \
+    yamllint \
+      > "${PATCH_DIR}/diff-patch-yamllint.txt"
+
+  # shellcheck disable=SC2016
+  numPrepatch=$(wc -l "${PATCH_DIR}/branch-yamllint-result.txt" | "${AWK}" '{print $1}')
+
+  # shellcheck disable=SC2016
+  numPostpatch=$(wc -l "${PATCH_DIR}/patch-yamllint-result.txt" | "${AWK}" '{print $1}')
+
+  # shellcheck disable=SC2016
+  diffPostpatch=$(wc -l "${PATCH_DIR}/diff-patch-yamllint.txt" | "${AWK}" '{print $1}')
+
+
+  ((fixedpatch=numPrepatch-numPostpatch+diffPostpatch))
+
+  statstring=$(generic_calcdiff_status "${numPrepatch}" "${numPostpatch}" "${diffPostpatch}" )
+
+  if [[ ${diffPostpatch} -gt 0 ]] ; then
+    add_vote_table -1 yamllint "${BUILDMODEMSG} ${statstring}"
+    add_footer_table yamllint "@@BASE@@/diff-patch-yamllint.txt"
+    bugsystem_linecomments "yamllint" "${PATCH_DIR}/diff-patch-yamllint.txt"
+    return 1
+  elif [[ ${fixedpatch} -gt 0 ]]; then
+    add_vote_table +1 yamllint "${BUILDMODEMSG} ${statstring}"
+    return 0
+  fi
+
+  add_vote_table +1 yamllint "There were no new yamllint issues."
+  return 0
+}
+
+function yamllint_postcompile
+{
+  declare repostatus=$1
+
+  if [[ "${repostatus}" = branch ]]; then
+    yamllint_preapply
+  else
+    yamllint_postapply
+  fi
+}