-
Notifications
You must be signed in to change notification settings - Fork 68
/
run.sh
executable file
·352 lines (321 loc) · 9.75 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
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
#!/bin/bash
set -e
readonly SCRIPT_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "${SCRIPT_PATH}/helpers.sh"
readonly BUILDER_CI_REPO_URL="https://github.com/dalehenrich/builderCI"
readonly BUILDER_CI_DOWNLOAD_URL="${BUILDER_CI_REPO_URL}/archive/master.zip"
readonly DEFAULT_STON_CONFIG='smalltalk.ston'
################################################################################
# Check OS to be Linux or OS X, otherwise exit with '1'.
################################################################################
check_os() {
local os_name=$(uname -s)
case "${os_name}" in
"Linux"|"Darwin")
;;
*)
print_error_and_exit "Unsupported platform '${os_name}'."
;;
esac
}
################################################################################
# Set and verify $config_project_home and $config_ston if applicable.
# Locals:
# config_project_home
# config_ston
# Globals:
# TRAVIS_BUILD_DIR
# Arguments:
# Custom project home path
################################################################################
determine_project() {
local custom_ston=$1
if is_file "${custom_ston}"; then
config_ston=$(basename "${custom_ston}")
config_project_home="$(dirname "${custom_ston}")"
elif is_travis_build; then
config_project_home="${TRAVIS_BUILD_DIR}"
locate_ston_config
else
print_error_and_exit "No valid STON provided and not running on Travis."
fi
# Convert to absolute path if necessary
if [[ "${config_project_home:0:1}" != "/" ]]; then
config_project_home="$(cd "${config_project_home}" && pwd)"
fi
if ! is_dir "${config_project_home}"; then
print_error_and_exit "Project home cannot be found."
fi
}
################################################################################
# Allow STON config filename to start with a dot.
# Locals:
# config_project_home
# Globals:
# DEFAULT_STON_CONFIG
################################################################################
locate_ston_config() {
if ! is_file "${config_project_home}/${DEFAULT_STON_CONFIG}"; then
if is_file "${config_project_home}/.${DEFAULT_STON_CONFIG}"; then
config_ston=".${DEFAULT_STON_CONFIG}"
else
print_error_and_exit "STON cannot be found."
fi
fi
}
################################################################################
# Validate options and exit with '1' if an option is invalid.
# Locals:
# config_smalltalk
################################################################################
validate_configuration() {
if is_empty "${config_smalltalk}"; then
print_error_and_exit "Smalltalk image is not defined."
fi
}
################################################################################
# Make sure global path variables are set for local builds.
# Globals:
# SMALLTALK_CI_HOME
################################################################################
check_and_set_paths() {
if is_empty "${SMALLTALK_CI_HOME}" && ! is_travis_build; then
export SMALLTALK_CI_HOME="${SCRIPT_PATH}"
source "${SMALLTALK_CI_HOME}/env_vars"
fi
}
################################################################################
# Load options from project's '.travis.yml', global environment variables and
# user's parameters.
# Locals:
# config_builder_ci_fallback
# config_smalltalk
# Arguments:
# All positional parameters
################################################################################
parse_args() {
if ! is_travis_build && [[ $# -eq 0 ]]; then
print_help
exit 0
fi
determine_project "${!#}" # Use last argument for custom STON
# Handle all arguments and flags
while :
do
case "$1" in
--builder-ci)
config_builder_ci_fallback="true"
shift
;;
--clean)
config_clean="true"
shift
;;
-d | --debug)
config_debug="true"
shift
;;
-h | --help)
print_help
exit 0
;;
--headfull)
config_headless="false"
shift
;;
-s | --smalltalk)
config_smalltalk="$2"
shift 2
;;
-v | --verbose)
config_verbose="true"
shift
;;
--)
shift
break
;;
-*)
print_error_and_exit "Unknown option: $1"
;;
*)
break
;;
esac
done
validate_configuration
}
is_fallback_enabled() {
[[ "${config_builder_ci_fallback}" = "true" ]]
}
################################################################################
# Initiate builderCI fallback build.
# Locals:
# config_smalltalk
# config_project_home
# Globals:
# BUILDER_CI_DOWNLOAD_URL
# Returns:
# builderCI status code
################################################################################
builder_ci_fallback() {
# Make sure the script runs on Linux
if [[ "$(uname -s)" != "Linux" ]]; then
print_error_and_exit "builderCI only supports Linux builds."
fi
if is_travis_build; then
# Make sure the script runs on standard infrastructure
sudo -n true
if [[ "$?" != 0 ]]; then
print_error_and_exit "sudo is not available."
fi
fi
print_info "Starting legacy build using builderCI..."
export ST="${config_smalltalk}"
export PROJECT_HOME="${config_project_home}"
cd "${HOME}"
wget -q -O builderCI.zip "${BUILDER_CI_DOWNLOAD_URL}"
unzip -q builderCI.zip
cd builderCI-*
source build_env_vars
ln -s "${PROJECT_HOME}" "${GIT_PATH}"
print_info "builderCI: Build image..."
./build_image.sh
print_info "builderCI: Run tests..."
"$BUILDER_CI_HOME/testTravisCI.sh" -verbose
return $?
}
################################################################################
# Make sure all required folders exist, create build folder and symlink project.
# Locals:
# config_project_home
# Globals:
# SMALLTALK_CI_CACHE
# SMALLTALK_CI_BUILD_BASE
# SMALLTALK_CI_VMS
# SMALLTALK_CI_BUILD
# SMALLTALK_CI_GIT
################################################################################
prepare_folders() {
print_info "Preparing folders..."
is_dir "${SMALLTALK_CI_CACHE}" || mkdir "${SMALLTALK_CI_CACHE}"
is_dir "${SMALLTALK_CI_BUILD_BASE}" || mkdir "${SMALLTALK_CI_BUILD_BASE}"
is_dir "${SMALLTALK_CI_VMS}" || mkdir "${SMALLTALK_CI_VMS}"
# Create folder for this build
if is_dir "${SMALLTALK_CI_BUILD}"; then
print_info "Build folder already exists at ${SMALLTALK_CI_BUILD}."
else
mkdir "${SMALLTALK_CI_BUILD}"
fi
# Link project folder to git_cache
ln -s "${config_project_home}" "${SMALLTALK_CI_GIT}"
}
################################################################################
# Run cleanup if requested by user.
# Locals:
# config_clean
################################################################################
check_clean_up() {
local user_input
local question1="Are you sure you want to clear builds and cache? (y/N): "
local question2="Continue with build? (y/N): "
if [[ "${config_clean}" = "true" ]]; then
read -p "${question1}" user_input
if [[ "${user_input}" = "y" ]]; then
clean_up
fi
read -p "${question2}" user_input
[[ "${user_input}" != "y" ]] && exit 0
fi
return 0
}
################################################################################
# Remove all builds and clear cache.
# Globals:
# SMALLTALK_CI_CACHE
# SMALLTALK_CI_BUILD_BASE
################################################################################
clean_up() {
if is_dir "${SMALLTALK_CI_CACHE}" || \
! is_dir "${SMALLTALK_CI_BUILD_BASE}"; then
print_info "Cleaning up..."
print_info "Removing the following directories:"
print_info " ${SMALLTALK_CI_CACHE}"
print_info " ${SMALLTALK_CI_BUILD_BASE}"
rm -rf "${SMALLTALK_CI_CACHE}" "${SMALLTALK_CI_BUILD_BASE}"
print_info "Done."
else
print_notice "Nothing to clean up."
fi
}
################################################################################
# Load platform-specific package and run the build.
# Locals:
# config_smalltalk
# Returns:
# Status code of build
################################################################################
run() {
case "${config_smalltalk}" in
Squeak*)
print_info "Starting Squeak build..."
source "${SMALLTALK_CI_HOME}/squeak/run.sh"
;;
Pharo*)
print_info "Starting Pharo build..."
source "${SMALLTALK_CI_HOME}/pharo/run.sh"
;;
GemStone*)
print_info "Starting GemStone build..."
source "${SMALLTALK_CI_HOME}/gemstone/run.sh"
;;
*)
print_error_and_exit "Unknown Smalltalk version '${config_smalltalk}'."
;;
esac
if debug_enabled; then
travis_fold start display_config "Current configuration"
for var in ${!config_@}; do
echo "${var}=${!var}"
done
travis_fold end display_config
fi
run_build
return $?
}
################################################################################
# Main entry point. Exit with build status code.
# Arguments:
# All positional parameters
################################################################################
main() {
local config_smalltalk="${TRAVIS_SMALLTALK_VERSION}"
local config_ston="${DEFAULT_STON_CONFIG}"
local config_project_home
local config_builder_ci_fallback="false"
local config_clean="false"
local config_debug="false"
local config_headless="true"
local config_verbose="false"
local exit_status=0
check_os
parse_args "$@"
[[ "${config_verbose}" = "true" ]] && set -x
check_and_set_paths
check_clean_up
if is_fallback_enabled; then
builder_ci_fallback || exit_status=$?
else
prepare_folders
run || exit_status=$?
if [[ "${exit_status}" -ne 0 ]]; then
print_error "Failed to load and test project."
exit ${exit_status}
fi
fi
print_results "${SMALLTALK_CI_BUILD}" || exit_status=$?
exit ${exit_status}
}
if [[ "$(basename -- "$0")" = "run.sh" ]]; then
main "$@"
fi