blob: 8d47a5fda3b1c929a68662cfca3625e63e122194 [file] [log] [blame]
Johannes Schindelin88dedd52017-03-05 19:25:19 +01001#!/bin/sh
2#
Đoàn Trần Công Danh5a33f542020-04-04 08:08:48 +07003# Build and test Git inside container
Johannes Schindelin88dedd52017-03-05 19:25:19 +01004#
5# Usage:
Đoàn Trần Công Danh5a33f542020-04-04 08:08:48 +07006# run-docker-build.sh <host-user-id>
Johannes Schindelin88dedd52017-03-05 19:25:19 +01007#
8
SZEDER Gábor04d47e92018-01-29 18:17:10 +01009set -ex
SZEDER Gábora8b8b6b2017-12-27 17:36:00 +010010
SZEDER Gábor53303302018-01-29 18:17:12 +010011if test $# -ne 1 || test -z "$1"
12then
Đoàn Trần Công Danh5a33f542020-04-04 08:08:48 +070013 echo >&2 "usage: run-docker-build.sh <host-user-id>"
SZEDER Gábor53303302018-01-29 18:17:12 +010014 exit 1
15fi
16
Đoàn Trần Công Danh2bd1e2d2020-04-04 08:08:47 +070017case "$jobname" in
18Linux32)
19 switch_cmd="linux32 --32bit i386"
20 ;;
Đoàn Trần Công Danhe0f86902020-04-04 08:08:50 +070021linux-musl)
22 switch_cmd=
23 useradd () { adduser -D "$@"; }
24 ;;
Đoàn Trần Công Danh2bd1e2d2020-04-04 08:08:47 +070025*)
26 exit 1
27 ;;
28esac
29
Đoàn Trần Công Danhc3bc4492020-04-04 08:08:49 +070030"${0%/*}/install-docker-dependencies.sh"
Johannes Schindelin88dedd52017-03-05 19:25:19 +010031
32# If this script runs inside a docker container, then all commands are
33# usually executed as root. Consequently, the host user might not be
34# able to access the test output files.
SZEDER Gábor53303302018-01-29 18:17:12 +010035# If a non 0 host user id is given, then create a user "ci" with that
36# user id to make everything accessible to the host user.
SZEDER Gábor04d47e92018-01-29 18:17:10 +010037HOST_UID=$1
SZEDER Gábor53303302018-01-29 18:17:12 +010038if test $HOST_UID -eq 0
39then
40 # Just in case someone does want to run the test suite as root.
41 CI_USER=root
42else
43 CI_USER=ci
SZEDER Gábor6b995762018-01-29 18:17:13 +010044 if test "$(id -u $CI_USER 2>/dev/null)" = $HOST_UID
45 then
46 echo "user '$CI_USER' already exists with the requested ID $HOST_UID"
47 else
48 useradd -u $HOST_UID $CI_USER
49 fi
50
SZEDER Gábor53303302018-01-29 18:17:12 +010051 # Due to a bug the test suite was run as root in the past, so
52 # a prove state file created back then is only accessible by
53 # root. Now that bug is fixed, the test suite is run as a
54 # regular user, but the prove state file coming from Travis
55 # CI's cache might still be owned by root.
56 # Make sure that this user has rights to any cached files,
57 # including an existing prove state file.
58 test -n "$cache_dir" && chown -R $HOST_UID:$HOST_UID "$cache_dir"
59fi
Johannes Schindelin88dedd52017-03-05 19:25:19 +010060
61# Build and test
Đoàn Trần Công Danh2bd1e2d2020-04-04 08:08:47 +070062command $switch_cmd su -m -l $CI_USER -c "
SZEDER Gábor04d47e92018-01-29 18:17:10 +010063 set -ex
Đoàn Trần Công Danhffce2eb2020-04-04 08:08:46 +070064 export DEVELOPER='$DEVELOPER'
65 export DEFAULT_TEST_TARGET='$DEFAULT_TEST_TARGET'
66 export GIT_PROVE_OPTS='$GIT_PROVE_OPTS'
67 export GIT_TEST_OPTS='$GIT_TEST_OPTS'
68 export GIT_TEST_CLONE_2GB='$GIT_TEST_CLONE_2GB'
69 export MAKEFLAGS='$MAKEFLAGS'
70 export cache_dir='$cache_dir'
SZEDER Gábor04d47e92018-01-29 18:17:10 +010071 cd /usr/src/git
Đoàn Trần Công Danhffce2eb2020-04-04 08:08:46 +070072 test -n '$cache_dir' && ln -s '$cache_dir/.prove' t/.prove
Johannes Schindelineaa62292019-01-27 15:26:52 -080073 make
SZEDER Gáborbbf24ad2019-01-17 02:29:11 +010074 make test
Đoàn Trần Công Danhffce2eb2020-04-04 08:08:46 +070075"