test: start building all code
Code is built when testing it, but some type of build failures are
not properly translated by the junit converter we use. Adding this
extra build will catch this previously missed failures and should
affect test time minimally as builds will have been cached.
Fixes:
@@ -50,11 +50,11 @@ exit_code=0
# to be pushed to GCS as artifact.
runPresubmitTests() {
if [ -z ${RUN_INTEGRATION_TESTS} ]; then
- go test -race -v -timeout 15m -short ./... 2>&1 \
- | tee sponge_log.log
+ go test -race -v -timeout 15m -short ./... 2>&1 |
+ tee sponge_log.log
else
- go test -race -v -timeout 45m ./... 2>&1 \
- | tee sponge_log.log
+ go test -race -v -timeout 45m ./... 2>&1 |
+ tee sponge_log.log
fi
# Run integration tests against an emulator.
@@ -63,25 +63,32 @@ runPresubmitTests() {
fi
# Takes the kokoro output log (raw stdout) and creates a machine-parseable
# xUnit XML file.
- cat sponge_log.log \
- | go-junit-report -set-exit-code > sponge_log.xml
+ cat sponge_log.log |
+ go-junit-report -set-exit-code >sponge_log.xml
# Add the exit codes together so we exit non-zero if any module fails.
exit_code=$(($exit_code + $?))
+ # There are some types of build failures that go-junit-report does not
+ # properly handle. We can be safe here and run go build as well to catch such
+ # failures.
+ if [[ $PWD != *"/internal/"* ]]; then
+ go build ./...
+ fi
+ exit_code=$(($exit_code + $?))
}
-SIGNIFICANT_CHANGES=$(git --no-pager diff --name-only origin/main...$KOKORO_GIT_COMMIT_google_cloud_go \
- | grep -Ev '(\.md$|^\.github)' || true)
+SIGNIFICANT_CHANGES=$(git --no-pager diff --name-only origin/main...$KOKORO_GIT_COMMIT_google_cloud_go |
+ grep -Ev '(\.md$|^\.github)' || true)
# CHANGED_DIRS is the list of significant top-level directories that changed,
# but weren't deleted by the current PR. CHANGED_DIRS will be empty when run on main.
-CHANGED_DIRS=$(echo "$SIGNIFICANT_CHANGES" | tr ' ' '\n' | grep "/" | cut -d/ -f1 | sort -u \
- | tr '\n' ' ' | xargs ls -d 2>/dev/null || true)
+CHANGED_DIRS=$(echo "$SIGNIFICANT_CHANGES" | tr ' ' '\n' | grep "/" | cut -d/ -f1 | sort -u |
+ tr '\n' ' ' | xargs ls -d 2>/dev/null || true)
echo "Running tests only in changed submodules: $CHANGED_DIRS"
for d in $CHANGED_DIRS; do
- for i in `find "$d" -name go.mod`; do
- pushd `dirname $i`;
+ for i in $(find "$d" -name go.mod); do
+ pushd $(dirname $i)
runPresubmitTests
- popd;
+ popd
done
done
