-
Notifications
You must be signed in to change notification settings - Fork 530
Expand file tree
/
Copy pathfunctions.sh
More file actions
executable file
·78 lines (66 loc) · 1.29 KB
/
functions.sh
File metadata and controls
executable file
·78 lines (66 loc) · 1.29 KB
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
GREEN="\033[32m"
RED="\033[31m"
NO_COLOR="\033[0m"
function checkFailures {
if [[ $HAS_FAILURES == 1 ]] || [[ -f '.has_failures' ]]; then
echo "Ruh roh. Failed tests."
if [[ -f '.has_failures' ]]; then
cat '.has_failures'
fi
return 1
fi
return 0
}
function testcase {
if [ $? -eq 0 ]; then
echo -e "$GREEN ✓ SUCCESS $NO_COLOR"
return 0
else
echo -e "$RED ✗ FAILED $NO_COLOR"
export HAS_FAILURES=1
touch '.has_failures'
echo "has_failures $@" >> '.has_failures'
return 1
fi
}
function contains {
loop=($1)
for i in "${loop[@]}"
do
if [[ "$i" == "$2" ]] ; then
return 0
fi
done
return 1
}
function emptyOrContains {
[[ "" == "$1" ]] || contains "$1" "$2"
}
function platform {
emptyOrContains "${BUILD_PLATFORM[*]}" "$1"
}
function filterPlatform {
eval 'array=${'${1}'[@]}'
eval "array=( $array )"
result=""
for i in "${array[@]}"; do
if platform $i; then
result="$result $i"
fi
done
# remove leading space
eval "$1=( ${result} )"
}
function die {
[[ -z "$1" ]] || echo "Error: $1"
exit 1
}
# executes script in this shell passed as stdin
function executeScript {
while read line; do
eval $line
done
}
function checkDefined() {
[ "${!1}" ] || die "\$$1 variable is awol."
}