52e3d26c545b4086ea5df9023728545f78994cd2
[grml-debootstrap.git] / travis / execute.sh
1 #!/bin/bash
2
3 set -eu -o pipefail
4
5 RELEASE="${RELEASE:-stretch}"
6 export RELEASE
7
8 # run shellcheck tests
9 docker run koalaman/shellcheck:stable --version
10 docker run -v "$(pwd)":/code koalaman/shellcheck:stable -e SC2181 /code/chroot-script /code/grml-debootstrap
11
12 # build Debian package
13 wget -O- https://travis.debian.net/script.sh | sh -
14
15 if ! [ "${TRAVIS_DEBIAN_DISTRIBUTION:-}" = "unstable" ] ; then
16   echo "TRAVIS_DEBIAN_DISTRIBUTION is $TRAVIS_DEBIAN_DISTRIBUTION and not unstable, skipping VM build tests."
17   exit 0
18 fi
19
20 # copy only the binary from the TRAVIS_DEBIAN_INCREMENT_VERSION_NUMBER=true build
21 cp ../grml-debootstrap_*travis*deb .
22
23 # we need to run in privileged mode to be able to use loop devices
24 docker run --privileged -v "$(pwd)":/code --rm -i -t debian:stretch /code/travis/build-vm.sh
25
26 [ -x ./goss ] || curl -fsSL https://goss.rocks/install | GOSS_DST="$(pwd)" sh
27
28 sudo apt-get update
29 sudo apt-get -y install qemu-system-x86
30
31 # sudo timeout --preserve-status --foreground 120 qemu-system-x86_64 -hda qemu.img -serial stdio -display none | tee -a qemu.log
32 sudo qemu-system-x86_64 -hda qemu.img -serial stdio -display none | tee -a qemu.log &
33
34 timeout=120
35 success=0
36 while [ "$timeout" -gt 0 ]; do
37   ((timeout--))
38   if ./goss --gossfile ./travis/goss.yaml validate --format nagios ; then
39     success=1
40     sleep 1
41     break
42   else
43     echo "Tests didn't pass YET, will retry again [$timeout retries left]"
44     sleep 1
45   fi
46 done
47
48 if [ "$success" = "1" ] ; then
49   echo "All tests passed! (◕‿◕)"
50 else
51   echo "Reached timeout after $timeout seconds with failing tests. ¯\(º o)/¯ ☂" >&2
52   echo "Latest test run results:"
53   ./goss --gossfile ./travis/goss.yaml validate
54   exit 1
55 fi