-
Notifications
You must be signed in to change notification settings - Fork 7
/
run-tests.sh
executable file
·179 lines (148 loc) · 3.79 KB
/
run-tests.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#!/usr/bin/env bash
set -e
source ./build.sh
# Can be set as environment variable
if [ -z "$BUILD_SERVER" ]; then
BUILD_SERVER=https://build-stage.defold.com
#BUILD_SERVER=http://localhost:9000
fi
log "**********************************"
log "Using extender server ${BUILD_SERVER}"
if [ ! -z "$EXTENDER_HEADER_NAME" ]; then
SERVER_VERSION=$(wget --header "${EXTENDER_HEADER_NAME}: ${EXTENDER_HEADER_VALUE}" -q -O - $BUILD_SERVER)
else
SERVER_VERSION=$(wget -q -O - $BUILD_SERVER)
fi
log "${SERVER_VERSION}"
log "**********************************"
if [ -z "$PLATFORMS" ]; then
PLATFORMS="armv7-android,arm64-ios,js-web,x86_64-win32,x86_64-linux,x86_64-macos"
fi
log "Using platforms ${PLATFORMS}"
if [ -z "$PROJECTS" ]; then
log "No projects specified!"
exit 1
fi
# Replace new lines with comma
PROJECTS=$(echo $PROJECTS | tr '\n' ',' | tr ' ' ',')
if [ -z "$CHANNEL" ]; then
CHANNEL=alpha
fi
if [ -z "$ARCHIVE_PATH" ]; then
ARCHIVE_PATH=d.defold.com
fi
case ${CHANNEL} in
"alpha"|"beta"|"stable")
unset SHA1
log "Using channel ${CHANNEL}"
;;
*)
SHA1=${CHANNEL}
unset CHANNEL
log "Using sha1 ${SHA1}"
;;
esac
if [ -z "$HANDLE_ERRORS" ]; then
HANDLE_ERRORS="true"
fi
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
BUILD_FOLDER=build
if [ ! -d "$BUILD_FOLDER" ]; then
mkdir -p $BUILD_FOLDER
fi
ERRORTXT=${SCRIPTDIR}/errors.txt
function cleanup() {
log "Cleaning up"
cd $SCRIPTDIR
log "Removing" ./$BUILD_FOLDER
rm -rf ./$BUILD_FOLDER
log "Removing jre"
rm -rf ./jre || true
log "Removing tar files"
rm ./*.tar.gz* || true
log "Removing jar files"
rm ./*.jar || true
}
trap cleanup 0
download_project() {
local url=$1
local name=project
local zipname=${name}.zip
log "Downloading ${url}"
curl -L -o $BUILD_FOLDER/$zipname $url
unzip -q $BUILD_FOLDER/$zipname -d $BUILD_FOLDER/$name
rm $BUILD_FOLDER/$zipname
}
check_error() {
local status=$1
local name=$2
local platform=$3
if [ $status -ne 0 ]; then
touch ${ERRORTXT}
log "Failed to build '${name}'' for ${platform}" >> "${ERRORTXT}"
fi
}
check_failed_builds() {
if [ -f ${ERRORTXT} ]; then
echo "At least one of the builds failed:"
cat ${ERRORTXT}
exit 1
fi
}
# Function to shuffle an array passed as a parameter
shuffle() {
local i tmp size max rand shuffled_string
IFS=',' read -ra arr <<< "$1"
# Get the size of the array
size=${#arr[*]}
# Maximum random number
max=$(( 32768 / size * size ))
for ((i=size-1; i>0; i--)); do
# Get a random number within the range
while (( (rand = RANDOM) >= max )); do :; done
# Perform a modulo operation to get a number within the array size
rand=$(( rand % (i+1) ))
# Swap the elements
tmp=${arr[i]}
arr[i]=${arr[rand]}
arr[rand]=$tmp
done
shuffled_string=$(IFS=,; echo "${arr[*]}")
echo "$shuffled_string"
}
build_project() {
local shuffled_platform=$(shuffle $1)
local platforms=(${shuffled_platform//,/ })
local url=$2
local variant=$3
local projectfile=`find $BUILD_FOLDER/$name -name game.project`
local projectdir="$(dirname $projectfile)"
pushd $projectdir
resolve [email protected] 123456
for i in ${platforms[@]}; do
log "Building $url for ${i}"
if [ "$HANDLE_ERRORS" == "true" ]; then
echo "DISABLING ERRORS"
set +e
fi
bob --platform ${i} build --build-server $BUILD_SERVER --use-async-build-server --defoldsdk ${SHA1} --variant=$variant -v
check_error $? $url $i
if [ "$HANDLE_ERRORS" == "true" ]; then
set -e
fi
done
popd
}
log "Using Java"
which java
java -version
download_bob
PROJECTS=(${PROJECTS//,/ })
for project in ${PROJECTS[@]}; do
download_project $project
build_project $PLATFORMS $project debug
build_project $PLATFORMS $project release
build_project $PLATFORMS $project headless
rm -rf $BUILD_FOLDER
done
check_failed_builds