Skip to content

Commit c9e1b8d

Browse files
authored
chore: run system tests only for modified packages (#14449)
Currently the system test runs for all packages. This PR adds logic to check if there is a change to the package level `CHANGELOG.md` so that we only runs system tests for packages that have changed. We are only interested in `packages/<package>/CHANGELOG.md` changing as we only want to run system tests on release PRs. Fixes googleapis/librarian#2067
1 parent 8ac6820 commit c9e1b8d

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

.kokoro/system.sh

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,35 @@ pwd
3838
# A file for running system tests
3939
system_test_script="${PROJECT_ROOT}/.kokoro/system-single.sh"
4040

41+
# This is needed in order for `git diff` to succeed
42+
git config --global --add safe.directory $(realpath .)
43+
4144
# Run system tests for each package with directory packages/*/tests/system
4245
for dir in `find 'packages' -type d -wholename 'packages/*/tests/system'`; do
4346
# Get the path to the package by removing the suffix /tests/system
4447
package=$(echo $dir | cut -f -2 -d '/')
45-
echo "Running system tests for ${package}"
46-
pushd ${package}
47-
# Temporarily allow failure.
48+
49+
files_to_check=${package}/CHANGELOG.md
50+
51+
echo "checking changes with 'git diff "${KOKORO_GITHUB_PULL_REQUEST_TARGET_BRANCH}...${KOKORO_GITHUB_PULL_REQUEST_COMMIT}" -- ${files_to_check}'"
4852
set +e
49-
${system_test_script}
50-
ret=$?
53+
package_modified=$(git diff "${KOKORO_GITHUB_PULL_REQUEST_TARGET_BRANCH}...${KOKORO_GITHUB_PULL_REQUEST_COMMIT}" -- ${files_to_check} | wc -l)
5154
set -e
52-
if [ ${ret} -ne 0 ]; then
53-
RETVAL=${ret}
55+
if [[ "${package_modified}" -eq 0 ]]; then
56+
echo "no change detected in ${files_to_check}, skipping"
57+
else
58+
echo "change detected in ${files_to_check}"
59+
echo "Running system tests for ${package}"
60+
pushd ${package}
61+
# Temporarily allow failure.
62+
set +e
63+
${system_test_script}
64+
ret=$?
65+
set -e
66+
if [ ${ret} -ne 0 ]; then
67+
RETVAL=${ret}
68+
fi
69+
popd
5470
fi
55-
popd
5671
done
57-
5872
exit ${RETVAL}

0 commit comments

Comments
 (0)