feat: add junit support to shellcheck output
This requires us to run shellcheck twice, as the first pass doesn't output anything human readable - both because of the redirect and because shellcheck doesn't directly support it - which increases lint runtime but allows us to have both the junit information and the normal human-readable output. Note that the checkstyle output does not contain timing info.
This commit is contained in:
38
tests.mk
38
tests.mk
@@ -1,5 +1,16 @@
|
||||
SYSTEM := $(shell sh -c 'uname -s 2>/dev/null')
|
||||
|
||||
bats:
|
||||
ifeq ($(SYSTEM),Darwin)
|
||||
ifneq ($(shell bats --version > /dev/null 2>&1 ; echo $$?),0)
|
||||
brew install bats-core
|
||||
endif
|
||||
else
|
||||
git clone https://github.com/josegonzalez/bats-core.git /tmp/bats
|
||||
cd /tmp/bats && sudo ./install.sh /usr/local
|
||||
rm -rf /tmp/bats
|
||||
endif
|
||||
|
||||
shellcheck:
|
||||
ifneq ($(shell shellcheck --version > /dev/null 2>&1 ; echo $$?),0)
|
||||
ifeq ($(SYSTEM),Darwin)
|
||||
@@ -11,7 +22,16 @@ else
|
||||
endif
|
||||
endif
|
||||
|
||||
ci-dependencies: shellcheck bats
|
||||
xmlstarlet:
|
||||
ifneq ($(shell xmlstarlet --version > /dev/null 2>&1 ; echo $$?),0)
|
||||
ifeq ($(SYSTEM),Darwin)
|
||||
brew install xmlstarlet
|
||||
else
|
||||
sudo apt-get update -qq && sudo apt-get install -qq -y xmlstarlet
|
||||
endif
|
||||
endif
|
||||
|
||||
ci-dependencies: shellcheck bats xmlstarlet
|
||||
|
||||
setup-deploy-tests:
|
||||
mkdir -p /home/dokku
|
||||
@@ -57,20 +77,14 @@ ifeq ($(shell grep dokku.me /home/dokku/VHOST 2>/dev/null),)
|
||||
echo "dokku.me" > /home/dokku/VHOST
|
||||
endif
|
||||
|
||||
bats:
|
||||
ifeq ($(SYSTEM),Darwin)
|
||||
ifneq ($(shell bats --version > /dev/null 2>&1 ; echo $$?),0)
|
||||
brew install bats-core
|
||||
endif
|
||||
else
|
||||
git clone https://github.com/josegonzalez/bats-core.git /tmp/bats
|
||||
cd /tmp/bats && sudo ./install.sh /usr/local
|
||||
rm -rf /tmp/bats
|
||||
endif
|
||||
|
||||
lint:
|
||||
# these are disabled due to their expansive existence in the codebase. we should clean it up though
|
||||
# SC2034: VAR appears unused - https://github.com/koalaman/shellcheck/wiki/SC2034
|
||||
ifeq ($(CIRCLECI),true)
|
||||
@echo creating junit output...
|
||||
@mkdir -p test-results/shellcheck
|
||||
@$(QUIET) find . -not -path '*/\.*' -not -path './debian/*' -type f | xargs file | grep text | awk -F ':' '{ print $$1 }' | xargs head -n1 | egrep -B1 "bash" | grep "==>" | awk '{ print $$2 }' | xargs shellcheck -e SC2034 -f checkstyle | xmlstarlet tr tests/checkstyle2junit.xslt > test-results/shellcheck/results.xml
|
||||
endif
|
||||
@echo linting...
|
||||
@$(QUIET) find . -not -path '*/\.*' -not -path './debian/*' -type f | xargs file | grep text | awk -F ':' '{ print $$1 }' | xargs head -n1 | egrep -B1 "bash" | grep "==>" | awk '{ print $$2 }' | xargs shellcheck -e SC2034
|
||||
|
||||
|
||||
44
tests/checkstyle2junit.xslt
Normal file
44
tests/checkstyle2junit.xslt
Normal file
@@ -0,0 +1,44 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
|
||||
<xsl:output encoding="UTF-8" method="xml"></xsl:output>
|
||||
|
||||
<xsl:template match="/">
|
||||
<testsuite>
|
||||
<xsl:attribute name="tests">
|
||||
<xsl:value-of select="count(.//file)" />
|
||||
</xsl:attribute>
|
||||
<xsl:attribute name="failures">
|
||||
<xsl:value-of select="count(.//error)" />
|
||||
</xsl:attribute>
|
||||
<xsl:for-each select="//checkstyle">
|
||||
<xsl:apply-templates />
|
||||
</xsl:for-each>
|
||||
</testsuite>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="file">
|
||||
<testcase>
|
||||
<xsl:attribute name="classname">
|
||||
<xsl:value-of select="@name" />
|
||||
</xsl:attribute>
|
||||
<xsl:attribute name="name">
|
||||
<xsl:value-of select="@name" />
|
||||
</xsl:attribute>
|
||||
<xsl:apply-templates select="node()" />
|
||||
</testcase>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="error">
|
||||
<failure>
|
||||
<xsl:attribute name="type">
|
||||
<xsl:value-of select="@source" />
|
||||
</xsl:attribute>
|
||||
<xsl:text>Line </xsl:text>
|
||||
<xsl:value-of select="@line" />
|
||||
<xsl:text>: </xsl:text>
|
||||
<xsl:value-of select="@message" />
|
||||
<xsl:text> See https://www.shellcheck.net/wiki/</xsl:text>
|
||||
<xsl:value-of select="substring(@source, '12')" />
|
||||
</failure>
|
||||
</xsl:template>
|
||||
</xsl:stylesheet>
|
||||
Reference in New Issue
Block a user