From d7bdf417bd995148594f243d3fc6bb7b712ee60d Mon Sep 17 00:00:00 2001 From: Nick Rhodes Date: Fri, 29 Mar 2019 03:46:10 +0000 Subject: [PATCH] Parallelize the Travis build process... ...and remove the Docker dependency. Just run the shell tests directly from the Travis CI container. --- .travis.yml | 34 ++++++++++------------------------ tests/01-spellcheck.sh | 10 +++++----- tests/05-shellcheck.sh | 30 +++++++++--------------------- tests/_helpers | 22 +++++++++++----------- 4 files changed, 35 insertions(+), 61 deletions(-) diff --git a/.travis.yml b/.travis.yml index 60b42f1..67ffed6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,26 +1,12 @@ +dist: xenial language: bash -notifications: - email: false -services: - - docker before_install: - - docker pull centos -script: - # Save changed files to a text file to narrow test scope - - "git remote add upstream https://github.com/rackerlabs/auter.git" - - "git fetch upstream develop:rdevelop" - # - "git diff rmaster --name-only >CHANGEDFILES" - # - "cat CHANGEDFILES" - - # Create docker image and run general code checks - - "sudo docker run --rm=true --mount type=bind,source=$(pwd),destination=/auter --name auter-test -td centos:7" - - "docker exec auter-test yum -y -q install epel-release &>/dev/null" - - "docker exec auter-test yum -y -q install findutils ShellCheck aspell aspell-en &>/dev/null" - - "docker exec auter-test /auter/tests/01-spellcheck.sh" - - "docker exec auter-test /auter/tests/05-shellcheck.sh" - - # RPM Build test - # - "$TRAVIS_BUILD_DIR/tests/10-rpmbuild.sh" - - # DEB Build test - # - "$TRAVIS_BUILD_DIR/tests/20-debuild.sh" + - sudo apt-get update + - sudo apt-get install -y aspell aspell-en +jobs: + include: + - stage: Basic Tests + name: SpellCheck + script: ./tests/01-spellcheck.sh + - name: ShellCheck + script: ./tests/05-shellcheck.sh diff --git a/tests/01-spellcheck.sh b/tests/01-spellcheck.sh index a00d282..6027a6b 100755 --- a/tests/01-spellcheck.sh +++ b/tests/01-spellcheck.sh @@ -2,7 +2,7 @@ . "$(dirname "$0")"/_helpers -if ! command -v aspell &>/devnull; then echo "apsell not installed. Aborting test"; exit 1; fi +run_cmd "Check for aspell" command -v aspell EXITCODE=0 @@ -14,15 +14,15 @@ FILELIST+=("$AUTERDIR/NEWS") FILELIST+=("$AUTERDIR/buildGuide.md") FILELIST+=("$AUTERDIR/contrib/README.md") -for FILE in "${FILELIST[@]}"; do - if aspel_out="$(aspell -a --personal="${TESTDIR}"/.aspell_auter_dictionary 2>&1 < "${FILE}")"; then +for _file in "${FILELIST[@]}"; do + if aspel_out="$(aspell -a --personal="$TESTDIR"/.aspell_auter_dictionary 2>&1 < "$_file")"; then spelling_mistakes="$(awk '/^&/{print $2}' <<< "$aspel_out")" if [[ -n "$spelling_mistakes" ]]; then - log_fail "$FILE failed SpellCheck" + log_fail "$_file failed SpellCheck" EXITCODE=1 sort <<< "$spelling_mistakes" | uniq -c else - log_success "$FILE passed SpellCheck" + log_success "$_file passed SpellCheck" fi else diff --git a/tests/05-shellcheck.sh b/tests/05-shellcheck.sh index 257f3cf..958407a 100755 --- a/tests/05-shellcheck.sh +++ b/tests/05-shellcheck.sh @@ -5,37 +5,25 @@ EXITCODE=0 # Create a list of script files to be checked. -if [[ -f "$CHANGEDFILES" ]]; then - readarray -t FILELIST < <(find "$AUTERDIR" -type f -not -path '*/\.*' | egrep "$(xargs <"$CHANGEDFILES" | tr ' ' '|')") -else - readarray -t FILELIST < <(find "$AUTERDIR" -type f -not -path '*/\.*') -fi +readarray -t FILELIST < <(find "$AUTERDIR" -type f -not -path '*/\.*') -for FILE in "${FILELIST[@]}"; do - grep -q '^#!/.*sh' "$FILE" && SCRIPTSTOTEST+=("$FILE") +for _file in "${FILELIST[@]}"; do + grep -q '^#!/.*sh' "$_file" && SCRIPTSTOTEST+=("$_file") done # SC2102 is related to https://github.com/koalaman/shellcheck/issues/682. This # was previously removed from the online checker but still exists in the # standalone package. sc_excl=("SC2102") -#sc_excl+=("SC1090 SC1091") # Can't follow source +sc_excl+=("SC1090" "SC1091") # Can't follow source #sc_excl+=("SC2181") # Check RC directly -for SCRIPT in "${SCRIPTSTOTEST[@]}"; do - # Define script specifc exclusions. Reasons should be documented as comments - # This can be done bu adding "# shellcheck disable=SC2016" to the previous line in the script - # ----------------------------------------------# - # Excluding SC2016 due to line 11 of 10-rpmbuild.sh. Expansion is specifically blocked - # [[ "${SCRIPT}" =~ 10-rpmbuild.sh ]] && sc_excl+=",SC2016" - # ----------------------------------------------# - - SHELLCHECK_OUTPUT="$(shellcheck -e "${sc_excl[@]}" "$SCRIPT")" - if [[ $? -eq 0 ]]; then - log_success "$SCRIPT passed ShellCheck" +for _script in "${SCRIPTSTOTEST[@]}"; do + if shellcheck_output="$(shellcheck -e "$(IFS=','; echo "${sc_excl[*]}")" "$_script")"; then + log_success "$_script passed ShellCheck" else - log_fail "$SCRIPT failed ShellCheck" - awk '{printf "| %s\n",$0}' <<< "$SHELLCHECK_OUTPUT" + log_fail "$_script failed ShellCheck" + awk '{printf "| %s\n",$0}' <<< "$shellcheck_output" echo "-----------------------------------------------------------------------" EXITCODE=1 fi diff --git a/tests/_helpers b/tests/_helpers index d2dc17b..2ec3657 100644 --- a/tests/_helpers +++ b/tests/_helpers @@ -5,12 +5,12 @@ grn='\033[32m' ylw='\033[33m' rst='\033[0m' -log_success () { printf "[%b OK %b] %s\n" "$grn" "$rst" "$1"; } -log_fail () { printf "[%b FAIL %b] %s\n" "$red" "$rst" "$1"; } -log_info () { printf "[%b INFO %b] %s\n" "$ylw" "$rst" "$1"; } +log_success () { printf "[%b OK %b] %s\\n" "$grn" "$rst" "$1"; } +log_fail () { printf "[%b FAIL %b] %s\\n" "$red" "$rst" "$1"; } +log_info () { printf "[%b INFO %b] %s\\n" "$ylw" "$rst" "$1"; } function quit() { -docker ps -aq | xargs docker stop + docker ps -aq | xargs docker stop exit "${1:-1}" } export -f quit @@ -18,20 +18,20 @@ export -f quit function run_cmd () { local tag="$1"; shift - if OUTPUT="$("${@}" 2>&1)"; then + if output="$("${@}" 2>&1)"; then log_success "$tag" return 0 else log_fail "$tag" - awk '{printf "| %s\n",$0}' <<< "$OUTPUT" + awk '{printf "| %s\n",$0}' <<< "$output" echo "-----------------------------------------------------------------------" quit 1 fi } export -f run_cmd -export TESTDIR="$(dirname "$0")" -export AUTERDIR="$(dirname "$TESTDIR")" -export AUTERPARENTDIR="$(dirname "$AUTERDIR")" -export VERSION="$(grep "Version" "$AUTERDIR"/auter.spec | awk '{print $2}')" -export CHANGEDFILES="$(find "$AUTERDIR" -name CHANGEDFILES)" +TESTDIR="$(dirname "$0")" +AUTERDIR="$(dirname "$TESTDIR")" +AUTERPARENTDIR="$(dirname "$AUTERDIR")" +VERSION="$(grep "Version" "$AUTERDIR"/auter.spec | awk '{print $2}')" +export TESTDIR AUTERDIR AUTERPARENTDIR VERSION