Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parallelize the Travis build process... #223

Merged
merged 1 commit into from
Mar 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 10 additions & 24 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
10 changes: 5 additions & 5 deletions tests/01-spellcheck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
30 changes: 9 additions & 21 deletions tests/05-shellcheck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 11 additions & 11 deletions tests/_helpers
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,33 @@ 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

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