浏览代码

Meta: Integrate Shellcheck into Travis

lint-shell-scripts searches over the repository looking for shell
scripts. On those found, shellcheck is run against them. If any linting
fails print those warnings and exit with a non-zero exit code.

Run this script automatically in Travis.
Shannon Booth 5 年之前
父节点
当前提交
084e67f267
共有 2 个文件被更改,包括 28 次插入1 次删除
  1. 2 1
      .travis.yml
  2. 26 0
      Meta/lint-shell-scripts.sh

+ 2 - 1
.travis.yml

@@ -22,7 +22,7 @@ notifications:
 before_install:
 - sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
 - sudo apt-get update -qq
-- sudo apt-get install g++-8 libstdc++-8-dev
+- sudo apt-get install g++-8 libstdc++-8-dev shellcheck
 - sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-8 90
 - sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 90
 - sudo apt-get install -y libmpfr-dev libmpc-dev libgmp-dev
@@ -33,3 +33,4 @@ script:
 - ./BuildIt.sh
 - cd ../Kernel
 - ./makeall.sh
+- ../Meta/lint-shell-scripts.sh

+ 26 - 0
Meta/lint-shell-scripts.sh

@@ -0,0 +1,26 @@
+#!/bin/bash
+set -e pipefail
+
+script_path=$(cd -P -- "$(dirname -- "$0")" && pwd -P)
+cd "$script_path/.."
+
+ERRORS=()
+
+for f in $(find . -path ./Root -prune -o \
+    -path ./Ports -prune -o \
+    -path ./.git -prune -o \
+    -path ./Toolchain -prune -o \
+    -type f | sort -u); do
+    if file "$f" | grep --quiet shell; then
+        {
+            shellcheck "$f" && echo -e "[\033[0;32mOK\033[0m]: sucessfully linted $f"
+        } || {
+            ERRORS+=("$f")
+        }
+fi
+done
+
+if (( ${#ERRORS[@]} )); then
+    echo "Files failing shellcheck: ${ERRORS[*]}"
+    exit 1
+fi