Skip to content

chore: migrate samples to google-cloud-python system test infrastructure#2768

Merged
ohmayr merged 17 commits into
mainfrom
fix-samples-presubmit
Jun 18, 2026
Merged

chore: migrate samples to google-cloud-python system test infrastructure#2768
ohmayr merged 17 commits into
mainfrom
fix-samples-presubmit

Conversation

@ohmayr

@ohmayr ohmayr commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

This PR migrates the sample testing infrastructure away from the broken/legacy python-docs-samples secrets setup. It adopts the standard python-multi docker image and trampoline.sh execution flow used by the rest of google-cloud-python. Additionally, it permanently drops the .kokoro configurations and required GitHub status checks for the unsupported Python 3.7, 3.8, and 3.9 environments.

Fixes: #2767

@product-auto-label product-auto-label Bot added size: s Pull request size is small. samples Issues that are directly related to samples. labels Jun 18, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request migrates the samples directory to tests/system and updates the corresponding Kokoro configuration files, test scripts, Makefile, and other tooling to reference the new path. The review feedback highlights a critical issue where periodic builds rewinding to older releases will fail because tests/system does not exist yet; a dynamic fallback to samples is suggested. Additionally, the reviewer recommends updating TRAMPOLINE_BUILD_FILE in periodic-head.cfg files to reflect the renamed script, and adding safety checks to ensure KOKORO_GFILE_DIR is non-empty before checking for files within it.

Comment on lines +19 to +23
# Exit early if samples don't exist
if ! find tests/system -name 'requirements.txt' | grep -q .; then
echo "No tests run. './tests/system/**/requirements.txt' not found"
exit 0
fi

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

During periodic builds, the repository is checked out at the LATEST_RELEASE tag (which was created before this migration). At that tag, the tests/system directory does not exist, but samples does. As a result, find tests/system will fail, and the script will silently exit with 0 without running any tests.

To prevent this, we should dynamically fall back to samples if tests/system is not present.

Suggested change
# Exit early if samples don't exist
if ! find tests/system -name 'requirements.txt' | grep -q .; then
echo "No tests run. './tests/system/**/requirements.txt' not found"
exit 0
fi
# Exit early if tests don't exist
TEST_DIR="tests/system"
if [ ! -d "$TEST_DIR" ] && [ -d "samples" ]; then
TEST_DIR="samples"
fi
if ! find "$TEST_DIR" -name 'requirements.txt' | grep -q .; then
echo "No tests run. './$TEST_DIR/**/requirements.txt' not found"
exit 0
fi

Comment thread .kokoro/test-system-impl.sh Outdated
set +e
RTN=0
ROOT=$(pwd)
for file in tests/system/**/requirements.txt; do

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Use the dynamically resolved $TEST_DIR variable to support running tests on older releases during periodic builds.

Suggested change
for file in tests/system/**/requirements.txt; do
for file in "$TEST_DIR"/**/requirements.txt; do

Comment thread .kokoro/test-system-against-head.sh Outdated
shopt -s globstar

exec .kokoro/test-samples-impl.sh
exec .kokoro/test-system-impl.sh

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Since .kokoro/test-samples-against-head.sh has been renamed to .kokoro/test-system-against-head.sh, please make sure to update the TRAMPOLINE_BUILD_FILE environment variable in all periodic-head.cfg files (e.g., .kokoro/system/python3.10/periodic-head.cfg, etc.) to point to the new filename. Currently, they still reference the old .kokoro/test-samples-against-head.sh path, which will cause those builds to fail.

Comment on lines +35 to +39
if [[ -f "${KOKORO_GFILE_DIR}/project-id.json" ]]; then
export PROJECT_ID=$(cat "${KOKORO_GFILE_DIR}/project-id.json")
export GOOGLE_CLOUD_PROJECT="${PROJECT_ID}"
gcloud config set project "$PROJECT_ID"
fi

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

It is safer to ensure KOKORO_GFILE_DIR is non-empty before checking for the existence of project-id.json to avoid checking the root directory /project-id.json if the variable is unset.

Suggested change
if [[ -f "${KOKORO_GFILE_DIR}/project-id.json" ]]; then
export PROJECT_ID=$(cat "${KOKORO_GFILE_DIR}/project-id.json")
export GOOGLE_CLOUD_PROJECT="${PROJECT_ID}"
gcloud config set project "$PROJECT_ID"
fi
if [[ -n "${KOKORO_GFILE_DIR}" && -f "${KOKORO_GFILE_DIR}/project-id.json" ]]; then
export PROJECT_ID=$(cat "${KOKORO_GFILE_DIR}/project-id.json")
export GOOGLE_CLOUD_PROJECT="${PROJECT_ID}"
gcloud config set project "$PROJECT_ID"
fi

Comment on lines +42 to +45
if [[ -f "${KOKORO_GFILE_DIR}/service-account.json" ]]; then
export GOOGLE_APPLICATION_CREDENTIALS="${KOKORO_GFILE_DIR}/service-account.json"
gcloud auth activate-service-account --key-file="${GOOGLE_APPLICATION_CREDENTIALS}"
fi

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

It is safer to ensure KOKORO_GFILE_DIR is non-empty before checking for the existence of service-account.json to avoid checking the root directory /service-account.json if the variable is unset.

Suggested change
if [[ -f "${KOKORO_GFILE_DIR}/service-account.json" ]]; then
export GOOGLE_APPLICATION_CREDENTIALS="${KOKORO_GFILE_DIR}/service-account.json"
gcloud auth activate-service-account --key-file="${GOOGLE_APPLICATION_CREDENTIALS}"
fi
if [[ -n "${KOKORO_GFILE_DIR}" && -f "${KOKORO_GFILE_DIR}/service-account.json" ]]; then
export GOOGLE_APPLICATION_CREDENTIALS="${KOKORO_GFILE_DIR}/service-account.json"
gcloud auth activate-service-account --key-file="${GOOGLE_APPLICATION_CREDENTIALS}"
fi

@product-auto-label product-auto-label Bot added size: m Pull request size is medium. and removed size: s Pull request size is small. labels Jun 18, 2026
@product-auto-label product-auto-label Bot added size: l Pull request size is large. and removed size: m Pull request size is medium. labels Jun 18, 2026
@product-auto-label product-auto-label Bot added size: m Pull request size is medium. and removed size: l Pull request size is large. labels Jun 18, 2026
@product-auto-label product-auto-label Bot added size: l Pull request size is large. and removed size: m Pull request size is medium. labels Jun 18, 2026
@ohmayr ohmayr changed the title chore: migrate samples to system infra chore: migrate samples to google-cloud-python system test infrastructure Jun 18, 2026

@daniel-sanche daniel-sanche left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ohmayr ohmayr marked this pull request as ready for review June 18, 2026 22:10
@ohmayr ohmayr requested a review from a team as a code owner June 18, 2026 22:10
@product-auto-label product-auto-label Bot added size: xs Pull request size is extra small. and removed size: l Pull request size is large. labels Jun 18, 2026
@product-auto-label product-auto-label Bot added size: l Pull request size is large. and removed size: xs Pull request size is extra small. labels Jun 18, 2026
@ohmayr ohmayr merged commit 348fc8f into main Jun 18, 2026
16 checks passed
@ohmayr ohmayr deleted the fix-samples-presubmit branch June 18, 2026 23:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

samples Issues that are directly related to samples. size: l Pull request size is large.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Kokoro presubmit failing: python-docs-samples secrets are DISABLED

2 participants