Skip to content

Commit d1dfc72

Browse files
Ace NassriTakashi Matsuo
andauthored
feat: Add DRIFT region tag parser to CI (#4506)
* Add DRIFT region tag parser to CI * Fix missing bracket * Move pip install to run_tests.sh * Use uuid in temp file + python write instead of stdout * Use set e for error handling + check file existence * use `python3 -m pip install` * remove env vars from run_single_test.sh Co-authored-by: Takashi Matsuo <tmatsuo@google.com>
1 parent 1c90e8e commit d1dfc72

4 files changed

Lines changed: 59 additions & 0 deletions

File tree

.kokoro/python3.7/periodic.cfg

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,10 @@ env_vars: {
2424
key: "REPORT_TO_BUILD_COP_BOT"
2525
value: "true"
2626
}
27+
28+
# Run DRIFT test result injection
29+
# (only for Python 3.7 builds)
30+
env_vars: {
31+
key: "INJECT_REGION_TAGS"
32+
value: "true"
33+
}

.kokoro/tests/run_single_test.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,36 @@ fi
4141
nox -s "$RUN_TESTS_SESSION"
4242
EXIT=$?
4343

44+
echo "PWD: ${PWD}"
45+
46+
# Inject region tag data into the test log
47+
set +e # Don't fail the entire test if this step fails
48+
if [[ "${INJECT_REGION_TAGS:-}" == "true" ]]; then
49+
50+
export XUNIT_PATH="$PWD/sponge_log.xml"
51+
export XUNIT_TMP_PATH="$(mktemp)"
52+
53+
if [[ -f "$XUNIT_PATH" ]]; then
54+
echo "=== Injecting region tags into XUnit output ==="
55+
echo "Processing XUnit output file: $XUNIT_PATH (saving output to $XUNIT_TMP_PATH)"
56+
57+
# We use `python3` because it will work even if we remove old
58+
# python versions from the docker image.
59+
echo "Calling python3 ${PARSER_PATH} inject-snippet-mapping --output_file ${XUNIT_TMP_PATH} ${PWD}"
60+
cat "$XUNIT_PATH" | \
61+
python3 "$PARSER_PATH" inject-snippet-mapping --output_file "$XUNIT_TMP_PATH" "$PWD"
62+
if [[ $? -eq 0 ]] && [[ -s "$XUNIT_PATH" ]]; then
63+
mv $XUNIT_TMP_PATH $XUNIT_PATH
64+
else
65+
echo "Region tag injection FAILED; XUnit file not modified."
66+
fi
67+
else
68+
echo "No XUnit output file found!"
69+
fi
70+
echo "=== Region tag injection complete! ==="
71+
fi
72+
set -e
73+
4474
# If REPORT_TO_BUILD_COP_BOT is set to "true", send the test log
4575
# to the Build Cop Bot.
4676
# See:

.kokoro/tests/run_tests.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,27 @@ set +e
121121
RTN=0
122122
ROOT=$(pwd)
123123

124+
# Setup DRIFT region tag injector
125+
# (only run on *some* builds)
126+
if [[ "${INJECT_REGION_TAGS:-}" == "true" ]]; then
127+
echo "=== Setting up DRIFT region tag injector ==="
128+
# install PyYaml (used by the DRIFT region tag parsing system)
129+
echo "--- Installing PyYaml ---"
130+
python3 -m pip install --user pyyaml
131+
132+
# Use ${HOME} because trampoline will automatically clean up this
133+
# directory.
134+
export REGION_TAG_PARSER_DIR="${HOME}/region-tag-parser"
135+
export PARSER_PATH="${REGION_TAG_PARSER_DIR}/wizard-py/cli.py"
136+
137+
if [[ ! -f $PARSER_PATH ]]; then
138+
echo "--- Fetching injection script from HEAD (via GitHub) ---"
139+
git clone https://github.com/GoogleCloudPlatform/repo-automation-playground "$REGION_TAG_PARSER_DIR" --single-branch
140+
chmod +x $PARSER_PATH
141+
fi
142+
echo "=== Region tag injector setup complete ==="
143+
fi
144+
124145
test_prog="${PROJECT_ROOT}/.kokoro/tests/run_single_test.sh"
125146

126147
btlr_args=(

.trampolinerc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ required_envvars+=(
2525
pass_down_envvars+=(
2626
"BUILD_SPECIFIC_GCLOUD_PROJECT"
2727
"REPORT_TO_BUILD_COP_BOT"
28+
"INJECT_REGION_TAGS"
2829
# Target directories.
2930
"RUN_TESTS_DIRS"
3031
# The nox session to run.

0 commit comments

Comments
 (0)