This repository has been archived by the owner on Apr 5, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
dnt.sh
executable file
·111 lines (89 loc) · 2.98 KB
/
dnt.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/bash
##############################################################
# DNT: Run tests in Docker containers for many Node versions #
##############################################################
CONFIG_FILE=".dntrc"
OUTPUT_PREFIX=""
COPYDIR=$(pwd)
# How many tests can we run at once without making the computer grind to a halt
# or causing other unwanted resource problems:
SIMULTANEOUS=$(getconf _NPROCESSORS_ONLN)
COPY_CMD="rsync -aAXx --delete --exclude .git --exclude build /dnt-src/ /dnt/"
LOG_OK_CMD="tail -1"
IOJS_VERSIONS=
if [ -f $CONFIG_FILE ]; then
source ./$CONFIG_FILE
else
echo "You must have a ${CONFIG_FILE} in the current directory"
exit 1
fi
NODE_VERSIONS="$NODE_VERSIONS $IOJS_VERSIONS"
# The versions of Node to test, this assumes that we have a Docker image
# set up with the name "node_dev/<version>"
#NODE_VERSIONS=$(cat ${__dirname}/node_versions.list)
if [ $# -gt 0 ] ; then
NODE_VERSIONS=$*
echo "Using Node versions: ${NODE_VERSIONS}"
fi
if [ "X${NODE_VERSIONS}" == "X" ]; then
echo "You must set up a NODE_VERSIONS list in your ${CONFIG_FILE}"
exit 1
fi
if [ "X${TEST_CMD}" == "X" ]; then
echo "You must set up a TEST_CMD in your ${CONFIG_FILE}"
exit 1
fi
START_TS=$(date +%s)
test_node() {
local OUT=/tmp/${OUTPUT_PREFIX}dnt-${NV}.out
local TYPE=$1
local NV=$2
local ID=${TYPE}_dev/${NV}
docker inspect "$ID" &> /dev/null
if [[ $? -ne 0 ]]; then
echo -e "\033[31mCould not find container for [\033[1m$NV\033[22m]\033[39m"
return
fi
# Run test in a Docker container
RUNCMD="/bin/su -s /bin/bash dnt -c '${COPY_CMD};${TEST_CMD}'"
if [ "X${APT_INSTALL}" != "X" ]; then
RUNCMD="apt-get update && apt-get install -y ${APT_INSTALL} && ${RUNCMD}"
fi
DOCKER_EXEC="docker run -i --rm"
if [ "X${RUN_TIMEOUT}" != "X" ]; then
DOCKER_EXEC="timeout $RUN_TIMEOUT docker run -i --rm"
fi
if [ "${CONSOLE_LOG}" == "true" ]; then
$DOCKER_EXEC -v ~/.npm/:/dnt/.npm/ -v ${COPYDIR}:/dnt-src/:ro $ID /bin/bash -c "$RUNCMD" 2>&1 | tee $OUT
else
$DOCKER_EXEC -v ~/.npm/:/dnt/.npm/ -v ${COPYDIR}:/dnt-src/:ro $ID /bin/bash -c "$RUNCMD" &> $OUT
fi
# Print status
LAST_LINE=$(eval "cat /tmp/${OUTPUT_PREFIX}dnt-${NV}.out | $LOG_OK_CMD")
printf "${TYPE}@\033[1m\033[33m%-8s\033[39m\033[22m: " $NV
if [[ $LAST_LINE == "ok" ]]; then
echo -ne "\033[1m\033[32mPASS\033[39m\033[22m"
elif [[ $LAST_LINE == "# fail 0" ]]; then
echo -ne "\033[1m\033[32mPASS\033[39m\033[22m"
else
echo -ne "\033[1m\033[31mFAIL\033[39m\033[22m"
fi
echo -e " \033[3mwrote output to ${OUT}\033[23m"
}
# Run all tests
_C=0
for NV in $NODE_VERSIONS; do
test_node "node" $NV &
# Small break between each start, gives Docker breathing room
sleep 0.5
# Crude limiting on the number of simultaneous runs
let _C=_C+1
if [[ $((_C % ${SIMULTANEOUS})) == 0 ]]; then
wait
fi
done
wait
END_TS=$(date +%s)
DURATION=$((END_TS-START_TS))
VERSIONS=$(echo $NODE_VERSIONS | wc -w)
echo "Took ${DURATION}s to run ${VERSIONS} versions of Node"