diff --git a/.kokoro/build.sh b/.kokoro/build.sh index 3691dd9a0a3f..46d18a23a149 100755 --- a/.kokoro/build.sh +++ b/.kokoro/build.sh @@ -328,6 +328,48 @@ case ${JOB_TYPE} in popd fi ;; + samples) + if [[ -z "${BUILD_SUBDIR}" ]]; then + echo "Error: BUILD_SUBDIR must be set for samples job type." >&2 + exit 1 + fi + + SAMPLES_DIR=samples + # only run ITs in snapshot/ on presubmit PRs. run ITs in all 3 samples/ subdirectories otherwise. + if [[ ! -z ${KOKORO_GITHUB_PULL_REQUEST_NUMBER} ]] + then + SAMPLES_DIR=samples/snapshot + fi + + FULL_SAMPLES_DIR="${BUILD_SUBDIR}/${SAMPLES_DIR}" + + if [[ -f "${FULL_SAMPLES_DIR}/pom.xml" ]] + then + for FILE in ${KOKORO_GFILE_DIR}/secret_manager/*-samples-secrets; do + [[ -f "$FILE" ]] || continue + source "$FILE" + done + + echo "Installing modules for ${BUILD_SUBDIR}..." + install_modules "${BUILD_SUBDIR}" || RETURN_CODE=$? + + if [[ "${RETURN_CODE:-0}" -eq 0 ]]; then + pushd "${FULL_SAMPLES_DIR}" + mvn -B \ + -ntp \ + -DtrimStackTrace=false \ + -Dclirr.skip=true \ + -Denforcer.skip=true \ + -Dfmt.skip=true \ + -fae \ + verify + RETURN_CODE=$? + popd + fi + else + echo "no sample pom.xml found in ${FULL_SAMPLES_DIR} - skipping sample tests" + fi + ;; *) ;; esac diff --git a/.kokoro/presubmit/samples.cfg b/.kokoro/presubmit/samples.cfg deleted file mode 100644 index ba8d719411d6..000000000000 --- a/.kokoro/presubmit/samples.cfg +++ /dev/null @@ -1,33 +0,0 @@ -# Format: //devtools/kokoro/config/proto/build.proto - -# Configure the docker image for kokoro-trampoline. -env_vars: { - key: "TRAMPOLINE_IMAGE" - value: "gcr.io/cloud-devrel-kokoro-resources/java11" -} - -env_vars: { - key: "JOB_TYPE" - value: "samples" -} - -# TODO: remove this after we've migrated all tests and scripts -env_vars: { - key: "GCLOUD_PROJECT" - value: "java-docs-samples-testing" -} - -env_vars: { - key: "GOOGLE_CLOUD_PROJECT" - value: "java-docs-samples-testing" -} - -env_vars: { - key: "GOOGLE_APPLICATION_CREDENTIALS" - value: "secret_manager/java-docs-samples-service-account" -} - -env_vars: { - key: "SECRET_MANAGER_KEYS" - value: "java-docs-samples-service-account" -} \ No newline at end of file diff --git a/java-bigquery/.cloudbuild/samples_build.yaml b/java-bigquery/.cloudbuild/samples_build.yaml index 354adf972029..ccabd1a9fb34 100644 --- a/java-bigquery/.cloudbuild/samples_build.yaml +++ b/java-bigquery/.cloudbuild/samples_build.yaml @@ -20,6 +20,7 @@ steps: ] env: - 'JOB_TYPE=samples' + - 'BUILD_SUBDIR=java-bigquery' - 'BIGQUERY_PROJECT_ID=cloud-java-ci-sample' - 'GOOGLE_CLOUD_PROJECT=cloud-java-ci-sample' - 'GCS_BUCKET=java-samples-bigquery' diff --git a/java-bigquerystorage/.cloudbuild/samples_build.yaml b/java-bigquerystorage/.cloudbuild/samples_build.yaml index 333515cfd7f8..6ee3da56cc90 100644 --- a/java-bigquerystorage/.cloudbuild/samples_build.yaml +++ b/java-bigquerystorage/.cloudbuild/samples_build.yaml @@ -20,6 +20,7 @@ steps: ] env: - 'JOB_TYPE=samples' + - 'BUILD_SUBDIR=java-bigquerystorage' - 'GOOGLE_CLOUD_PROJECT=cloud-java-ci-sample' - 'BIGTABLE_TESTING_INSTANCE=instance' - name: gcr.io/cloud-devrel-public-resources/java8 diff --git a/java-datastore/.cloudbuild/samples_build.yaml b/java-datastore/.cloudbuild/samples_build.yaml index 3dd2ff94ced1..12de85bb085c 100644 --- a/java-datastore/.cloudbuild/samples_build.yaml +++ b/java-datastore/.cloudbuild/samples_build.yaml @@ -20,6 +20,7 @@ steps: ] env: - 'JOB_TYPE=samples' + - 'BUILD_SUBDIR=java-datastore' - 'GOOGLE_CLOUD_PROJECT=cloud-java-ci-sample' - 'KOKORO_GITHUB_PULL_REQUEST_NUMBER=$_PR_NUMBER' - name: gcr.io/cloud-devrel-public-resources/java11 diff --git a/java-logging/.cloudbuild/samples_build.yaml b/java-logging/.cloudbuild/samples_build.yaml index 018fdd1fcf9c..ae64e2c27696 100644 --- a/java-logging/.cloudbuild/samples_build.yaml +++ b/java-logging/.cloudbuild/samples_build.yaml @@ -19,6 +19,7 @@ steps: '.kokoro/build.sh' ] env: + - 'BUILD_SUBDIR=java-logging' - 'JOB_TYPE=samples' - 'GOOGLE_CLOUD_PROJECT=cloud-java-ci-sample' - name: gcr.io/cloud-devrel-public-resources/java8 diff --git a/java-storage/.cloudbuild/samples_build.yaml b/java-storage/.cloudbuild/samples_build.yaml index c22f133517d0..d9f727b272d7 100644 --- a/java-storage/.cloudbuild/samples_build.yaml +++ b/java-storage/.cloudbuild/samples_build.yaml @@ -20,6 +20,7 @@ steps: ] env: - 'JOB_TYPE=samples' + - 'BUILD_SUBDIR=java-storage' - 'GOOGLE_CLOUD_PROJECT=cloud-java-ci-sample' - 'GOOGLE_CLOUD_PROJECT_NUMBER=615621127317' - 'IT_SERVICE_ACCOUNT_EMAIL=samples@cloud-java-ci-sample.iam.gserviceaccount.com' diff --git a/monorepo-migration/migrate.sh b/monorepo-migration/migrate.sh index 93b4b2c788c4..73bf816b1bbc 100755 --- a/monorepo-migration/migrate.sh +++ b/monorepo-migration/migrate.sh @@ -56,6 +56,7 @@ FIX_COPYRIGHT_SCRIPT="$TRANSFORM_SCRIPT_DIR/fix_copyright_headers.py" UPDATE_GENERATION_CONFIG_SCRIPT="$TRANSFORM_SCRIPT_DIR/update_generation_config.py" UPDATE_OWLBOT_HERMETIC_SCRIPT="$TRANSFORM_SCRIPT_DIR/update_owlbot_hermetic.py" TRANSFORM_OWLBOT_SCRIPT="$TRANSFORM_SCRIPT_DIR/update_owlbot.py" +UPDATE_SAMPLES_BUILD_SCRIPT="$TRANSFORM_SCRIPT_DIR/update_samples_build.py" # Track number of commits made by this script COMMIT_COUNT=0 @@ -251,6 +252,18 @@ if [ -d "$SOURCE_REPO_NAME/.github/workflows" ]; then COMMIT_COUNT=$((COMMIT_COUNT + 1)) fi +# 7.5b Adapt samples_build.yaml if present +SAMPLES_BUILD_YAML="$SOURCE_REPO_NAME/.cloudbuild/samples_build.yaml" +if [ -f "$SAMPLES_BUILD_YAML" ]; then + echo "Adapting samples_build.yaml..." + python3 "$UPDATE_SAMPLES_BUILD_SCRIPT" "$SAMPLES_BUILD_YAML" "$SOURCE_REPO_NAME" + + echo "Committing samples_build.yaml update..." + git add "$SAMPLES_BUILD_YAML" + git commit -n --no-gpg-sign -m "chore($SOURCE_REPO_NAME): adapt samples_build.yaml for monorepo" + COMMIT_COUNT=$((COMMIT_COUNT + 1)) +fi + # 7.6 Update generation_config.yaml echo "Updating generation_config.yaml..." SOURCE_CONFIG="$SOURCE_REPO_NAME/generation_config.yaml" diff --git a/monorepo-migration/update_samples_build.py b/monorepo-migration/update_samples_build.py new file mode 100755 index 000000000000..50b837c055a4 --- /dev/null +++ b/monorepo-migration/update_samples_build.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python3 +# Copyright 2026 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +import re + +def main(): + if len(sys.argv) < 3: + print("Usage: update_samples_build.py ") + sys.exit(1) + + file_path = sys.argv[1] + library_name = sys.argv[2] + + with open(file_path, 'r') as f: + content = f.read() + + if 'BUILD_SUBDIR=' in content: + print(f"BUILD_SUBDIR already present in {file_path}. Skipping.") + sys.exit(0) + + # Find the 'env:' line and insert 'BUILD_SUBDIR' after it + lines = content.splitlines() + new_lines = [] + modified = False + + for line in lines: + new_lines.append(line) + match = re.match(r'^(\s*)env:\s*$', line) + if match and not modified: + indent = match.group(1) + # Insert BUILD_SUBDIR under env: + new_lines.append(f"{indent}- 'BUILD_SUBDIR={library_name}'") + modified = True + + if modified: + with open(file_path, 'w') as f: + f.write('\n'.join(new_lines) + '\n') + print(f"Successfully added BUILD_SUBDIR={library_name} to {file_path}") + else: + print(f"Warning: Could not find 'env:' block in {file_path}") + +if __name__ == '__main__': + main()