blob: 6cd832efb9cb59687fac4cf95bf471bc87923a96 [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
Ævar Arnfjörð Bjarmasonc08bb262021-11-23 17:29:10 +010018linux32)
Đoàn Trần Công Danh2bd1e2d2020-04-04 08:08:47 +070019 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
SZEDER Gábor53303302018-01-29 18:17:12 +010050fi
Johannes Schindelin88dedd52017-03-05 19:25:19 +010051
52# Build and test
Đoàn Trần Công Danh2bd1e2d2020-04-04 08:08:47 +070053command $switch_cmd su -m -l $CI_USER -c "
SZEDER Gábor04d47e92018-01-29 18:17:10 +010054 set -ex
Đoàn Trần Công Danhffce2eb2020-04-04 08:08:46 +070055 export DEVELOPER='$DEVELOPER'
56 export DEFAULT_TEST_TARGET='$DEFAULT_TEST_TARGET'
57 export GIT_PROVE_OPTS='$GIT_PROVE_OPTS'
58 export GIT_TEST_OPTS='$GIT_TEST_OPTS'
59 export GIT_TEST_CLONE_2GB='$GIT_TEST_CLONE_2GB'
60 export MAKEFLAGS='$MAKEFLAGS'
61 export cache_dir='$cache_dir'
SZEDER Gábor04d47e92018-01-29 18:17:10 +010062 cd /usr/src/git
Đoàn Trần Công Danhffce2eb2020-04-04 08:08:46 +070063 test -n '$cache_dir' && ln -s '$cache_dir/.prove' t/.prove
Johannes Schindelineaa62292019-01-27 15:26:52 -080064 make
SZEDER Gáborbbf24ad2019-01-17 02:29:11 +010065 make test
Đoàn Trần Công Danhffce2eb2020-04-04 08:08:46 +070066"