doc: Clarify the release process for a first stable
[tor.git] / scripts / ci / ci-driver.sh
blobef31da1ca35620b2e0025b8b4323efbe8235304d
1 #!/bin/bash
3 ####
4 # DO NOT EDIT THIS FILE IN MASTER. ONLY EDIT IT IN THE OLDEST SUPPORTED
5 # BRANCH, THEN MERGE FORWARD.
6 ####
8 # This script is used to build Tor for continuous integration. It should
9 # be kept the same for all supported Tor versions.
11 # It's subject to the regular Tor license; see LICENSE for copying
12 # information.
14 set -o errexit
15 set -o nounset
17 # Options for this script.
18 DEBUG_CI="${DEBUG_CI:-no}"
19 COLOR_CI="${COLOR_CI:-yes}"
21 # Options for which CI system this is.
22 ON_GITLAB="${ON_GITLAB:-yes}"
24 # Options for things we usually won't want to skip.
25 RUN_STAGE_CONFIGURE="${RUN_STAGE_CONFIGURE:-yes}"
26 RUN_STAGE_BUILD="${RUN_STAGE_BUILD:-yes}"
27 RUN_STAGE_TEST="${RUN_STAGE_TEST:-yes}"
29 # Options for how to build Tor. All should be yes/no.
30 FATAL_WARNINGS="${FATAL_WARNINGS:-yes}"
31 HARDENING="${HARDENING:-no}"
32 COVERAGE="${COVERAGE:-no}"
33 DOXYGEN="${DOXYGEN:-no}"
34 ASCIIDOC="${ASCIIDOC:-no}"
35 TRACING="${TRACING:-no}"
36 ALL_BUGS_ARE_FATAL="${ALL_BUGS_ARE_FATAL:-no}"
37 DISABLE_DIRAUTH="${DISABLE_DIRAUTH:-no}"
38 DISABLE_RELAY="${DISABLE_RELAY:-no}"
39 NSS="${NSS:-no}"
41 # Options for which tests to run. All should be yes/no.
42 CHECK="${CHECK:-yes}"
43 STEM="${STEM:-no}"
44 CHUTNEY="${CHUTNEY:-no}"
45 DISTCHECK="${DISTCHECK:-no}"
47 # Options for where the Tor source is.
48 CI_SRCDIR="${CI_SRCDIR:-.}"
50 # Options for where to build.
51 CI_BUILDDIR="${CI_BUILDDIR:-./build}"
53 # How parallel should we run make?
54 MAKE_J_OPT="${MAKE_J_OPT:--j4}"
55 # Should we stop after make finds an error?
56 MAKE_K_OPT="${MAKE_K_OPT:--k}"
58 # What make target should we use for chutney?
59 CHUTNEY_MAKE_TARGET="${CHUTNEY_MAKE_TARGET:-test-network}"
61 # Where do we find our additional testing tools?
62 CHUTNEY_PATH="${CHUTNEY_PATH:-}"
63 STEM_PATH="${STEM_PATH:-}"
65 #############################################################################
66 # Preliminary functions.
68 # Terminal coloring/emphasis stuff.
69 if [[ "${COLOR_CI}" == "yes" ]]; then
70 T_RED=$(tput setaf 1 || true)
71 T_GREEN=$(tput setaf 2 || true)
72 T_YELLOW=$(tput setaf 3 || true)
73 T_DIM=$(tput dim || true)
74 T_BOLD=$(tput bold || true)
75 T_RESET=$(tput sgr0 || true)
76 else
77 T_RED=
78 T_GREEN=
79 T_YELLOW=
80 T_DIM=
81 T_BOLD=
82 T_RESET=
85 function error()
87 echo "${T_BOLD}${T_RED}ERROR:${T_RESET} $*" 1>&2
90 function die()
92 echo "${T_BOLD}${T_RED}FATAL ERROR:${T_RESET} $*" 1>&2
93 exit 1
96 function skipping()
98 echo "${T_BOLD}${T_YELLOW}Skipping $*${T_RESET}"
101 function hooray()
103 echo "${T_BOLD}${T_GREEN}$*${T_RESET}"
106 if [[ "${DEBUG_CI}" == "yes" ]]; then
107 function debug()
109 echo "${T_DIM}(debug): $*${T_RESET}"
111 else
112 function debug()
118 function yes_or_no()
120 local varname="$1"
121 local value="${!varname}"
122 debug "${varname} is ${value}"
123 if [[ "${value}" != 'yes' && "${value}" != 'no' ]]; then
124 die "${varname} must be 'yes' or 'no'. Got unexpected value ${value}".
128 function incompatible()
130 local varname1="$1"
131 local varname2="$2"
132 local val1="${!varname1}"
133 local val2="${!varname2}"
134 if [[ "${val1}" = 'yes' && "${val2}" = 'yes' ]]; then
135 die "Cannot set both ${varname1} and ${varname2}: they are incompatible."
139 function runcmd()
141 echo "${T_BOLD}\$ $*${T_RESET}"
142 if ! "$@" ; then
143 error "command '$*' has failed."
144 return 1
148 function show_git_version()
150 local tool="$1"
151 local dir="$2"
152 local version="?????"
153 if [[ -e "$dir/.git" ]] ; then
154 version=$(cd "$dir"; git rev-parse HEAD)
156 echo "${T_BOLD}$tool:${T_RESET} $version"
159 if [[ "${ON_GITLAB}" == "yes" ]]; then
160 function start_section()
162 local label="$1"
163 local stamp
164 stamp=$(date +%s)
165 printf "section_start:%s:%s\r\e[0K" "$stamp" "$label"
166 echo "${T_BOLD}${T_GREEN}========= $label${T_RESET}"
168 function end_section()
170 local label="$1"
171 local stamp
172 stamp=$(date +%s)
173 printf "section_end:%s:%s\r\e[0K" "$stamp" "$label"
175 else
176 function start_section()
178 true
180 function end_section()
182 true
186 #############################################################################
187 # Validate inputs.
189 debug Validating inputs
190 yes_or_no DEBUG_CI
191 yes_or_no COLOR_CI
192 yes_or_no ON_GITLAB
193 yes_or_no FATAL_WARNINGS
194 yes_or_no HARDENING
195 yes_or_no COVERAGE
196 yes_or_no DOXYGEN
197 yes_or_no ASCIIDOC
198 yes_or_no TRACING
199 yes_or_no ALL_BUGS_ARE_FATAL
200 yes_or_no DISABLE_DIRAUTH
201 yes_or_no DISABLE_RELAY
202 yes_or_no NSS
204 yes_or_no RUN_STAGE_CONFIGURE
205 yes_or_no RUN_STAGE_BUILD
206 yes_or_no RUN_STAGE_TEST
208 yes_or_no CHECK
209 yes_or_no STEM
210 yes_or_no DISTCHECK
212 incompatible DISTCHECK CHECK
213 incompatible DISTCHECK CHUTNEY
214 incompatible DISTCHECK STEM
215 incompatible DISTCHECK COVERAGE
216 incompatible DISTCHECK DOXYGEN
218 if [[ "${CHUTNEY}" = yes && "${CHUTNEY_PATH}" = '' ]] ; then
219 die "CHUTNEY is set to 'yes', but CHUTNEY_PATH was not specified."
222 if [[ "${STEM}" = yes && "${STEM_PATH}" = '' ]] ; then
223 die "STEM is set to 'yes', but STEM_PATH was not specified."
226 #############################################################################
227 # Set up options for make and configure.
229 make_options=()
230 if [[ "$MAKE_J_OPT" != "" ]]; then
231 make_options+=("$MAKE_J_OPT")
233 if [[ "$MAKE_K_OPT" != "" ]]; then
234 make_options+=("$MAKE_K_OPT")
237 configure_options=()
238 if [[ "$FATAL_WARNINGS" == "yes" ]]; then
239 configure_options+=("--enable-fatal-warnings")
241 if [[ "$HARDENING" == "yes" ]]; then
242 configure_options+=("--enable-fragile-hardening")
244 if [[ "$COVERAGE" == "yes" ]]; then
245 configure_options+=("--enable-coverage")
247 if [[ "$ASCIIDOC" != "yes" ]]; then
248 configure_options+=("--disable-asciidoc")
250 if [[ "$TRACING" == "yes" ]]; then
251 configure_options+=("--enable-tracing-instrumentation-lttng")
253 if [[ "$ALL_BUGS_ARE_FATAL" == "yes" ]]; then
254 configure_options+=("--enable-all-bugs-are-fatal")
256 if [[ "$DISABLE_DIRAUTH" == "yes" ]]; then
257 configure_options+=("--disable-module-dirauth")
259 if [[ "$DISABLE_RELAY" == "yes" ]]; then
260 configure_options+=("--disable-module-relay")
262 if [[ "$NSS" == "yes" ]]; then
263 configure_options+=("--enable-nss")
266 #############################################################################
267 # Tell the user about our versions of different tools and packages.
269 uname -a
270 printf "python: "
271 python -V || echo "no 'python' binary."
272 printf "python3: "
273 python3 -V || echo "no 'python3' binary."
275 show_git_version Tor "${CI_SRCDIR}"
276 if [[ "${STEM}" = "yes" ]]; then
277 show_git_version Stem "${STEM_PATH}"
279 if [[ "${CHUTNEY}" = "yes" ]]; then
280 show_git_version Chutney "${CHUTNEY_PATH}"
283 #############################################################################
284 # Determine the version of Tor.
286 TOR_VERSION=$(grep -m 1 AC_INIT "${CI_SRCDIR}"/configure.ac | sed -e 's/.*\[//; s/\].*//;')
288 # Use variables like these when we need to behave differently depending on
289 # Tor version. Only create the variables we need.
290 TOR_VER_AT_LEAST_043=no
291 TOR_VER_AT_LEAST_044=no
293 # These are the currently supported Tor versions; no need to work with anything
294 # ancient in this script.
295 case "$TOR_VERSION" in
296 0.4.5.*)
297 TOR_VER_AT_LEAST_043=yes
298 TOR_VER_AT_LEAST_044=yes
300 0.4.6.*)
301 TOR_VER_AT_LEAST_043=yes
302 TOR_VER_AT_LEAST_044=yes
304 0.4.7.*)
305 TOR_VER_AT_LEAST_043=yes
306 TOR_VER_AT_LEAST_044=yes
308 esac
310 #############################################################################
311 # Make sure the directories are all there.
313 # Make sure CI_SRCDIR exists and has a file we expect.
314 if [[ ! -d "$CI_SRCDIR" ]] ; then
315 die "CI_SRCDIR=${CI_SRCDIR} is not a directory"
317 if [[ ! -f "$CI_SRCDIR/src/core/or/or.h" ]] ; then
318 die "CI_SRCDIR=${CI_SRCDIR} does not look like a Tor directory."
321 # Make CI_SRCDIR absolute.
322 CI_SRCDIR=$(cd "$CI_SRCDIR" && pwd)
324 # Create an "artifacts" directory to copy artifacts into.
325 mkdir -p ./artifacts
327 if [[ "$RUN_STAGE_CONFIGURE" = "yes" ]]; then
329 start_section "Autogen"
330 runcmd cd "${CI_SRCDIR}"
331 runcmd ./autogen.sh
332 runcmd mkdir -p "${CI_BUILDDIR}"
333 runcmd cd "${CI_BUILDDIR}"
334 end_section "Autogen"
336 # make the builddir absolute too.
337 CI_BUILDDIR=$(pwd)
339 start_section "Configure"
340 if ! runcmd "${CI_SRCDIR}"/configure "${configure_options[@]}" ; then
341 error "Here is the end of config.log:"
342 runcmd tail config.log
343 die "Unable to continue"
345 end_section "Configure"
346 else
347 debug "Skipping configure stage. Making sure that ${CI_BUILDDIR}/config.log exists."
348 if [[ ! -d "${CI_BUILDDIR}" ]]; then
349 die "Build directory ${CI_BUILDDIR} did not exist!"
351 if [[ ! -f "${CI_BUILDDIR}/config.log" ]]; then
352 die "Tor was not configured in ${CI_BUILDDIR}!"
355 cp config.log "${CI_SRCDIR}"/artifacts
357 runcmd cd "${CI_BUILDDIR}"
358 CI_BUILDDIR=$(pwd)
361 ###############################
362 # Build Tor.
364 if [[ "$RUN_STAGE_BUILD" = "yes" ]] ; then
365 if [[ "$DISTCHECK" = "no" ]]; then
366 start_section "Build"
367 runcmd make "${make_options[@]}" all
368 cp src/app/tor "${CI_SRCDIR}"/artifacts
369 end_section "Build"
370 else
371 export DISTCHECK_CONFIGURE_FLAGS="${configure_options[*]}"
372 # XXXX Set make options?
373 start_section Distcheck
374 if runcmd make "${make_options[@]}" distcheck ; then
375 hooray "Distcheck was successful. Nothing further will be done."
376 # We have to exit early here, since we can't do any other tests.
377 cp tor-*.tar.gz "${CI_SRCDIR}"/artifacts
378 exit 0
379 else
380 error "Diagnostics:"
381 runcmd make show-distdir-testlog || true
382 runcmd make show-distdir-core || true
383 die "Unable to continue."
385 end_section Distcheck
389 ##############################
390 # Run tests.
392 if [[ "$RUN_STAGE_TEST" == "no" ]]; then
393 echo "Skipping tests. Exiting now."
394 exit 0
397 FAILED_TESTS=""
399 if [[ "${DOXYGEN}" = 'yes' ]]; then
400 start_section Doxygen
401 if [[ "${TOR_VER_AT_LEAST_043}" = 'yes' ]]; then
402 if runcmd make doxygen; then
403 hooray "make doxygen has succeeded."
404 else
405 FAILED_TESTS="${FAILED_TESTS} doxygen"
407 else
408 skipping "make doxygen: doxygen is broken for Tor < 0.4.3"
410 end_section Doxygen
413 if [[ "${ASCIIDOC}" = 'yes' ]]; then
414 start_section Asciidoc
415 if runcmd make manpages; then
416 hooray "make manpages has succeeded."
417 else
418 FAILED_TESTS="${FAILED_TESTS} asciidoc"
420 end_section Asciidoc
423 if [[ "${CHECK}" = "yes" ]]; then
424 start_section "Check"
425 if runcmd make "${make_options[@]}" check; then
426 hooray "make check has succeeded."
427 else
428 error "Here are the contents of the test suite output:"
429 runcmd cat test-suite.log || true
430 FAILED_TESTS="${FAILED_TESTS} check"
432 end_section "Check"
435 if [[ "${CHUTNEY}" = "yes" ]]; then
436 start_section "Chutney"
437 export CHUTNEY_TOR_SANDBOX=0
438 export CHUTNEY_ALLOW_FAILURES=2
439 # Send 5MB for every verify check.
440 export CHUTNEY_DATA_BYTES=5000000
441 if runcmd make "${CHUTNEY_MAKE_TARGET}"; then
442 hooray "Chutney tests have succeeded"
443 else
444 error "Chutney says:"
445 export CHUTNEY_DATA_DIR="${CHUTNEY_PATH}/net"
446 runcmd "${CHUTNEY_PATH}"/tools/diagnostics.sh || true
447 # XXXX These next two should be part of a make target.
448 runcmd ls test_network_log || true
449 runcmd head -n -0 test_network_log/* || true
450 FAILED_TESTS="${FAILED_TESTS} chutney"
452 end_section "Chutney"
455 if [[ "${STEM}" = "yes" ]]; then
456 start_section "Stem"
457 # 0.3.5 and onward have now disabled onion service v2 so we need to exclude
458 # these Stem tests from now on.
459 EXCLUDE_TESTS="--exclude-test control.controller.test_ephemeral_hidden_services_v2 --exclude-test control.controller.test_hidden_services_conf --exclude-test control.controller.test_with_ephemeral_hidden_services_basic_auth --exclude-test control.controller.test_without_ephemeral_hidden_services --exclude-test control.controller.test_with_ephemeral_hidden_services_basic_auth_no_credentials"
460 if [[ "${TOR_VER_AT_LEAST_044}" = 'yes' ]]; then
461 # XXXX This should probably be part of some test-stem make target.
463 # Disable the check around EXCLUDE_TESTS that requires double quote. We
464 # need it to be expanded.
465 # shellcheck disable=SC2086
466 if runcmd timelimit -p -t 520 -s USR1 -T 30 -S ABRT \
467 python3 "${STEM_PATH}/run_tests.py" \
468 --tor src/app/tor \
469 --integ --test control.controller \
470 $EXCLUDE_TESTS \
471 --test control.base_controller \
472 --test process \
473 --log TRACE \
474 --log-file stem.log ; then
475 hooray "Stem tests have succeeded"
476 else
477 error "Stem output:"
478 runcmd tail -1000 "${STEM_PATH}"/test/data/tor_log
479 runcmd grep -v "SocketClosed" stem.log | tail -1000
480 FAILED_TESTS="${FAILED_TESTS} stem"
482 else
483 skipping "Stem: broken with <= 0.4.3. See bug tor#40077"
485 end_section "Stem"
488 # TODO: Coverage
490 if [[ "${FAILED_TESTS}" != "" ]]; then
491 die "Failed tests: ${FAILED_TESTS}"
494 hooray "Everything seems fine."