ci/linux32: libify install-dependencies step
[git] / ci / run-docker-build.sh
1 #!/bin/sh
2 #
3 # Build and test Git inside container
4 #
5 # Usage:
6 #   run-docker-build.sh <host-user-id>
7 #
8
9 set -ex
10
11 if test $# -ne 1 || test -z "$1"
12 then
13         echo >&2 "usage: run-docker-build.sh <host-user-id>"
14         exit 1
15 fi
16
17 case "$jobname" in
18 Linux32)
19         switch_cmd="linux32 --32bit i386"
20         ;;
21 *)
22         exit 1
23         ;;
24 esac
25
26 "${0%/*}/install-docker-dependencies.sh"
27
28 # If this script runs inside a docker container, then all commands are
29 # usually executed as root. Consequently, the host user might not be
30 # able to access the test output files.
31 # If a non 0 host user id is given, then create a user "ci" with that
32 # user id to make everything accessible to the host user.
33 HOST_UID=$1
34 if test $HOST_UID -eq 0
35 then
36         # Just in case someone does want to run the test suite as root.
37         CI_USER=root
38 else
39         CI_USER=ci
40         if test "$(id -u $CI_USER 2>/dev/null)" = $HOST_UID
41         then
42                 echo "user '$CI_USER' already exists with the requested ID $HOST_UID"
43         else
44                 useradd -u $HOST_UID $CI_USER
45         fi
46
47         # Due to a bug the test suite was run as root in the past, so
48         # a prove state file created back then is only accessible by
49         # root.  Now that bug is fixed, the test suite is run as a
50         # regular user, but the prove state file coming from Travis
51         # CI's cache might still be owned by root.
52         # Make sure that this user has rights to any cached files,
53         # including an existing prove state file.
54         test -n "$cache_dir" && chown -R $HOST_UID:$HOST_UID "$cache_dir"
55 fi
56
57 # Build and test
58 command $switch_cmd su -m -l $CI_USER -c "
59         set -ex
60         export DEVELOPER='$DEVELOPER'
61         export DEFAULT_TEST_TARGET='$DEFAULT_TEST_TARGET'
62         export GIT_PROVE_OPTS='$GIT_PROVE_OPTS'
63         export GIT_TEST_OPTS='$GIT_TEST_OPTS'
64         export GIT_TEST_CLONE_2GB='$GIT_TEST_CLONE_2GB'
65         export MAKEFLAGS='$MAKEFLAGS'
66         export cache_dir='$cache_dir'
67         cd /usr/src/git
68         test -n '$cache_dir' && ln -s '$cache_dir/.prove' t/.prove
69         make
70         make test
71 "