Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions .kokoro/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 0 additions & 33 deletions .kokoro/presubmit/samples.cfg

This file was deleted.

1 change: 1 addition & 0 deletions java-bigquery/.cloudbuild/samples_build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
1 change: 1 addition & 0 deletions java-bigquerystorage/.cloudbuild/samples_build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions java-datastore/.cloudbuild/samples_build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions java-logging/.cloudbuild/samples_build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions java-storage/.cloudbuild/samples_build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
13 changes: 13 additions & 0 deletions monorepo-migration/migrate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
56 changes: 56 additions & 0 deletions monorepo-migration/update_samples_build.py
Original file line number Diff line number Diff line change
@@ -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 <path_to_yaml> <library_name>")
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
Comment on lines +30 to +46
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The script has two potential issues with its logic:

  1. The check if 'BUILD_SUBDIR=' in content: is very broad and might trigger a false positive if the string appears in a comment or a different context, causing the script to skip necessary updates.
  2. It injects BUILD_SUBDIR into the first env: block it finds. In multi-step Cloud Build configs, the first step might be a setup task (e.g., cloning or decryption), while the actual build step (which needs the variable) is further down. Since env variables are step-scoped in Cloud Build, the variable must be added to the specific step that executes the build script.


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()
Loading