fix: manual preservation of Version.java files#12862
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a workaround to prevent owl-bot copy-code from omitting Version.java files by implementing a backup and restore mechanism during the post-processing phase. The changes include new utility functions backup_version_java and restore_version_java in utilities.sh, and their integration into postprocess_library.sh. Review feedback highlights potential issues with shell word splitting in the new functions and suggests using find -print0 with a while read loop to safely handle filenames that may contain spaces.
…ities.sh Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
…ities.sh Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Removed outdated regex for Version.java and adjusted deep-preserve-regex.
…gleapis/google-cloud-java into fix/version-java-owlbot-yaml
…gleapis/google-cloud-java into fix/version-java-owlbot-yaml
|
|
|
cc: @zhumin8 since this may affect librarian migration. |



Description
This PR addresses an issue where
Version.javafiles were either incorrectly preserved or not generated during a library's initial generation due to an overly relaxeddeep-preserve-regexrule in the OwlBot configuration templates.To fix this edge case, we are moving the responsibility of preserving existing
Version.javafiles away from the OwlBot YAML regex and directly into our hermetic build scripts.Implementation Details
deep-preserve-regexrule targetingVersion.javafromowlbot.yaml.monorepo.j2.utilities.shand invoked them inpostprocess_library.sh. The script now dynamically scans for existingVersion.javafiles, backs them up to a temporary directory before executingowl-bot copy-code, and restores them immediately after.Why this approach?
Version.javafiles, the script does nothing, allowing OwlBot to generate and retain the new file as intended.Version.javafiles. Because ourbackup_version_javautility copies the existing file out of the repository beforeowl-bot copy-codeexecutes, the file containing the updated Release Please version string is safely stored inmktemp -d. Afterowl-bot copy-codewrites the newly generated, genericVersion.javafile to the repo,restore_version_javaoverwrites it with our backup. This guarantees the Release Please version updates are perfectly preserved.mktemp -dwhich guarantees they are unaffected by OwlBot'sdeep-remove-regexfolder wipes.Testing
chore/test-hermetic-buildbranch with arbitrary values inVersion.javafiles and confirm they remain untouched via integration test