diff --git a/tools/internal_ci/helper_scripts/delete_nonartifacts.sh b/tools/internal_ci/helper_scripts/delete_nonartifacts.sh deleted file mode 100755 index 01e9427e1c7..00000000000 --- a/tools/internal_ci/helper_scripts/delete_nonartifacts.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2018 The gRPC Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -set -ex - -# change to grpc repo root -cd "$(dirname "$0")/../../.." - -# After kokoro build finishes, the workspace gets rsync'ed to another machine, -# from where the artifacts and reports are processed. -# Especially on Windows, the rsync can take long time, so we cleanup the workspace -# after finishing each build. We only leave files we want to keep: -# - reports and artifacts -# - directory containing the kokoro scripts to prevent deleting a script while being executed. -time find . -type f -not -iname "*sponge_log.*" -not -path "./reports/*" -not -path "./artifacts/*" -not -path "./tools/internal_ci/*" -exec rm -f {} + diff --git a/tools/internal_ci/helper_scripts/move_src_tree_and_respawn_itself.bat b/tools/internal_ci/helper_scripts/move_src_tree_and_respawn_itself.bat new file mode 100644 index 00000000000..cdceeeee44d --- /dev/null +++ b/tools/internal_ci/helper_scripts/move_src_tree_and_respawn_itself.bat @@ -0,0 +1,58 @@ +@rem Copyright 2021 The gRPC Authors +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem http://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. + +@rem Call this script at the beginning of your CI script to move +@rem the entire source tree to a different directory. +@rem That avoids slow finalization (and a number of other problems) +@rem caused by kokoro rsyncing the entire /tmpfs/src directory +@rem back to the agent. +@rem Since batch scripts don't support the "source" unix command, +@rem invoking this script is a bit trickier than on unix. +@rem This script should be invoked from the CI script like this: +@rem IF "%cd%"=="T:\src" ( +@rem call %~dp0\..\..\..\tools\internal_ci\helper_scripts\move_src_tree_and_respawn_itself.bat %0 +@rem exit /b %errorlevel% +@rem ) + +@echo off + +@rem CI script path needs to be passed as arg1. +set CI_SCRIPT_RELATIVE_TO_SRC=%1 + +@rem Check that this script was invoked under correct circumstances. +IF NOT "%cd%"=="T:\src" ( + @echo "Error: Current directory must be T:\src when invoking move_src_tree_and_respawn_itself.bat" + exit /b 1 +) + +@rem T:\ is equivalent to /tmpfs on kokoro linux. +echo "Moving workspace from T:\src to T:\altsrc and respawning the CI script." +cd /d T:\ +@rem We cannot simply rename "src" to "altsrc" as on linux since the currently running batch file is in it +@rem and windows holds a lock that prevents moving the dir. +bash -c "set -ex; mkdir -p altsrc; time cp -r src/github altsrc;" +@rem Delete files we can under the original "src/github" directory, skipping the directory that contains CI scripts +@rem (as on of the scripts is currently running and cannot be deleted) +@rem We don't want to delete files in "src" outside of "src/github" since they contain e.g kokoro input artifacts. +bash -c "set -ex; cd src/github; time find . -type f -not -path './grpc/tools/internal_ci/*' -exec rm -f {} +; ls grpc" +cd altsrc + +@rem scripts in tools/run_tests generate test reports and we need to make sure these reports +@rem land in a directory that is going to be rsynced back to the kokoro agent. +set GRPC_TEST_REPORT_BASE_DIR=T:\src\github\grpc + +echo "Invoking original CI script now." +@echo on +call "%CI_SCRIPT_RELATIVE_TO_SRC%" +exit /b %errorlevel% diff --git a/tools/internal_ci/helper_scripts/move_src_tree_and_respawn_itself_rc b/tools/internal_ci/helper_scripts/move_src_tree_and_respawn_itself_rc new file mode 100644 index 00000000000..ad915d68e24 --- /dev/null +++ b/tools/internal_ci/helper_scripts/move_src_tree_and_respawn_itself_rc @@ -0,0 +1,52 @@ +#!/bin/bash +# Copyright 2021 The gRPC Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Source this rc script at the beginning of your CI script to move +# the entire source tree to a different directory. +# That avoids slow finalization (and a number of other problems) +# caused by kokoro rsyncing the entire /tmpfs/src directory +# back to the agent. +# See b/74837748 for more context. + +set -ex + +CURRENT_DIR="$(pwd)" +CI_SCRIPT_RELATIVE_TO_SRC="$0" + +if [ "${CURRENT_DIR}" == "/tmpfs/altsrc" ] +then + # we already respawned under /tmpfs/altsrc, no need to do anything + echo "Successfully respawned the CI script ${CI_SCRIPT_RELATIVE_TO_SRC} under ${CURRENT_DIR}." + # scripts in tools/run_tests generate test reports and we need to make sure these reports + # land in a directory that is going to be rsynced back to the kokoro agent. + export GRPC_TEST_REPORT_BASE_DIR="/tmpfs/src/github/grpc" +elif [ "${CURRENT_DIR}" == "/tmpfs/src" ] +then + # we need to respawn now + # - step out of current directory + # - rename src/github to altsrc/github (/tmpfs/src is the directory that gets rsynced back to kokoro agent once the CI script finishes). + # Note that we don't want to move the entire /tmpfs/src tree (which contains e.g. the input artifacts as well, + # and their path is referenced by kokoro env variables), just /tmpfs/src/github + # which contains all the cloned github repositories (=our workspace in which the build happens) + echo "Moving workspace from /tmpfs/src to /tmpfs/altsrc and respawning the CI script." + # once "exec bash" starts, the CI script in the original location will no longer be in use and it will be safe to move + # the entire "/tmpfs/src/github" tree (moving the bash script file while running is probably safe anyway on unix, but it doesn't + # hurt to be extra careful) + exec bash -c "set -ex; cd /tmpfs; mkdir -p altsrc; mv src/github altsrc; cd altsrc; exec '${CI_SCRIPT_RELATIVE_TO_SRC}'" +else + # avoid messing with the workspace if we don't see the directory layout + # that's standard on kokoro (in case this script gets accidentally invoked outside of kokoro) + echo "Looks the script is currently not running on kokoro, skipping respawn and continuing the original CI script." +fi diff --git a/tools/internal_ci/helper_scripts/store_artifacts_from_moved_src_tree.sh b/tools/internal_ci/helper_scripts/store_artifacts_from_moved_src_tree.sh new file mode 100755 index 00000000000..858e3cbc6c5 --- /dev/null +++ b/tools/internal_ci/helper_scripts/store_artifacts_from_moved_src_tree.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env bash +# Copyright 2021 The gRPC Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# If you have used "move_src_tree_and_respawn_itself_rc" in a CI script +# and the script produces artifacts to be stored by kokoro, run this +# at the end of the script. + +set -ex + +if [ "${GRPC_TEST_REPORT_BASE_DIR}" == "" ] +then + # looks like the move_src_tree_and_respawn_itself_rc hasn't been used + # and we're not running under a moved source tree + exit 0 +fi + +# change to grpc repo root +cd "$(dirname "$0")/../../.." + +# If running under a moved source tree (see grpc/tools/internal_ci/helper_scripts/move_src_tree_and_respawn_itself_rc), +# we need to copy the artifacts produced by the build to a location that's stored by kokoro. + +# artifacts in this directory will be stored by kokoro +mkdir -p "${GRPC_TEST_REPORT_BASE_DIR}/artifacts" +time cp -r artifacts/* "${GRPC_TEST_REPORT_BASE_DIR}/artifacts" || true diff --git a/tools/internal_ci/linux/grpc_bazel_distribtest.cfg b/tools/internal_ci/linux/grpc_bazel_distribtest.cfg index 00b398ddf5f..84a2ab35017 100644 --- a/tools/internal_ci/linux/grpc_bazel_distribtest.cfg +++ b/tools/internal_ci/linux/grpc_bazel_distribtest.cfg @@ -21,6 +21,5 @@ action { define_artifacts { regex: "**/*sponge_log.*" regex: "github/grpc/reports/**" - regex: "github/grpc/artifacts/**" } } diff --git a/tools/internal_ci/linux/grpc_bazel_distribtest_latest.cfg b/tools/internal_ci/linux/grpc_bazel_distribtest_latest.cfg index f0fe33c9459..04b51a8f7c6 100644 --- a/tools/internal_ci/linux/grpc_bazel_distribtest_latest.cfg +++ b/tools/internal_ci/linux/grpc_bazel_distribtest_latest.cfg @@ -21,6 +21,5 @@ action { define_artifacts { regex: "**/*sponge_log.*" regex: "github/grpc/reports/**" - regex: "github/grpc/artifacts/**" } } diff --git a/tools/internal_ci/linux/grpc_build_artifacts.sh b/tools/internal_ci/linux/grpc_build_artifacts.sh index 9cf6b2428de..0810790c37b 100755 --- a/tools/internal_ci/linux/grpc_build_artifacts.sh +++ b/tools/internal_ci/linux/grpc_build_artifacts.sh @@ -15,6 +15,9 @@ set -ex +# avoid slow finalization after the script has exited. +source $(dirname $0)/../../../tools/internal_ci/helper_scripts/move_src_tree_and_respawn_itself_rc + # change to grpc repo root cd $(dirname $0)/../../.. @@ -26,4 +29,11 @@ set -e # rvm commands are very verbose rvm --default use ruby-2.4.1 set -ex -tools/run_tests/task_runner.py -f artifact linux -j 12 +tools/run_tests/task_runner.py -f artifact linux -j 12 || FAILED="true" + +tools/internal_ci/helper_scripts/store_artifacts_from_moved_src_tree.sh + +if [ "$FAILED" != "" ] +then + exit 1 +fi diff --git a/tools/internal_ci/linux/grpc_build_packages.sh b/tools/internal_ci/linux/grpc_build_packages.sh index ff71298add4..f9b8953ecf0 100644 --- a/tools/internal_ci/linux/grpc_build_packages.sh +++ b/tools/internal_ci/linux/grpc_build_packages.sh @@ -15,6 +15,9 @@ set -ex +# avoid slow finalization after the script has exited. +source $(dirname $0)/../../../tools/internal_ci/helper_scripts/move_src_tree_and_respawn_itself_rc + # change to grpc repo root cd $(dirname $0)/../../.. @@ -33,4 +36,12 @@ mv ${KOKORO_GFILE_DIR}/github/grpc/artifacts input_artifacts || true chmod +x input_artifacts/protoc*/* || true ls -R input_artifacts || true -tools/run_tests/task_runner.py -f package linux -j 6 +tools/run_tests/task_runner.py -f package linux -j 6 || FAILED="true" + +tools/internal_ci/helper_scripts/store_artifacts_from_moved_src_tree.sh + +if [ "$FAILED" != "" ] +then + exit 1 +fi + diff --git a/tools/internal_ci/linux/grpc_distribtests.sh b/tools/internal_ci/linux/grpc_distribtests.sh index 8a8111d557a..c809f22ee76 100644 --- a/tools/internal_ci/linux/grpc_distribtests.sh +++ b/tools/internal_ci/linux/grpc_distribtests.sh @@ -15,6 +15,9 @@ set -ex +# avoid slow finalization after the script has exited. +source $(dirname $0)/../../../tools/internal_ci/helper_scripts/move_src_tree_and_respawn_itself_rc + # change to grpc repo root cd $(dirname $0)/../../.. diff --git a/tools/internal_ci/linux/grpc_distribtests_php.sh b/tools/internal_ci/linux/grpc_distribtests_php.sh index a0de6701d43..aad8d65b9bb 100755 --- a/tools/internal_ci/linux/grpc_distribtests_php.sh +++ b/tools/internal_ci/linux/grpc_distribtests_php.sh @@ -15,6 +15,9 @@ set -ex +# avoid slow finalization after the script has exited. +source $(dirname $0)/../../../tools/internal_ci/helper_scripts/move_src_tree_and_respawn_itself_rc + # change to grpc repo root cd $(dirname $0)/../../.. @@ -45,6 +48,8 @@ cp -r artifacts/* input_artifacts/ || true # a better signal about which distribtest are affected by the currently broken artifact builds. tools/run_tests/task_runner.py -f distribtest linux php -j 4 -x distribtests/sponge_log.xml || FAILED="true" +tools/internal_ci/helper_scripts/store_artifacts_from_moved_src_tree.sh + if [ "$FAILED" != "" ] then exit 1 diff --git a/tools/internal_ci/linux/grpc_distribtests_python.sh b/tools/internal_ci/linux/grpc_distribtests_python.sh index 37f026d9674..a03309231d5 100755 --- a/tools/internal_ci/linux/grpc_distribtests_python.sh +++ b/tools/internal_ci/linux/grpc_distribtests_python.sh @@ -15,6 +15,9 @@ set -ex +# avoid slow finalization after the script has exited. +source $(dirname $0)/../../../tools/internal_ci/helper_scripts/move_src_tree_and_respawn_itself_rc + # change to grpc repo root cd $(dirname $0)/../../.. @@ -50,6 +53,8 @@ cp -r artifacts/* input_artifacts/ || true # a better signal about which distribtest are affected by the currently broken artifact builds. tools/run_tests/task_runner.py -f distribtest linux python -j 12 -x distribtests/sponge_log.xml || FAILED="true" +tools/internal_ci/helper_scripts/store_artifacts_from_moved_src_tree.sh + if [ "$FAILED" != "" ] then exit 1 diff --git a/tools/internal_ci/linux/grpc_distribtests_ruby.sh b/tools/internal_ci/linux/grpc_distribtests_ruby.sh index bb794e7f3b2..3da15534b8a 100755 --- a/tools/internal_ci/linux/grpc_distribtests_ruby.sh +++ b/tools/internal_ci/linux/grpc_distribtests_ruby.sh @@ -15,6 +15,9 @@ set -ex +# avoid slow finalization after the script has exited. +source $(dirname $0)/../../../tools/internal_ci/helper_scripts/move_src_tree_and_respawn_itself_rc + # change to grpc repo root cd $(dirname $0)/../../.. @@ -46,6 +49,8 @@ cp -r artifacts/ruby_native_gem_*/* input_artifacts/ || true # a better signal about which distribtest are affected by the currently broken artifact builds. tools/run_tests/task_runner.py -f distribtest linux ruby -j 6 -x distribtests/sponge_log.xml || FAILED="true" +tools/internal_ci/helper_scripts/store_artifacts_from_moved_src_tree.sh + if [ "$FAILED" != "" ] then exit 1 diff --git a/tools/internal_ci/linux/grpc_distribtests_standalone.sh b/tools/internal_ci/linux/grpc_distribtests_standalone.sh index 084daa9bc6a..f71f3b13773 100755 --- a/tools/internal_ci/linux/grpc_distribtests_standalone.sh +++ b/tools/internal_ci/linux/grpc_distribtests_standalone.sh @@ -15,6 +15,9 @@ set -ex +# avoid slow finalization after the script has exited. +source $(dirname $0)/../../../tools/internal_ci/helper_scripts/move_src_tree_and_respawn_itself_rc + # change to grpc repo root cd $(dirname $0)/../../.. diff --git a/tools/internal_ci/linux/grpc_run_interop_tests.sh b/tools/internal_ci/linux/grpc_run_interop_tests.sh index 1f4eda2d529..8b02bd05cff 100755 --- a/tools/internal_ci/linux/grpc_run_interop_tests.sh +++ b/tools/internal_ci/linux/grpc_run_interop_tests.sh @@ -15,6 +15,9 @@ set -ex +# avoid slow finalization after the script has exited. +source $(dirname $0)/../../../tools/internal_ci/helper_scripts/move_src_tree_and_respawn_itself_rc + export LANG=en_US.UTF-8 # Enter the gRPC repo root diff --git a/tools/internal_ci/linux/grpc_run_tests_matrix.sh b/tools/internal_ci/linux/grpc_run_tests_matrix.sh index 7c5b07a78c1..8f5d4f2f527 100755 --- a/tools/internal_ci/linux/grpc_run_tests_matrix.sh +++ b/tools/internal_ci/linux/grpc_run_tests_matrix.sh @@ -15,6 +15,9 @@ set -ex +# avoid slow finalization after the script has exited. +source $(dirname $0)/../../../tools/internal_ci/helper_scripts/move_src_tree_and_respawn_itself_rc + # change to grpc repo root cd $(dirname $0)/../../.. diff --git a/tools/internal_ci/macos/grpc_build_artifacts.sh b/tools/internal_ci/macos/grpc_build_artifacts.sh index 02b2331f5f1..2e4522a6f91 100755 --- a/tools/internal_ci/macos/grpc_build_artifacts.sh +++ b/tools/internal_ci/macos/grpc_build_artifacts.sh @@ -15,6 +15,9 @@ set -ex +# avoid slow finalization after the script has exited. +source $(dirname $0)/../../../tools/internal_ci/helper_scripts/move_src_tree_and_respawn_itself_rc + # change to grpc repo root cd $(dirname $0)/../../.. @@ -40,7 +43,7 @@ update_rubygems tools/run_tests/task_runner.py -f artifact macos || FAILED="true" -tools/internal_ci/helper_scripts/delete_nonartifacts.sh || true +tools/internal_ci/helper_scripts/store_artifacts_from_moved_src_tree.sh if [ "$FAILED" != "" ] then diff --git a/tools/internal_ci/macos/grpc_distribtests.sh b/tools/internal_ci/macos/grpc_distribtests.sh index cf2ba090176..919121b6591 100644 --- a/tools/internal_ci/macos/grpc_distribtests.sh +++ b/tools/internal_ci/macos/grpc_distribtests.sh @@ -15,6 +15,9 @@ set -ex +# avoid slow finalization after the script has exited. +source $(dirname $0)/../../../tools/internal_ci/helper_scripts/move_src_tree_and_respawn_itself_rc + # change to grpc repo root cd $(dirname $0)/../../.. @@ -26,11 +29,4 @@ source tools/internal_ci/helper_scripts/prepare_build_macos_rc mv ${KOKORO_GFILE_DIR}/github/grpc/artifacts input_artifacts || true ls -R input_artifacts || true -tools/run_tests/task_runner.py -f distribtest macos || FAILED="true" - -tools/internal_ci/helper_scripts/delete_nonartifacts.sh || true - -if [ "$FAILED" != "" ] -then - exit 1 -fi +tools/run_tests/task_runner.py -f distribtest macos diff --git a/tools/internal_ci/macos/grpc_distribtests_php.sh b/tools/internal_ci/macos/grpc_distribtests_php.sh index a6c33285d79..5bd716c32fc 100644 --- a/tools/internal_ci/macos/grpc_distribtests_php.sh +++ b/tools/internal_ci/macos/grpc_distribtests_php.sh @@ -15,6 +15,9 @@ set -ex +# avoid slow finalization after the script has exited. +source $(dirname $0)/../../../tools/internal_ci/helper_scripts/move_src_tree_and_respawn_itself_rc + # change to grpc repo root cd $(dirname $0)/../../.. @@ -39,7 +42,7 @@ cp -r artifacts/php_pecl_package_macos_*/* input_artifacts/ || true # a better signal about which distribtest are affected by the currently broken artifact builds. tools/run_tests/task_runner.py -f distribtest macos php -j 4 -x distribtests/sponge_log.xml || FAILED="true" -tools/internal_ci/helper_scripts/delete_nonartifacts.sh || true +tools/internal_ci/helper_scripts/store_artifacts_from_moved_src_tree.sh if [ "$FAILED" != "" ] then diff --git a/tools/internal_ci/macos/grpc_interop_toprod.sh b/tools/internal_ci/macos/grpc_interop_toprod.sh index c4d300d4a9b..962a37d8eb5 100755 --- a/tools/internal_ci/macos/grpc_interop_toprod.sh +++ b/tools/internal_ci/macos/grpc_interop_toprod.sh @@ -15,6 +15,9 @@ set -ex +# avoid slow finalization after the script has exited. +source $(dirname $0)/../../../tools/internal_ci/helper_scripts/move_src_tree_and_respawn_itself_rc + # change to grpc repo root cd $(dirname $0)/../../.. @@ -41,8 +44,6 @@ tools/run_tests/run_interop_tests.py -l c++ \ --default_service_account="interop-to-prod-tests@grpc-testing.iam.gserviceaccount.com" \ --skip_compute_engine_creds --internal_ci -t -j 4 || FAILED="true" -tools/internal_ci/helper_scripts/delete_nonartifacts.sh || true - if [ "$FAILED" != "" ] then exit 1 diff --git a/tools/internal_ci/macos/grpc_ios_binary_size.sh b/tools/internal_ci/macos/grpc_ios_binary_size.sh index 523e3ae8b7d..66b098dfa2a 100755 --- a/tools/internal_ci/macos/grpc_ios_binary_size.sh +++ b/tools/internal_ci/macos/grpc_ios_binary_size.sh @@ -16,6 +16,9 @@ # This script is invoked by Jenkins and runs a diff on the microbenchmarks set -ex +# avoid slow finalization after the script has exited. +source $(dirname $0)/../../../tools/internal_ci/helper_scripts/move_src_tree_and_respawn_itself_rc + # List of benchmarks that provide good signal for analyzing performance changes in pull requests # Enter the gRPC repo root diff --git a/tools/internal_ci/macos/grpc_run_bazel_c_cpp_tests.sh b/tools/internal_ci/macos/grpc_run_bazel_c_cpp_tests.sh index 194f273f675..01f34e0e3ff 100644 --- a/tools/internal_ci/macos/grpc_run_bazel_c_cpp_tests.sh +++ b/tools/internal_ci/macos/grpc_run_bazel_c_cpp_tests.sh @@ -15,6 +15,9 @@ set -ex +# avoid slow finalization after the script has exited. +source $(dirname $0)/../../../tools/internal_ci/helper_scripts/move_src_tree_and_respawn_itself_rc + # change to grpc repo root cd $(dirname $0)/../../.. diff --git a/tools/internal_ci/macos/grpc_run_bazel_core_ios_tests.sh b/tools/internal_ci/macos/grpc_run_bazel_core_ios_tests.sh index fa33aa45079..68e96d7af08 100644 --- a/tools/internal_ci/macos/grpc_run_bazel_core_ios_tests.sh +++ b/tools/internal_ci/macos/grpc_run_bazel_core_ios_tests.sh @@ -15,6 +15,9 @@ set -ex +# avoid slow finalization after the script has exited. +source $(dirname $0)/../../../tools/internal_ci/helper_scripts/move_src_tree_and_respawn_itself_rc + # change to grpc repo root cd $(dirname $0)/../../.. diff --git a/tools/internal_ci/macos/grpc_run_bazel_cpp_ios_tests.sh b/tools/internal_ci/macos/grpc_run_bazel_cpp_ios_tests.sh index c6523408040..0acd139bcef 100644 --- a/tools/internal_ci/macos/grpc_run_bazel_cpp_ios_tests.sh +++ b/tools/internal_ci/macos/grpc_run_bazel_cpp_ios_tests.sh @@ -15,6 +15,9 @@ set -ex +# avoid slow finalization after the script has exited. +source $(dirname $0)/../../../tools/internal_ci/helper_scripts/move_src_tree_and_respawn_itself_rc + # change to grpc repo root cd $(dirname $0)/../../.. diff --git a/tools/internal_ci/macos/grpc_run_bazel_isolated_tests.sh b/tools/internal_ci/macos/grpc_run_bazel_isolated_tests.sh index e213105d61d..c137d382911 100644 --- a/tools/internal_ci/macos/grpc_run_bazel_isolated_tests.sh +++ b/tools/internal_ci/macos/grpc_run_bazel_isolated_tests.sh @@ -15,6 +15,9 @@ set -ex +# avoid slow finalization after the script has exited. +source $(dirname $0)/../../../tools/internal_ci/helper_scripts/move_src_tree_and_respawn_itself_rc + # change to grpc repo root cd $(dirname $0)/../../.. diff --git a/tools/internal_ci/macos/grpc_run_tests_matrix.sh b/tools/internal_ci/macos/grpc_run_tests_matrix.sh index b74508b7eb0..fcb27d3ee1f 100755 --- a/tools/internal_ci/macos/grpc_run_tests_matrix.sh +++ b/tools/internal_ci/macos/grpc_run_tests_matrix.sh @@ -15,6 +15,9 @@ set -ex +# avoid slow finalization after the script has exited. +source $(dirname $0)/../../../tools/internal_ci/helper_scripts/move_src_tree_and_respawn_itself_rc + # change to grpc repo root cd $(dirname $0)/../../.. @@ -25,8 +28,6 @@ tools/run_tests/run_tests_matrix.py $RUN_TESTS_FLAGS || FAILED="true" # kill port_server.py to prevent the build from freezing ps aux | grep port_server\\.py | awk '{print $2}' | xargs kill -9 -tools/internal_ci/helper_scripts/delete_nonartifacts.sh || true - if [ "$FAILED" != "" ] then exit 1 diff --git a/tools/internal_ci/windows/bazel_rbe.bat b/tools/internal_ci/windows/bazel_rbe.bat index 3fd021b3ef4..acf0076d872 100644 --- a/tools/internal_ci/windows/bazel_rbe.bat +++ b/tools/internal_ci/windows/bazel_rbe.bat @@ -12,6 +12,13 @@ @rem See the License for the specific language governing permissions and @rem limitations under the License. +@rem Avoid slow finalization after the script has exited. +@rem See the script's prologue for info on the correct invocation pattern. +IF "%cd%"=="T:\src" ( + call %~dp0\..\..\..\tools\internal_ci\helper_scripts\move_src_tree_and_respawn_itself.bat %0 + exit /b %errorlevel% +) + @rem TODO(jtattermusch): make this generate less output @rem TODO(jtattermusch): use tools/bazel script to keep the versions in sync choco install bazel -y --version 4.2.1 --limit-output diff --git a/tools/internal_ci/windows/grpc_build_artifacts.bat b/tools/internal_ci/windows/grpc_build_artifacts.bat index b8901e384cf..72813bd4b59 100644 --- a/tools/internal_ci/windows/grpc_build_artifacts.bat +++ b/tools/internal_ci/windows/grpc_build_artifacts.bat @@ -12,6 +12,13 @@ @rem See the License for the specific language governing permissions and @rem limitations under the License. +@rem Avoid slow finalization after the script has exited. +@rem See the script's prologue for info on the correct invocation pattern. +IF "%cd%"=="T:\src" ( + call %~dp0\..\..\..\tools\internal_ci\helper_scripts\move_src_tree_and_respawn_itself.bat %0 + exit /b %errorlevel% +) + @rem Boringssl build no longer supports yasm choco uninstall yasm -y --limit-output choco install nasm -y --limit-output @@ -25,6 +32,6 @@ call tools/internal_ci/helper_scripts/prepare_build_windows.bat || exit /b 1 python tools/run_tests/task_runner.py -f artifact windows -j 4 set RUNTESTS_EXITCODE=%errorlevel% -bash tools/internal_ci/helper_scripts/delete_nonartifacts.sh +bash tools/internal_ci/helper_scripts/store_artifacts_from_moved_src_tree.sh exit /b %RUNTESTS_EXITCODE% diff --git a/tools/internal_ci/windows/grpc_build_packages.bat b/tools/internal_ci/windows/grpc_build_packages.bat index 8f1e5794e29..42d2346f77d 100644 --- a/tools/internal_ci/windows/grpc_build_packages.bat +++ b/tools/internal_ci/windows/grpc_build_packages.bat @@ -12,6 +12,13 @@ @rem See the License for the specific language governing permissions and @rem limitations under the License. +@rem Avoid slow finalization after the script has exited. +@rem See the script's prologue for info on the correct invocation pattern. +IF "%cd%"=="T:\src" ( + call %~dp0\..\..\..\tools\internal_ci\helper_scripts\move_src_tree_and_respawn_itself.bat %0 + exit /b %errorlevel% +) + @rem enter repo root cd /d %~dp0\..\..\.. @@ -24,6 +31,4 @@ rem The only build_packages task that ever needed to run on windows was C#, but rem building C# nugets on linux (as dotnet SDK on linux does a good job) rem TODO(jtattermusch): remove the infrastructure for running "build_packages" kokoro job on windows. -bash tools/internal_ci/helper_scripts/delete_nonartifacts.sh - exit /b %RUNTESTS_EXITCODE% diff --git a/tools/internal_ci/windows/grpc_distribtests.bat b/tools/internal_ci/windows/grpc_distribtests.bat index 6b74972f359..5d1051860b2 100644 --- a/tools/internal_ci/windows/grpc_distribtests.bat +++ b/tools/internal_ci/windows/grpc_distribtests.bat @@ -12,6 +12,13 @@ @rem See the License for the specific language governing permissions and @rem limitations under the License. +@rem Avoid slow finalization after the script has exited. +@rem See the script's prologue for info on the correct invocation pattern. +IF "%cd%"=="T:\src" ( + call %~dp0\..\..\..\tools\internal_ci\helper_scripts\move_src_tree_and_respawn_itself.bat %0 + exit /b %errorlevel% +) + @rem enter repo root cd /d %~dp0\..\..\.. @@ -24,6 +31,4 @@ dir input_artifacts python tools/run_tests/task_runner.py -f distribtest windows -j 4 set RUNTESTS_EXITCODE=%errorlevel% -bash tools/internal_ci/helper_scripts/delete_nonartifacts.sh - exit /b %RUNTESTS_EXITCODE% diff --git a/tools/internal_ci/windows/grpc_distribtests_standalone.bat b/tools/internal_ci/windows/grpc_distribtests_standalone.bat index e0722dbf375..1d0635723f3 100644 --- a/tools/internal_ci/windows/grpc_distribtests_standalone.bat +++ b/tools/internal_ci/windows/grpc_distribtests_standalone.bat @@ -12,6 +12,13 @@ @rem See the License for the specific language governing permissions and @rem limitations under the License. +@rem Avoid slow finalization after the script has exited. +@rem See the script's prologue for info on the correct invocation pattern. +IF "%cd%"=="T:\src" ( + call %~dp0\..\..\..\tools\internal_ci\helper_scripts\move_src_tree_and_respawn_itself.bat %0 + exit /b %errorlevel% +) + @rem enter repo root cd /d %~dp0\..\..\.. @@ -20,6 +27,4 @@ call tools/internal_ci/helper_scripts/prepare_build_windows.bat || exit /b 1 python tools/run_tests/task_runner.py -f distribtest windows cpp -j 4 set RUNTESTS_EXITCODE=%errorlevel% -bash tools/internal_ci/helper_scripts/delete_nonartifacts.sh - exit /b %RUNTESTS_EXITCODE% diff --git a/tools/internal_ci/windows/grpc_run_tests_matrix.bat b/tools/internal_ci/windows/grpc_run_tests_matrix.bat index cd410a51ef3..c13386d88d5 100644 --- a/tools/internal_ci/windows/grpc_run_tests_matrix.bat +++ b/tools/internal_ci/windows/grpc_run_tests_matrix.bat @@ -12,6 +12,13 @@ @rem See the License for the specific language governing permissions and @rem limitations under the License. +@rem Avoid slow finalization after the script has exited. +@rem See the script's prologue for info on the correct invocation pattern. +IF "%cd%"=="T:\src" ( + call %~dp0\..\..\..\tools\internal_ci\helper_scripts\move_src_tree_and_respawn_itself.bat %0 + exit /b %errorlevel% +) + @rem enter repo root cd /d %~dp0\..\..\.. @@ -28,6 +35,4 @@ python3 tools/run_tests/start_port_server.py python3 tools/run_tests/run_tests_matrix.py %RUN_TESTS_FLAGS% set RUNTESTS_EXITCODE=%errorlevel% -bash tools/internal_ci/helper_scripts/delete_nonartifacts.sh - exit /b %RUNTESTS_EXITCODE% diff --git a/tools/run_tests/dockerize/build_docker_and_run_tests.sh b/tools/run_tests/dockerize/build_docker_and_run_tests.sh index 4a7908b0462..74626e54fb6 100755 --- a/tools/run_tests/dockerize/build_docker_and_run_tests.sh +++ b/tools/run_tests/dockerize/build_docker_and_run_tests.sh @@ -81,7 +81,13 @@ docker run \ # run_tests.py runs TEMP_REPORTS_ZIP=$(mktemp) docker cp "$CONTAINER_NAME:/var/local/git/grpc/reports.zip" "${TEMP_REPORTS_ZIP}" || true -unzip -o "${TEMP_REPORTS_ZIP}" -d "$git_root" || true +if [ "${GRPC_TEST_REPORT_BASE_DIR}" != "" ] +then + REPORTS_DEST_DIR="${GRPC_TEST_REPORT_BASE_DIR}" +else + REPORTS_DEST_DIR="${git_root}" +fi +unzip -o "${TEMP_REPORTS_ZIP}" -d "${REPORTS_DEST_DIR}" || true rm -f "${TEMP_REPORTS_ZIP}" # remove the container, possibly killing it first diff --git a/tools/run_tests/python_utils/report_utils.py b/tools/run_tests/python_utils/report_utils.py index ffc59e8d984..5cf7851b5f0 100644 --- a/tools/run_tests/python_utils/report_utils.py +++ b/tools/run_tests/python_utils/report_utils.py @@ -80,6 +80,10 @@ def render_junit_xml_report(resultset, def create_xml_report_file(tree, report_file): """Generate JUnit-like report file from xml tree .""" + # env variable can be used to override the base location for the reports + base_dir = os.getenv('GRPC_TEST_REPORT_BASE_DIR', None) + if base_dir: + report_file = os.path.join(base_dir, report_file) # ensure the report directory exists report_dir = os.path.dirname(os.path.abspath(report_file)) if not os.path.exists(report_dir): diff --git a/tools/run_tests/run_tests_matrix.py b/tools/run_tests/run_tests_matrix.py index 29adeb40520..664d313c13b 100755 --- a/tools/run_tests/run_tests_matrix.py +++ b/tools/run_tests/run_tests_matrix.py @@ -62,8 +62,14 @@ def _matrix_job_logfilename(shortname_for_multi_target): # for the corresponding 'sponge_log.xml' report. # the shortname_for_multi_target component must be set to match the sponge_log.xml location # because the top-level render_junit_xml_report is called with multi_target=True - return '%s/%s/%s' % (_MATRIX_REPORT_NAME, shortname_for_multi_target, - 'sponge_log.log') + sponge_log_name = '%s/%s/%s' % ( + _MATRIX_REPORT_NAME, shortname_for_multi_target, 'sponge_log.log') + # env variable can be used to override the base location for the reports + # so we need to match that behavior here too + base_dir = os.getenv('GRPC_TEST_REPORT_BASE_DIR', None) + if base_dir: + sponge_log_name = os.path.join(base_dir, sponge_log_name) + return sponge_log_name def _docker_jobspec(name, @@ -102,11 +108,15 @@ def _workspace_jobspec(name, shortname = 'run_tests_%s' % name env = {'WORKSPACE_NAME': workspace_name} env.update(runtests_envs) + # if report base dir is set, we don't need to ".." to come out of the workspace dir + report_dir_prefix = '' if os.getenv('GRPC_TEST_REPORT_BASE_DIR', + None) else '../' test_job = jobset.JobSpec(cmdline=[ 'bash', 'tools/run_tests/helper_scripts/run_tests_in_workspace.sh', '-t', '-j', str(inner_jobs), '-x', - '../run_tests/%s' % _report_filename(name), '--report_suite_name', + '%srun_tests/%s' % + (report_dir_prefix, _report_filename(name)), '--report_suite_name', '%s' % _safe_report_name(name) ] + runtests_args, environ=env,