diff --git a/ci/test/01_base_install.sh b/ci/test/01_base_install.sh index f8d337f6c90..308f7abe862 100755 --- a/ci/test/01_base_install.sh +++ b/ci/test/01_base_install.sh @@ -8,6 +8,11 @@ export LC_ALL=C.UTF-8 set -o errexit -o pipefail -o xtrace +if [ "${DANGER_RUN_CI_ON_HOST}" != "1" ]; then + echo "This script will make unsafe local and global modifications, so it can only be run inside a container and requires DANGER_RUN_CI_ON_HOST=1" + exit 1 +fi + CFG_DONE="${BASE_ROOT_DIR}/ci.base-install-done" # Use a global setting to remember whether this script ran to avoid running it twice if [ "$( cat "${CFG_DONE}" || true )" == "done" ]; then diff --git a/ci/test/02_run_container.py b/ci/test/02_run_container.py index dce3730a65a..abaa535553d 100755 --- a/ci/test/02_run_container.py +++ b/ci/test/02_run_container.py @@ -158,7 +158,13 @@ def main(): if os.getenv("DANGER_RUN_CI_ON_HOST"): prefix = [] else: - prefix = ["docker", "exec", container_id] + prefix = [ + "docker", + "exec", + "--env", + "DANGER_RUN_CI_ON_HOST=1", # Safe to set *inside* the container + container_id, + ] return run([*prefix, *cmd_inner], **kwargs) diff --git a/ci/test/03_test_script.sh b/ci/test/03_test_script.sh index eb03c2dd493..ff9f2fd60a5 100755 --- a/ci/test/03_test_script.sh +++ b/ci/test/03_test_script.sh @@ -6,7 +6,12 @@ export LC_ALL=C.UTF-8 -set -ex +set -o errexit -o xtrace + +if [ "${DANGER_RUN_CI_ON_HOST}" != "1" ]; then + echo "This script will make unsafe local and global modifications, so it can only be run inside a container and requires DANGER_RUN_CI_ON_HOST=1" + exit 1 +fi cd "${BASE_ROOT_DIR}" @@ -44,6 +49,19 @@ echo "=== BEGIN env ===" env echo "=== END env ===" +# The CI framework should be flexible where it is run from. For example, from +# a git-archive, a git-worktree, or a normal git repo. +# The iwyu task requires a working git repo, which may not always be +# available, so initialize one with force. +if [[ "${RUN_IWYU}" == true ]]; then + mv .git .git_ci_backup || true + git init + git add ./src # the git diff command used later for iwyu only cares about ./src + git config user.email "ci@ci" + git config user.name "CI" + git commit -m "dummy CI ./src init for IWYU" +fi + if [ "$RUN_FUZZ_TESTS" = "true" ]; then export DIR_FUZZ_IN=${DIR_QA_ASSETS}/fuzz_corpora/ if [ ! -d "$DIR_FUZZ_IN" ]; then diff --git a/ci/test_imagefile b/ci/test_imagefile index 93494cc1bbe..908e9a0f5ab 100644 --- a/ci/test_imagefile +++ b/ci/test_imagefile @@ -21,4 +21,4 @@ COPY ./ci/test/00_setup_env.sh ./${FILE_ENV} ./ci/test/01_base_install.sh ./ci/t # Bash is required, so install it when missing RUN sh -c "bash -c 'true' || ( apk update && apk add --no-cache bash )" -RUN ["bash", "-c", "cd /ci_container_base/ && set -o errexit && source ./ci/test/00_setup_env.sh && ./ci/test/01_base_install.sh"] +RUN ["bash", "-c", "cd /ci_container_base/ && set -o errexit && source ./ci/test/00_setup_env.sh && DANGER_RUN_CI_ON_HOST=1 ./ci/test/01_base_install.sh"]