aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/check-lint-count.sh
blob: a029edb4394c964682795c98e4970e63f08f8a2c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env bash
#
# Checks the number of lint issues against historical values. Used in
# Travis CI builds to fail when the number increases by exploiting the
# caching mechanism.

if [[ $# != 2 || ! -f $1 ]]; then \
    echo "Usage: $0 <lint.xml file> <historical.xml file>"
    exit 1
fi

lint_file="$1"
historical_file="$2"

xmllint="$(which xmllint)"

if [[ ! -x $xmllint ]]; then \
    echo "Error: cannot find xmllint"
    exit 1
fi

if [[ ! -f $2 ]]; then \
  # no cache history, store this one and exit
  cp $1 $2
  exit 0
fi

echo "cat //issue/location" | xmllint --shell $historical_file | grep '<location' >/tmp/hist.$$
echo "cat //issue/location" | xmllint --shell $lint_file | grep '<location' >/tmp/lint.$$

old_count=$(cat /tmp/hist.$$ | wc -l)
new_count=$(cat /tmp/lint.$$ | wc -l)

echo "Historical count : $old_count, new count : $new_count"

if [[ $new_count > $old_count ]]; then \
    echo "FAILURE: lint issues increased from $old_count to $new_count"
    diff /tmp/lint.$$ /tmp/hist.$$
    rm -f /tmp/lint.$$ /tmp/hist.$$
    exit 2
fi

rm -f /tmp/lint.$$ /tmp/hist.$$

if [[ $TRAVIS_PULL_REQUEST == false ]]; then \
    # Okay, we either stayed the same or reduced our number.
    # Write it out so we can check it next build!
    mv $lint_file $historical_file 
fi