Commit 3d65c78
fix: manual preservation of Version.java files (#12862)
### 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
- [x] 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
---------
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>1 parent b974740 commit 3d65c78
File tree
5 files changed
+70
-2
lines changed- sdk-platform-java/hermetic_build/library_generation
- templates
- tests
- resources/goldens
- utils
5 files changed
+70
-2
lines changedLines changed: 9 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
88 | 94 | | |
89 | 95 | | |
90 | 96 | | |
91 | 97 | | |
92 | 98 | | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
93 | 102 | | |
94 | 103 | | |
95 | 104 | | |
| |||
Lines changed: 0 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
25 | 24 | | |
26 | 25 | | |
27 | 26 | | |
| |||
Lines changed: 22 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
213 | 213 | | |
214 | 214 | | |
215 | 215 | | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
216 | 237 | | |
217 | 238 | | |
218 | 239 | | |
| |||
266 | 287 | | |
267 | 288 | | |
268 | 289 | | |
| 290 | + | |
269 | 291 | | |
270 | 292 | | |
271 | 293 | | |
| |||
Lines changed: 0 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
25 | 24 | | |
26 | 25 | | |
27 | 26 | | |
| |||
Lines changed: 39 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
334 | 334 | | |
335 | 335 | | |
336 | 336 | | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
337 | 376 | | |
338 | 377 | | |
339 | 378 | | |
| |||
0 commit comments