Browse Source

New package jenkins-debian-glue-buildenv-taptools

Provide tap_tool_dispatcher and checkbashism and perlcritic
for generating TAP reports of shell and perl source code.
tags/v0.4.0
Michael Prokop 9 years ago
parent
commit
abc1949300
5 changed files with 136 additions and 0 deletions
  1. +15
    -0
      debian/control
  2. +3
    -0
      debian/jenkins-debian-glue-buildenv-taptools.install
  3. +38
    -0
      tap/checkbashism_tap
  4. +43
    -0
      tap/perlcritic_tap
  5. +37
    -0
      tap/tap_tool_dispatcher

+ 15
- 0
debian/control View File

@@ -68,3 +68,18 @@ Description: lintian integration in Jenkins
This package provides the lintian-junit-report script. The
script can be used for generating JUnit reports of lintian
checking Debian packages inside Jenkins jobs.

Package: jenkins-debian-glue-buildenv-taptools
Architecture: all
Depends: devscripts,
libperl-critic-perl,
ruby,
${misc:Depends}
Description: taptools integration in Jenkins
This package provides scripts to check shell and perl source code
for common errors, using checkbashism and perlcritic to
generate according TAP reports for usage inside Jenkins.
.
The provided tap_tool_dispatcher script can be used to automatically
detect according shell scripts and perl scripts to execute
checkbashism_tap and perlcritic_tap accordingly.

+ 3
- 0
debian/jenkins-debian-glue-buildenv-taptools.install View File

@@ -0,0 +1,3 @@
debian/tmp/usr/bin/checkbashism_tap usr/bin/
debian/tmp/usr/bin/perlcritic_tap usr/bin/
debian/tmp/usr/bin/tap_tool_dispatcher usr/bin/

+ 38
- 0
tap/checkbashism_tap View File

@@ -0,0 +1,38 @@
#!/usr/bin/env ruby

if ARGV[0].nil?
$stderr.puts "Usage: #{File.basename $0} <file>"
exit 1
end

if not system "which checkbashisms >/dev/null 2>&1"
$stderr.puts "Error: program checkbashisms does not exist (install devscripts package)."
exit 1
end

file = ARGV[0]

if not File.exists? file
$stderr.puts "Error: file #{file} could not be read."
exit 1
end

output = %x{checkbashisms --posix #{file} 2>&1}

num_lines = output.lines.count / 2 # checkbasims has one line message and one line code
exit 0 if num_lines == 0 # nothing found, jey
counter = 1

if output =~ /does not appear to have a #! interpreter line/
$stderr.puts "File #{file} does not appear to have a #! interpreter line, skipping."
exit 0
end


# output result in TAP format
puts "1..#{num_lines}"
output.gsub(/:\n/, ':').each_line do |critic|
next unless critic =~ /^possible bashism in/
puts "not ok #{counter} #{critic}"
counter += 1
end

+ 43
- 0
tap/perlcritic_tap View File

@@ -0,0 +1,43 @@
#!/usr/bin/env ruby

if ARGV[0].nil?
$stderr.puts "Usage: #{File.basename $0} <file>"
exit 1
end

if not system "which perlcritic >/dev/null 2>&1"
$stderr.puts "Error: program perlcritic does not exist (install libperl-critic-perl?)."
exit 1
end

# not sure whether we really should check this here..
#if !File.exists?('/usr/share/perl5/Test/Log4perl.pm')
# $stderr.puts "Error: libtest-log4perl-perl not installed."
# exit 1
#end

file = ARGV[0]

# make sure we're checking a perl script
mimetype = `file -b --keep-going #{file}`.gsub(/\n/,"")
if not /.*perl/i.match(mimetype)
$stderr.puts "File #{file} doesn't look like perl [#{mimetype}]. Ignoring."
exit 0
end

# let's see what perlcritic thinks...
output = %x{perlcritic #{file}}
num_lines = output.lines.count
counter = 1

# output result in TAP format
puts "1..#{num_lines}"
output.each_line do |critic|
if critic =~ /.* source OK$/
puts "ok #{counter} #{critic}"
else
puts "not ok #{counter} #{critic}"
end

counter += 1
end

+ 37
- 0
tap/tap_tool_dispatcher View File

@@ -0,0 +1,37 @@
#!/bin/bash

set -u

if [ -z "${REPORTS_DIRECTORY:-}" ] ; then
export REPORTS_DIRECTORY='reports'
fi

if [ -z "${WORKSPACE:-}" ] ; then
echo "Error: WORKSPACE unset, please run inside Jenkins. ">&2
exit 1
fi

if ! [ -d source ] ; then
echo "Error: no source directory found, please run inside Jenkins." >&2
exit 1
fi

# start with clean report dir
rm -rf "${REPORTS_DIRECTORY}"
mkdir -p "${REPORTS_DIRECTORY}"/perl
mkdir -p "${REPORTS_DIRECTORY}"/shell

# run perlcritic_tap
echo "*** perlcritic_tap ***"
find source -type f ! -path '*.svn*' -prune -exec \
sh -c 'input="$1"; output=$(echo $input | sed -e s,/,_,g); /usr/bin/perlcritic_tap "$input" > "${REPORTS_DIRECTORY}/perl/${output}"' '{}' '{}' ';'

# run checkbashism_tap
echo "*** checkbashism_tap ***"
find source -type f ! -path '*.svn*' -prune -exec \
sh -c 'input="$1"; output=$(echo $input | sed -e s,/,_,g); /usr/bin/checkbashism_tap "$input" > "${REPORTS_DIRECTORY}/shell/${output}"' '{}' '{}' ';'

# get rid of empty files
find "${REPORTS_DIRECTORY}" -type f -empty -exec rm {} +

## END OF FILE #################################################################

Loading…
Cancel
Save