modified version of jenkins debian glue (https://github.com/mika/jenkins-debian-glue) for devuan
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

157 lines
4.0 KiB

  1. #!/bin/bash
  2. set -u
  3. BASE_BIN=${BASE_BIN:-/usr/bin}
  4. # command line handling
  5. CMDLINE_OPTS=disable-checkbashism,disable-pep8,disable-perlcritic,disable-shellcheck
  6. CMDLINE_OPTS+=,file-list,help
  7. _opt_temp=$(getopt --name tap_tool_dispatcher -o -f+h --long $CMDLINE_OPTS -- "$@")
  8. if [ $? -ne 0 ]; then
  9. echo "Try '$0 --help' for more information." >& 2
  10. exit 1
  11. fi
  12. eval set -- "$_opt_temp"
  13. # defaults
  14. _opt_checkbashism=true
  15. _opt_pep8=true
  16. _opt_perlcritic=true
  17. _opt_shellcheck=true
  18. usage() {
  19. echo "$0 - run code style quality tools in parallel
  20. Usage: $0 [<options>]
  21. Supported options:
  22. --disable-checkbashism Disable checkbashism execution
  23. --disable-pep8 Disable pep8 execution
  24. --disable-perlcritic Disable perlcritic execution
  25. --disable-shellcheck Disable shellcheck execution
  26. -f|--file-list FILE File with the list of files to check
  27. -h|--help Display this usage information and exit
  28. "
  29. }
  30. while :; do
  31. case "$1" in
  32. --help|-h)
  33. usage ; exit 0;
  34. ;;
  35. --disable-checkbashism)
  36. _opt_checkbashism=false
  37. ;;
  38. --disable-pep8)
  39. _opt_pep8=false
  40. ;;
  41. --disable-perlcritic)
  42. _opt_perlcritic=false
  43. ;;
  44. --disable-shellcheck)
  45. _opt_shellcheck=false
  46. ;;
  47. --file-list|-f)
  48. [ -f "$2" ] || { echo "No $2 file found" >&2; exit 1; }
  49. FILE_LIST="$2"
  50. shift;
  51. ;;
  52. --)
  53. shift; break
  54. ;;
  55. *)
  56. echo "Internal getopt error! $1" >&2
  57. exit 1
  58. ;;
  59. esac
  60. shift
  61. done
  62. # sanity checks before executing anything
  63. if [ -z "${REPORTS_DIRECTORY:-}" ] ; then
  64. export REPORTS_DIRECTORY='reports'
  65. fi
  66. if [ -z "${WORKSPACE:-}" ] ; then
  67. echo "Error: WORKSPACE unset, please run inside Jenkins. ">&2
  68. exit 1
  69. fi
  70. if ! [ -d source ] ; then
  71. echo "Error: no source directory found, please run inside Jenkins." >&2
  72. exit 1
  73. fi
  74. # start with clean report dir
  75. rm -rf "${REPORTS_DIRECTORY}"
  76. # set up a temporary file which executes the requested commands
  77. TMPFILE="$(mktemp)" || exit 1
  78. # GNU parallel supports the -v option, while parallel from moreutils doesn't
  79. unset PARALLEL_OPTION
  80. if parallel --version >/dev/null 2>&1 ; then
  81. PARALLEL_OPTION='-v'
  82. fi
  83. if [ -n "${FILE_LIST:-}" ] ; then
  84. LIST="sed 's#^#source/#g' < $FILE_LIST"
  85. else
  86. LIST="find source -type f ! -path '*.svn*' ! -path '*.git/*' ! -name '.gitignore' -prune"
  87. fi
  88. echo "$LIST | parallel ${PARALLEL_OPTION:-} -- \\
  89. mkdir -p ${REPORTS_DIRECTORY}'/'{//} ';' \\" > "${TMPFILE}"
  90. if ! [ -x "$(which checkbashisms)" ] ; then
  91. echo "*** Skipping checkbashism checks as tool checkbashisms isn't present ***"
  92. else
  93. if $_opt_checkbashism ; then
  94. echo "${BASE_BIN}/checkbashism_tap '{}' '>' ${REPORTS_DIRECTORY}'/{}_checkbashism.tap' ';' \\" >> "${TMPFILE}"
  95. else
  96. echo "*** Skipping checkbashism tests as requested via --disable-checkbashism ***"
  97. fi
  98. fi
  99. if ! [ -x "$(which pep8)" ] ; then
  100. echo "*** Skipping pep8 checks as tool pep8 isn't present ***"
  101. else
  102. if $_opt_pep8 ; then
  103. echo "${BASE_BIN}/pep8_tap '{}' '>' ${REPORTS_DIRECTORY}'/{}_pep8.tap' ';' \\" >> "${TMPFILE}"
  104. else
  105. echo "*** Skipping pep8 tests as requested via --disable-pep8 ***"
  106. fi
  107. fi
  108. if ! [ -x "$(which perlcritic)" ] ; then
  109. echo "*** Skipping perlcritic checks as tool perlcritic (package libperl-critic-perl) isn't present ***"
  110. else
  111. if $_opt_perlcritic ; then
  112. echo "${BASE_BIN}/perlcritic_tap '{}' '>' ${REPORTS_DIRECTORY}'/{}_perlcritic.tap' ';' \\" >> "${TMPFILE}"
  113. else
  114. echo "*** Skipping pep8 tests as requested via --disable-perlcritic ***"
  115. fi
  116. fi
  117. if ! [ -x "$(which shellcheck)" ] ; then
  118. echo "*** Skipping shellcheck checks as tool shellcheck isn't present ***"
  119. else
  120. if $_opt_shellcheck ; then
  121. echo "${BASE_BIN}/shellcheck_tap '{}' '>' ${REPORTS_DIRECTORY}'/{}_shellcheck.tap' ';'" >> "${TMPFILE}"
  122. else
  123. echo "*** Skipping shellcheck tests as requested via --disable-shellcheck ***"
  124. fi
  125. fi
  126. # generate the executed script
  127. bash "${TMPFILE}"
  128. rm -f "${TMPFILE}"
  129. echo "*** Getting rid of empty files ***"
  130. find "${REPORTS_DIRECTORY}" -type f -empty -exec rm {} +
  131. ## END OF FILE #################################################################