Repository navigation
Expand file tree
/
Copy pathtest-runner.sh
More file actions
executable file
·84 lines (76 loc) · 2.8 KB
/
Copy pathtest-runner.sh
File metadata and controls
executable file
·84 lines (76 loc) · 2.8 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
79
80
81
82
83
84
#!/bin/sh
# ------------------------------------------------------------
# test-runner.sh – Semi-automated integration test runner
# ------------------------------------------------------------
# ------------------------------------------------------------
# Script/base dir
# ------------------------------------------------------------
get_base_dir() {
if [ -f "${0}" ]
then
# $0 points to a file on disk
printf '%s\n' "$(cd -- "$(dirname -- "${0}")" && pwd -P)"
else
# The script was sourced in a shell where $0 is not the script path
# Fallback to the current working directory
printf '%s\n' "$(pwd -P)"
fi
}
# ------------------------------------------------------------
# Check .env presence
# ------------------------------------------------------------
check_dot_env_file() {
if [ ! -f "${BASE_DIR}/.env" ]
then
cp "${BASE_DIR}/.env.template" "${BASE_DIR}/.env"
fi
if ! grep -q '^TEST_HOSTNAME=' "${BASE_DIR}/.env"
then
printf '\n' >> .env
cat "${BASE_DIR}/.test.env.template" >> "${BASE_DIR}/.env"
fi
}
# ------------------------------------------------------------
# rsync cwd
# ------------------------------------------------------------
deploy_src() {
rsync --times --partial --recursive --delete --rsh="ssh -o BatchMode=yes" . "${TEST_HOSTNAME}:${TEST_REMOTE_HOME}/${TEST_APP_NAME}" || fail_internal "Failed to deploy source code"
}
# ------------------------------------------------------------
# Main function to prevent occasional environment pollution
# ------------------------------------------------------------
closure() {
set -e
#set -x # Debug
# Define BASE_DIR
BASE_DIR="$(get_base_dir)"
# Load library
LIB_SH="${BASE_DIR}/lib.sh"
if [ ! -e "${LIB_SH}" ]
then
printf "${LIB_SH} does not exist, exiting\n"
exit 1
fi
# shellcheck source=lib.sh
if ! . "${LIB_SH}"
then
printf "Could not load ${LIB_SH}, exiting\n"
exit 1
fi
unset LIB_SH
# Do the job
cd "${BASE_DIR}"
check_dot_env_file
environment
check_mandatory_variables_set ".test.env.template"
if ! printf '%s\n' "${TEST_APP_NAME}" | grep -qE '^[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz][ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-]+$'
then
fail_internal "TEST_APP_NAME contains unsafe characters ${TEST_APP_NAME} — only latin letters and '-' are allowed"
fi
ssh "${TEST_HOSTNAME}" "rm -rf ${TEST_APP_NAME}" || fail_internal "Failed to remove ${TEST_APP_NAME} via SSH"
deploy_src
ssh "${TEST_HOSTNAME}" "${TEST_APP_NAME}/debug.sh" || fail_internal "./debug.sh via SSH failed"
ssh "${TEST_HOSTNAME}" "${TEST_APP_NAME}/test.sh" || fail_internal "./test.sh via SSH failed"
unset BASE_DIR
}
closure