diff options
-rwxr-xr-x | .ci/check-shell.sh | 70 | ||||
-rw-r--r-- | .ci/functions.sh | 9 | ||||
-rw-r--r-- | .ci/script-list.txt | 36 | ||||
-rw-r--r-- | .travis.yml | 28 |
4 files changed, 141 insertions, 2 deletions
diff --git a/.ci/check-shell.sh b/.ci/check-shell.sh new file mode 100755 index 00000000..a4ea3c52 --- /dev/null +++ b/.ci/check-shell.sh @@ -0,0 +1,70 @@ +#!/bin/bash + +. ./.ci/functions.sh + +# ------------ # +# FILE PATHS # +# ------------ # + +# https://medium.com/@joey_9999/how-to-only-lint-files-a-git-pull-request-modifies-3f02254ec5e0 +# get names of files from PR (excluding deleted files) +# TRAVIS_COMMIT_RANGE - HEAD of destination branch ... HEAD of PR branch +git diff --name-only --diff-filter=db "${TRAVIS_COMMIT_RANGE}" > ../pr-changes.txt + +# Find modified shell scripts +readarray list_of_changes < <(grep "^[^#]" ../pr-changes.txt) +list_of_changed_scripts=() +for file in "${list_of_changes[@]}"; do + # https://stackoverflow.com/questions/19345872/how-to-remove-a-newline-from-a-string-in-bash + # Remove new line and add ./ at the beginning + is_it_script "$file" && list_of_changed_scripts+=("./${file//[$'\t\r\n ']}") +done + +echo "Changed shell scripts:" +echo "${list_of_changed_scripts[@]}" +echo "------------" + +# ------------ # +# SHELLCHECK # +# ------------ # + +# sed part is to edit shellcheck output so csdiff/csgrep knows it is shellcheck output (--format=gcc) +shellcheck --format=gcc "${list_of_changed_scripts[@]}" | sed -e 's|$| <--[shellcheck]|' > ../pr-br-shellcheck.err + +# make destination branch +[[ ${TRAVIS_COMMIT_RANGE} =~ ^([0-9|a-f]*?)\. ]] && git checkout -b ci_br_dest "${BASH_REMATCH[1]}" + +shellcheck --format=gcc "${list_of_changed_scripts[@]}" | sed -e 's|$| <--[shellcheck]|' > ../dest-br-shellcheck.err + +# ------------ # +# VALIDATION # +# ------------ # + +exitstatus=0 + +# Check output for Fixes +csdiff --fixed "../dest-br-shellcheck.err" "../pr-br-shellcheck.err" > ../fixes.log +if [ "$(cat ../fixes.log | wc -l)" -ne 0 ]; then + echo "Fixed bugs:" + csgrep ../fixes.log + echo "------------" +else + echo "No Fixes!" + echo "------------" +fi + +# Check output for added bugs +csdiff --fixed "../pr-br-shellcheck.err" "../dest-br-shellcheck.err" > ../bugs.log +if [ "$(cat ../bugs.log | wc -l)" -ne 0 ]; then + echo "Added bugs, NEED INSPECTION:" + csgrep ../bugs.log + echo "------------" + exitstatus=1 +else + echo "No bugs added Yay!" + echo "------------" + exitstatus=0 +fi + +exit $exitstatus + diff --git a/.ci/functions.sh b/.ci/functions.sh new file mode 100644 index 00000000..300f92df --- /dev/null +++ b/.ci/functions.sh @@ -0,0 +1,9 @@ +# Function to check whether input param is on list of shell scripts +# $1 - <string> absolute path to file +is_it_script () { + [ $# -eq 0 ] && return 1 + + readarray list_of_scripts < ./.ci/script-list.txt + echo "${list_of_scripts[@]}" | grep --silent "$1" && return 0 +} + diff --git a/.ci/script-list.txt b/.ci/script-list.txt new file mode 100644 index 00000000..7323ceb7 --- /dev/null +++ b/.ci/script-list.txt @@ -0,0 +1,36 @@ +# Tracker of all shell scripts in this repository +etc/rc.d/init.d/functions +etc/rc.d/init.d/network +network-scripts/ifdown-bnep +network-scripts/ifdown-ippp +network-scripts/ifdown-post +network-scripts/ifdown-sit +network-scripts/ifup +network-scripts/ifup-bnep +network-scripts/ifup-eth +network-scripts/ifup-ipv6 +network-scripts/ifup-plusb +network-scripts/ifup-routes +network-scripts/ifup-tunnel +network-scripts/init.ipv6-global +network-scripts/network-functions-ipv6 +network-scripts/ifdown +network-scripts/ifdown-eth +network-scripts/ifdown-ipv6 +network-scripts/ifdown-routes +network-scripts/ifdown-tunnel +network-scripts/ifup-aliases +network-scripts/ifup-ctc +network-scripts/ifup-ippp +network-scripts/ifup-plip +network-scripts/ifup-post +network-scripts/ifup-sit +network-scripts/ifup-wireless +network-scripts/network-functions +usr/libexec/import-state +usr/libexec/loadmodules +usr/libexec/netconsole +usr/libexec/readonly-root +usr/sbin/service +.ci/check-shell.sh +.ci/functions.sh diff --git a/.travis.yml b/.travis.yml index b75e9141..ee431240 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,11 +2,35 @@ sudo: false dist: trusty -language: c -script: make all && make install DESTDIR=/tmp/initscripts +git: + depth: 2 + +## Source - 01: https://github.com/kdudka/csdiff/blob/master/.travis.yml +before_install: + - sudo apt-get update + - sudo apt-get install apt-transport-https + - echo "deb https://kdudka.fedorapeople.org/csbuild trusty contrib" | sudo tee -a /etc/apt/sources.list + - sudo apt-get update + +install: + - sudo apt-get install cmake help2man libboost-dev libboost-filesystem-dev libboost-program-options-dev libboost-python-dev libboost-regex-dev tree + - sudo apt-get install -y --force-yes csbuild +## End - 01 # We need to install the libpopt dependency without sudo: addons: apt: packages: libpopt-dev + +matrix: + include: + - language: shell + script: + - 'if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then bash ./.ci/check-shell.sh; fi' + - language: c + script: make all && make install DESTDIR=/tmp/initscripts + +notifications: + email: false + |