diff --git a/.kokoro/python3.7/periodic.cfg b/.kokoro/python3.7/periodic.cfg index f962097d226..dac39e8fe37 100644 --- a/.kokoro/python3.7/periodic.cfg +++ b/.kokoro/python3.7/periodic.cfg @@ -24,3 +24,10 @@ env_vars: { key: "REPORT_TO_BUILD_COP_BOT" value: "true" } + +# Run DRIFT test result injection +# (only for Python 3.7 builds) +env_vars: { + key: "INJECT_REGION_TAGS" + value: "true" +} diff --git a/.kokoro/tests/run_single_test.sh b/.kokoro/tests/run_single_test.sh index 94ce92762b0..c2f1963fd2b 100755 --- a/.kokoro/tests/run_single_test.sh +++ b/.kokoro/tests/run_single_test.sh @@ -41,6 +41,36 @@ fi nox -s "$RUN_TESTS_SESSION" EXIT=$? +echo "PWD: ${PWD}" + +# Inject region tag data into the test log +set +e # Don't fail the entire test if this step fails +if [[ "${INJECT_REGION_TAGS:-}" == "true" ]]; then + + export XUNIT_PATH="$PWD/sponge_log.xml" + export XUNIT_TMP_PATH="$(mktemp)" + + if [[ -f "$XUNIT_PATH" ]]; then + echo "=== Injecting region tags into XUnit output ===" + echo "Processing XUnit output file: $XUNIT_PATH (saving output to $XUNIT_TMP_PATH)" + + # We use `python3` because it will work even if we remove old + # python versions from the docker image. + echo "Calling python3 ${PARSER_PATH} inject-snippet-mapping --output_file ${XUNIT_TMP_PATH} ${PWD}" + cat "$XUNIT_PATH" | \ + python3 "$PARSER_PATH" inject-snippet-mapping --output_file "$XUNIT_TMP_PATH" "$PWD" + if [[ $? -eq 0 ]] && [[ -s "$XUNIT_PATH" ]]; then + mv $XUNIT_TMP_PATH $XUNIT_PATH + else + echo "Region tag injection FAILED; XUnit file not modified." + fi + else + echo "No XUnit output file found!" + fi + echo "=== Region tag injection complete! ===" +fi +set -e + # If REPORT_TO_BUILD_COP_BOT is set to "true", send the test log # to the Build Cop Bot. # See: diff --git a/.kokoro/tests/run_tests.sh b/.kokoro/tests/run_tests.sh index d05f32a1d9a..ecd9afb2d63 100755 --- a/.kokoro/tests/run_tests.sh +++ b/.kokoro/tests/run_tests.sh @@ -121,6 +121,27 @@ set +e RTN=0 ROOT=$(pwd) +# Setup DRIFT region tag injector +# (only run on *some* builds) +if [[ "${INJECT_REGION_TAGS:-}" == "true" ]]; then + echo "=== Setting up DRIFT region tag injector ===" + # install PyYaml (used by the DRIFT region tag parsing system) + echo "--- Installing PyYaml ---" + python3 -m pip install --user pyyaml + + # Use ${HOME} because trampoline will automatically clean up this + # directory. + export REGION_TAG_PARSER_DIR="${HOME}/region-tag-parser" + export PARSER_PATH="${REGION_TAG_PARSER_DIR}/wizard-py/cli.py" + + if [[ ! -f $PARSER_PATH ]]; then + echo "--- Fetching injection script from HEAD (via GitHub) ---" + git clone https://github.com/GoogleCloudPlatform/repo-automation-playground "$REGION_TAG_PARSER_DIR" --single-branch + chmod +x $PARSER_PATH + fi + echo "=== Region tag injector setup complete ===" +fi + test_prog="${PROJECT_ROOT}/.kokoro/tests/run_single_test.sh" btlr_args=( diff --git a/.trampolinerc b/.trampolinerc index b40411719b2..00d93d7f699 100644 --- a/.trampolinerc +++ b/.trampolinerc @@ -25,6 +25,7 @@ required_envvars+=( pass_down_envvars+=( "BUILD_SPECIFIC_GCLOUD_PROJECT" "REPORT_TO_BUILD_COP_BOT" + "INJECT_REGION_TAGS" # Target directories. "RUN_TESTS_DIRS" # The nox session to run.