Skip to content

fix: manual preservation of Version.java files#12862

Merged
diegomarquezp merged 10 commits intomainfrom
fix/version-java-owlbot-yaml
Apr 21, 2026
Merged

fix: manual preservation of Version.java files#12862
diegomarquezp merged 10 commits intomainfrom
fix/version-java-owlbot-yaml

Conversation

@diegomarquezp
Copy link
Copy Markdown
Contributor

@diegomarquezp diegomarquezp commented Apr 20, 2026

Description

This PR addresses an issue where Version.java files were either incorrectly preserved or not generated during a library's initial generation due to an overly relaxed deep-preserve-regex rule in the OwlBot configuration templates.

To fix this edge case, we are moving the responsibility of preserving existing Version.java files away from the OwlBot YAML regex and directly into our hermetic build scripts.

Implementation Details

  1. Removed Obsolete Regex: Removed the deep-preserve-regex rule targeting Version.java from owlbot.yaml.monorepo.j2.
  2. Conditional Backup/Restore: Extracted new backup and restore utilities into utilities.sh and invoked them in postprocess_library.sh. The script now dynamically scans for existing Version.java files, backs them up to a temporary directory before executing owl-bot copy-code, and restores them immediately after.

Why this approach?

  • First Generation: Since there are no existing Version.java files, the script does nothing, allowing OwlBot to generate and retain the new file as intended.
  • Release Please Interoperability: Release Please regularly updates the version string inside existing Version.java files. Because our backup_version_java utility copies the existing file out of the repository before owl-bot copy-code executes, the file containing the updated Release Please version string is safely stored in mktemp -d. After owl-bot copy-code writes the newly generated, generic Version.java file to the repo, restore_version_java overwrites it with our backup. This guarantees the Release Please version updates are perfectly preserved.
  • Hermetic Safety: The backups are stored in mktemp -d which guarantees they are unaffected by OwlBot's deep-remove-regex folder wipes.

Testing

  • Added unit tests
  • Once approach is validated: modify the chore/test-hermetic-build branch with arbitrary values in Version.java files and confirm they remain untouched via integration test

Copy link
Copy Markdown
Contributor

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

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 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.

Comment thread sdk-platform-java/hermetic_build/library_generation/utils/utilities.sh Outdated
Comment thread sdk-platform-java/hermetic_build/library_generation/utils/utilities.sh Outdated
diegomarquezp and others added 9 commits April 20, 2026 14:29
…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.
@diegomarquezp diegomarquezp marked this pull request as ready for review April 20, 2026 20:06
@diegomarquezp diegomarquezp requested a review from a team as a code owner April 20, 2026 20:06
@sonarqubecloud
Copy link
Copy Markdown

@sonarqubecloud
Copy link
Copy Markdown

@blakeli0
Copy link
Copy Markdown
Contributor

cc: @zhumin8 since this may affect librarian migration.

@diegomarquezp diegomarquezp merged commit 3d65c78 into main Apr 21, 2026
117 of 119 checks passed
@diegomarquezp diegomarquezp deleted the fix/version-java-owlbot-yaml branch April 21, 2026 01:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants