1 | #!/bin/bash |
---|
2 | |
---|
3 | # https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/ |
---|
4 | set -euxo pipefail |
---|
5 | |
---|
6 | # The filesystem location of the root of a virtualenv we can use to get/build |
---|
7 | # wheels. |
---|
8 | BOOTSTRAP_VENV="$1" |
---|
9 | shift |
---|
10 | |
---|
11 | # The filesystem location of the root of the project source. We need this to |
---|
12 | # know what wheels to get/build, of course. |
---|
13 | PROJECT_ROOT="$1" |
---|
14 | shift |
---|
15 | |
---|
16 | ALLOWED_FAILURE="$1" |
---|
17 | shift |
---|
18 | |
---|
19 | ARTIFACTS=$1 |
---|
20 | shift |
---|
21 | |
---|
22 | TAHOE_LAFS_TOX_ENVIRONMENT=$1 |
---|
23 | shift |
---|
24 | |
---|
25 | TAHOE_LAFS_TOX_ARGS=$1 |
---|
26 | shift || : |
---|
27 | |
---|
28 | if [ -n "${ARTIFACTS}" ]; then |
---|
29 | # If given an artifacts path, prepare to have some artifacts created |
---|
30 | # there. The integration tests don't produce any artifacts; that is the |
---|
31 | # case where we expect not to end up here. |
---|
32 | |
---|
33 | # Make sure we can actually write things to this directory. |
---|
34 | mkdir -p "${ARTIFACTS}" |
---|
35 | |
---|
36 | SUBUNIT2="${ARTIFACTS}"/results.subunit2 |
---|
37 | |
---|
38 | # Use an intermediate directory here because CircleCI extracts some label |
---|
39 | # information from its name. |
---|
40 | JUNITXML="${ARTIFACTS}"/junit/unittests/results.xml |
---|
41 | else |
---|
42 | SUBUNIT2="" |
---|
43 | JUNITXML="" |
---|
44 | fi |
---|
45 | |
---|
46 | # A prefix for the test command that ensure it will exit after no more than a |
---|
47 | # certain amount of time. Ideally, we would only enforce a "silent" period |
---|
48 | # timeout but there isn't obviously a ready-made tool for that. The unit test |
---|
49 | # suite only takes about 5 - 6 minutes on CircleCI right now. The integration |
---|
50 | # tests are a bit longer than that. 45 minutes seems like a moderately safe |
---|
51 | # window. |
---|
52 | # |
---|
53 | # This is primarily aimed at catching hangs on the PyPy job which runs for |
---|
54 | # about 21 minutes and then gets killed by CircleCI in a way that fails the |
---|
55 | # job and bypasses our "allowed failure" logic. |
---|
56 | TIMEOUT="timeout --kill-after 1m 45m" |
---|
57 | |
---|
58 | # Run the test suite as a non-root user. This is the expected usage some |
---|
59 | # small areas of the test suite assume non-root privileges (such as unreadable |
---|
60 | # files being unreadable). |
---|
61 | # |
---|
62 | # Also run with /tmp as a workdir because the non-root user won't be able to |
---|
63 | # create the tox working filesystem state in the source checkout because it is |
---|
64 | # owned by root. |
---|
65 | # |
---|
66 | # Send the output directly to a file because transporting the binary subunit2 |
---|
67 | # via tox and then scraping it out is hideous and failure prone. |
---|
68 | export SUBUNITREPORTER_OUTPUT_PATH="${SUBUNIT2}" |
---|
69 | export TAHOE_LAFS_TRIAL_ARGS="${TAHOE_LAFS_TRIAL_ARGS:---reporter=subunitv2-file --rterrors}" |
---|
70 | export PIP_NO_INDEX="1" |
---|
71 | |
---|
72 | # Make output unbuffered, so progress reports from subunitv2-file get streamed |
---|
73 | # and notify CircleCI we're still alive. |
---|
74 | export PYTHONUNBUFFERED=1 |
---|
75 | |
---|
76 | if [ "${ALLOWED_FAILURE}" = "yes" ]; then |
---|
77 | alternative="true" |
---|
78 | else |
---|
79 | alternative="false" |
---|
80 | fi |
---|
81 | |
---|
82 | WORKDIR=/tmp/tahoe-lafs.tox |
---|
83 | ${TIMEOUT} ${BOOTSTRAP_VENV}/bin/tox \ |
---|
84 | -c ${PROJECT_ROOT}/tox.ini \ |
---|
85 | --workdir "${WORKDIR}" \ |
---|
86 | -e "${TAHOE_LAFS_TOX_ENVIRONMENT}" \ |
---|
87 | ${TAHOE_LAFS_TOX_ARGS} || "${alternative}" |
---|
88 | |
---|
89 | if [ -n "${ARTIFACTS}" ]; then |
---|
90 | if [ ! -e "${SUBUNIT2}" ]; then |
---|
91 | echo "subunitv2 output file does not exist: ${SUBUNIT2}" |
---|
92 | exit 1 |
---|
93 | fi |
---|
94 | |
---|
95 | # Create a junitxml results area. |
---|
96 | mkdir -p "$(dirname "${JUNITXML}")" |
---|
97 | |
---|
98 | "${WORKDIR}/${TAHOE_LAFS_TOX_ENVIRONMENT}/bin/subunit2junitxml" < "${SUBUNIT2}" > "${JUNITXML}" || "${alternative}" |
---|
99 | fi |
---|