Skip to content

Commit a4d20bf

Browse files
fredrectensorflower-gardener
authored andcommitted
Gather test logs as CI artifacts
PiperOrigin-RevId: 415940853
1 parent 3d52466 commit a4d20bf

File tree

2 files changed

+67
-14
lines changed

2 files changed

+67
-14
lines changed

ci/kokoro/gcp_ubuntu/build.sh

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
# be used to reproduce errors locally by modifying WORKDIR to be
1919
# the top-level directory of the checked out TFMOT Github repository.
2020

21-
# TODO(b/185727163): switch to prebuilt Docker image to speed this up.
22-
2321
# Make Bash more strict, for easier debugging.
2422
set -e # Exit on the first error.
2523
set -u # Treat unset variables as error.
@@ -34,22 +32,53 @@ set -o pipefail # Treat the failure of a command in a pipeline as error.
3432
# parameters, will print the full command, with credentials, in the build logs.
3533
# set -x
3634

37-
# Code under repo is checked out to
38-
# ${KOKORO_ARTIFACTS_DIR}/github/tensorflow_model_optimization.
39-
WORKDIR="${KOKORO_ARTIFACTS_DIR}/github/tensorflow_model_optimization"
35+
# The TFMOT Git repository is checked out here.
36+
GIT_REPO_DIR="${KOKORO_ARTIFACTS_DIR}/github/tensorflow_model_optimization"
37+
38+
39+
cleanup() {
40+
# Collect the test logs.
41+
docker exec tfmot find \
42+
-L "bazel-testlogs" \
43+
\( -name "test.log" -o -name "test.xml" \) \
44+
-exec cp --parents {} "${KOKORO_ARTIFACTS_DIR}" \;
45+
46+
# Rename test.xml to sponge_log.xml so they show up in Sponge.
47+
docker exec tfmot find "${KOKORO_ARTIFACTS_DIR}/bazel-testlogs" \
48+
-type f \
49+
-name test.xml \
50+
-execdir mv "{}" sponge_log.xml \;
4051

52+
# Rename test.log to sponge_log.log so they show up in Sponge.
53+
docker exec tfmot find "${KOKORO_ARTIFACTS_DIR}/bazel-testlogs" \
54+
-type f \
55+
-name test.log \
56+
-execdir mv "{}" sponge_log.log \;
57+
58+
# Stop the container
59+
docker stop tfmot
60+
}
61+
62+
# Build the Docker image.
63+
# TODO(b/185727163): switch to prebuilt Docker image to speed this up.
4164
docker build --tag tfmot \
42-
$WORKDIR/ci/kokoro/gcp_ubuntu
65+
"${GIT_REPO_DIR}/ci/kokoro/gcp_ubuntu"
4366

44-
# Mount the checked out repository, make that the working directory and run
45-
# ci/kokoro/build.sh from the repository, which runs all the unit tests.
67+
# Start a Docker container in the background.
68+
# The Kokoro artitifacts directory is mounted and the work directory
69+
# conveniently set to the TFMOT Git repository.
4670
docker run \
47-
--volume "${WORKDIR?}:${WORKDIR?}" \
48-
--workdir="${WORKDIR?}" \
71+
-it \
72+
-d \
4973
--rm \
74+
--name tfmot \
75+
--volume "${KOKORO_ARTIFACTS_DIR}:${KOKORO_ARTIFACTS_DIR}" \
76+
--workdir="${GIT_REPO_DIR}" \
5077
tfmot:latest \
51-
ci/kokoro/build.sh
78+
bash
79+
80+
# On exit: collect the test logs and stop the container.
81+
trap cleanup EXIT
5282

53-
# Kokoro will rsync this entire directory back to the executor orchestrating the
54-
# build which takes forever and is totally useless.
55-
sudo rm -rf "${KOKORO_ARTIFACTS_DIR?}"/*
83+
# Run the tests inside the container,
84+
docker exec tfmot "${GIT_REPO_DIR}/ci/kokoro/build.sh"

ci/kokoro/gcp_ubuntu/common.cfg

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Format: //devtools/kokoro/config/proto/build.proto
2+
3+
# Copyright 2021 Google LLC
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
build_file: "tensorflow_model_optimization/ci/kokoro/gcp_ubuntu/build.sh"
18+
19+
action {
20+
define_artifacts {
21+
regex: "**/*sponge_log.xml"
22+
regex: "**/*sponge_log.log"
23+
}
24+
}

0 commit comments

Comments
 (0)