Shellcheck With Travis CI

Using shellcheck is a very easy way to avoid simple bugs in your shell scripts. By adding it to your CI you can easily make it a free check. To check all ‘sh’ and ‘bash’ files in my project I used the following code in ngenetzky/shlib.

#!/bin/bash

SCRIPTDIR="$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd -P)"
GITROOT="$(readlink -f "${SCRIPTDIR}/../")"

main(){
  (
    cd "${GITROOT}"
    find ./* \
      \( -iname '*.bash' -or -iname '*.sh' \) \
      -exec shellcheck "$@" {} +
  )
}

if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
    # Bash Strict Mode
    set -eu -o pipefail

    # set -x
    main "$@"
fi
sudo: required
dist: trusty
language: bash
script:
- scripts/test-shellcheck.bash

References:

Avatar
Nathan Genetzky
Software Engineer

Related

comments powered by Disqus