-
Notifications
You must be signed in to change notification settings - Fork 1
/
run.sh
executable file
·111 lines (99 loc) · 2.95 KB
/
run.sh
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/bin/sh
# Copyright (C) 2016 Wesley Tanaka <http://wtanaka.com/>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# This bootstrap script downloads the Ansible Role Tester into your
# role directory and executes it.
#
# Usage (in the root directory of your ansible role, the one that
# contains meta/ and tasks/)
#
# wget -O- bit.ly/ansibletest | sh
#
# To pin to a specific commit of role-tester-ansible
#
# wget -O- bit.ly/ansibletest | env BRANCH=fullshahashgoeshere sh
# Retry function
# Copied from https://github.com/wtanaka/bootci/blob/master/.bootci/common.sh
RETRY_SLEEP_SEC=10
RETRY_COUNT=5
retry()
{
for i in $(seq 1 $RETRY_COUNT); do
[ $i -gt 1 ] && sleep $RETRY_SLEEP_SEC; "$@" && s=0 && break ||
s=$? && >&2 echo "$@: failed try #$i; will retry in $RETRY_SLEEP_SEC sec";
done;
(exit $s)
}
download()
{
wget -O - "$@" || curl -L "$@" ||
python3 -c "import sys; from urllib.request import urlopen as u
sys.stdout.buffer.write(u('""$@""').read())"
}
if [ -z "$GITHUBUSER" ]; then
GITHUBUSER=wtanaka
fi
if [ -z "$PROJECT" ]; then
PROJECT=role-tester-ansible
fi
# Which version of role-tester-ansible to use, allow overriding with
# environment variable
if [ -z "$BRANCH" ]; then
BRANCH=master
fi
# The role under test -- allow setting from environment variable
if [ -z "$ROLENAME" ]; then
PWD="`pwd`"
ROLENAME="${PWD##*/}"
fi
while getopts a:b:ho:r: opt; do
case "$opt" in
a)
ANSIBLE_VERSIONS="$OPTARG"
;;
b)
BRANCH="$OPTARG"
;;
o)
DOCKER_IMAGES="$OPTARG"
;;
r)
ROLENAME="$OPTARG"
;;
h)
echo "Usage: $0 [-b BRANCH] [-r ROLENAME] [-h]"
exit
;;
esac
done
URL=https://github.com/"$GITHUBUSER"/"$PROJECT"/archive/"$BRANCH".tar.gz
retry download "$URL" | tar xvfz -
ROLE_UNDER_TEST="$ROLENAME"
export ROLE_UNDER_TEST
# Inlined from _functions.sh
ROLE_DIR="."
ROLE_TESTER_DIR="$PROJECT"-"$BRANCH"
if [ -d "$ROLE_DIR"/test/integration/default/serverspec ]; then
(cd $ROLE_TESTER_DIR; bundle exec kitchen diagnose |
grep '^[ ]*suite_name: ' | cut -d: -f2 | cut -c2- | uniq) |
while read LINE; do
mkdir -p "$ROLE_TESTER_DIR"/test/integration/"$LINE"
cp -a "$ROLE_DIR"/test/integration/default/serverspec \
"$ROLE_TESTER_DIR"/test/integration/"$LINE"
done
fi
make -s -C "$PROJECT"-"$BRANCH"