build: adapt samples build configurations for monorepo#13033
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a new 'samples' job type to the Kokoro build script and updates several Cloud Build configurations to include a 'BUILD_SUBDIR' environment variable, supporting the monorepo migration. It also adds a Python script and updates the migration shell script to automate these YAML modifications. Feedback identifies critical issues with error propagation in the build script, where failures in module installation or Maven execution might be masked, and potential logic flaws in the Python script regarding the broad detection of existing variables and the placement of environment variables in multi-step Cloud Build configurations.
| 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 |
There was a problem hiding this comment.
The script has two potential issues with its logic:
- 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. - It injects
BUILD_SUBDIRinto the firstenv: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. Sinceenvvariables are step-scoped in Cloud Build, the variable must be added to the specific step that executes the build script.
645c0b2 to
42f01b6
Compare
Adapts samples build configurations for already-migrated libraries in the monorepo by injecting the mandatory
BUILD_SUBDIRenvironment variable.samples_build.yamlfiles in already-migrated directories:java-bigquery,java-bigquerystorage,java-datastore,java-logging, andjava-storage.This ensures that samples build runs execute within their correct subdirectories in the monorepo environment. Note that the automation helper script and migration integration have been moved to the central tooling branch.
Towards #12983