-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathrun-tests.sh
executable file
·212 lines (175 loc) · 4.66 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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#!/usr/bin/env bash
set -e
source ./build.sh
declare PLATFORM_RESULTS=()
# store how many times we call build_project
declare BUILD_VARIANT_COUNT=0
# 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 "$PROJECT" ]; then
log "No project specified!"
exit 1
fi
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
local variant=$4
if [ $status -ne 0 ]; then
touch ${ERRORTXT}
log "Failed to build '${name}' for '${platform}' variant '${variant}'" >> "${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 platforms_str=$1
local platforms=(${platforms_str//,/ })
local url=$2
local variant=$3
local projectfile=`find $BUILD_FOLDER/$name -name game.project`
local projectdir="$(dirname $projectfile)"
pushd $projectdir
BUILD_VARIANT_COUNT=$((BUILD_VARIANT_COUNT+1))
resolve
local idx=0
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
bob_exit_code=$?
check_error $bob_exit_code $url $i $variant
if [[ $bob_exit_code -eq 0 && "${GITHUB_ACTIONS:-false}" == "true" ]]; then
PLATFORM_RESULTS[$idx]=$(( ${PLATFORM_RESULTS[$idx]:-0} + 1 ))
fi
idx=$((idx+1))
if [ "$HANDLE_ERRORS" == "true" ]; then
set -e
fi
done
popd
}
log "Using Java"
which java
java -version
download_bob
shuffled_platform=$(shuffle $PLATFORMS)
splitted_platforms=(${shuffled_platform//,/ })
if [ ${GITHUB_ACTIONS:-false} == "true" ]; then
arr_len=${#splitted_platforms[@]}
for (( idx=0; idx<arr_len; idx++ )); do
PLATFORM_RESULTS+=(0)
done
fi
echo ${PLATFORM_RESULTS[@]}
download_project $PROJECT
build_project $shuffled_platform $PROJECT debug
build_project $shuffled_platform $PROJECT release
build_project $shuffled_platform $PROJECT headless
rm -rf $BUILD_FOLDER
if [ ${GITHUB_ACTIONS:-false} == "true" ]; then
success_platform=()
idx=0
for platform in ${splitted_platforms[@]}; do
if [ ${PLATFORM_RESULTS[$idx]} -eq $BUILD_VARIANT_COUNT ]; then
success_platform+=(${platform})
fi
idx=$((idx+1))
done
echo $(IFS=,; echo "${success_platform[*]}")
echo $(IFS=,; echo "${success_platform[*]}") >> ./succeeded_platforms
fi
check_failed_builds