From a2d32621f8c32d131508451e7eb3b4fafc534347 Mon Sep 17 00:00:00 2001 From: Phillip Wood Date: Wed, 1 Nov 2023 10:53:57 +0000 Subject: [PATCH] ci: always run tests as an unprivileged user Signed-off-by: Phillip Wood --- .gitlab-ci.yml | 4 +--- ci/run-build-and-tests.sh | 7 +++++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index cd98bcb18aa38a..a96d3e09053999 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -12,9 +12,7 @@ test: before_script: - ./ci/install-docker-dependencies.sh script: - - useradd builder --create-home - - chown -R builder "${CI_PROJECT_DIR}" - - sudo --preserve-env --set-home --user=builder ./ci/run-build-and-tests.sh + - ./ci/run-build-and-tests.sh after_script: - | if test "$CI_JOB_STATUS" != 'success' diff --git a/ci/run-build-and-tests.sh b/ci/run-build-and-tests.sh index 2528f25e31d3c8..b9441551ebd3e3 100755 --- a/ci/run-build-and-tests.sh +++ b/ci/run-build-and-tests.sh @@ -3,6 +3,13 @@ # Build and test Git # +if test "$(id -u)" -eq 0 +then + useradd --home-dir "$(pwd)" builder + chown -R builder . + exec sudo --preserve-env --set-home --user=builder "$0" +fi + . ${0%/*}/lib.sh case "$CI_OS_NAME" in