fix(google-cloud-secretmanager): improve librarian.js script and add missing functions#8424
Conversation
…d missing functions
There was a problem hiding this comment.
Code Review
This pull request updates the librarian.js script to process multiple client files and throw an error if replacements fail, while also adding path templates and helper methods to the v1 and v1beta2 Secret Manager service clients. Feedback was provided to make the librarian.js script idempotent to prevent build pipeline failures when run on already-processed files.
| filePaths.forEach(filePath => { | ||
| if (fs.existsSync(filePath)) { | ||
| replaceInFile(filePath, /return\sPromise\.resolve\(\);\s+}\s+}/g, replacement1); | ||
| replaceInFile(filePath, /topicPathTemplate:\s+new\s+this\._gaxModule\.PathTemplate\(\s+'projects\/{project}\/topics\/{topic}',?\s*\),?\s*};/g, replacement2); | ||
| } | ||
| }); No newline at end of file |
There was a problem hiding this comment.
The replaceInFile function now throws an error if no replacement is made. Since librarian.js is run as a post-processing script, running it on already-processed files (or running it twice) will cause the script to fail with an error, breaking the build/generation pipeline.
To make the script idempotent and safe to run multiple times, we can check if the file has already been processed (e.g., by checking if it contains secretVersionPath) and skip it gracefully.
| filePaths.forEach(filePath => { | |
| if (fs.existsSync(filePath)) { | |
| replaceInFile(filePath, /return\sPromise\.resolve\(\);\s+}\s+}/g, replacement1); | |
| replaceInFile(filePath, /topicPathTemplate:\s+new\s+this\._gaxModule\.PathTemplate\(\s+'projects\/{project}\/topics\/{topic}',?\s*\),?\s*};/g, replacement2); | |
| } | |
| }); | |
| filePaths.forEach(filePath => { | |
| if (fs.existsSync(filePath)) { | |
| const content = fs.readFileSync(filePath, 'utf8'); | |
| if (content.includes('secretVersionPath')) { | |
| console.log("File " + filePath + " is already processed. Skipping."); | |
| return; | |
| } | |
| replaceInFile(filePath, /return\sPromise\.resolve\(\);\s+}\s+}/g, replacement1); | |
| replaceInFile(filePath, /topicPathTemplate:\s+new\s+this\._gaxModule\.PathTemplate\(\s+'projects\/{project}\/topics\/{topic}',?\s*\),?\s*};/g, replacement2); | |
| } | |
| }); |
There was a problem hiding this comment.
@pearigee What do you think? Our long-term goal is to remove the file. Since this will eventually run in Librarian, we should add error handling in librarian for cases where the file fails rather than making it idempotent.
🤖 I have created a release *beep* *boop* --- <details><summary>datamanager: 0.4.0</summary> ## [0.4.0](https://togithub.com/googleapis/google-cloud-node/compare/datamanager-v0.3.0...datamanager-v0.4.0) (2026-06-16) ### Features * [datamanager] add encrypted_user_id.proto and the EncryptedUserId resource ([#8378](https://togithub.com/googleapis/google-cloud-node/issues/8378)) ([f5b12cf](https://togithub.com/googleapis/google-cloud-node/commit/f5b12cf10d9974c87e651e1182a5804030af8cdc)) </details> <details><summary>alloydb: 2.6.0</summary> ## [2.6.0](https://togithub.com/googleapis/google-cloud-node/compare/alloydb-v2.5.1...alloydb-v2.6.0) (2026-06-16) ### Features * Migrate google-cloud-alloydb to librarian ([#8491](https://togithub.com/googleapis/google-cloud-node/issues/8491)) ([2a7f823](https://togithub.com/googleapis/google-cloud-node/commit/2a7f82336695397220cae1ee249f8ff5e1871b60)) </details> <details><summary>api-gateway: 4.3.0</summary> ## [4.3.0](https://togithub.com/googleapis/google-cloud-node/compare/api-gateway-v4.2.2...api-gateway-v4.3.0) (2026-06-16) ### Features * Migrate google-cloud-apigateway to librarian ([#8492](https://togithub.com/googleapis/google-cloud-node/issues/8492)) ([29e4147](https://togithub.com/googleapis/google-cloud-node/commit/29e4147e202ac786d7a943e0156be4160bba459f)) </details> <details><summary>apigee-connect: 4.3.0</summary> ## [4.3.0](https://togithub.com/googleapis/google-cloud-node/compare/apigee-connect-v4.2.2...apigee-connect-v4.3.0) (2026-06-16) ### Features * Migrate google-cloud-apigeeconnect to librarian ([#8493](https://togithub.com/googleapis/google-cloud-node/issues/8493)) ([e314fa8](https://togithub.com/googleapis/google-cloud-node/commit/e314fa8c1aada689298f0ba84619f6918d17cb05)) </details> <details><summary>dataproc: 6.6.0</summary> ## [6.6.0](https://togithub.com/googleapis/google-cloud-node/compare/dataproc-v6.5.1...dataproc-v6.6.0) (2026-06-16) ### Features * Regenerated google-cloud-dataproc ([#8604](https://togithub.com/googleapis/google-cloud-node/issues/8604)) ([3b7367a](https://togithub.com/googleapis/google-cloud-node/commit/3b7367a24115ccf43bd46646f257cee6e787c07c)) </details> <details><summary>locationfinder: 0.2.0</summary> ## [0.2.0](https://togithub.com/googleapis/google-cloud-node/compare/locationfinder-v0.1.2...locationfinder-v0.2.0) (2026-06-16) ### Features * Update google-cloud-locationfinder API ([#8583](https://togithub.com/googleapis/google-cloud-node/issues/8583)) ([8882faa](https://togithub.com/googleapis/google-cloud-node/commit/8882faa7faecb3afab2f3a658d33bcc125b48885)) </details> <details><summary>recommender: 7.3.0</summary> ## [7.3.0](https://togithub.com/googleapis/google-cloud-node/compare/recommender-v7.2.2...recommender-v7.3.0) (2026-06-16) ### Features * [recommender] Support utilization insights and cloud hub ([#8375](https://togithub.com/googleapis/google-cloud-node/issues/8375)) ([7e6c7be](https://togithub.com/googleapis/google-cloud-node/commit/7e6c7bead35a43c675c8875ff1fd2979badeb6f7)) </details> <details><summary>redis: 5.3.0</summary> ## [5.3.0](https://togithub.com/googleapis/google-cloud-node/compare/redis-v5.2.2...redis-v5.3.0) (2026-06-16) ### Features * Local OwlBot generation batch 1 ([#8612](https://togithub.com/googleapis/google-cloud-node/issues/8612)) ([b4d5da7](https://togithub.com/googleapis/google-cloud-node/commit/b4d5da72a41c4d961eaeee7b7633c7885ecb9166)) </details> <details><summary>redis-cluster: 0.11.0</summary> ## [0.11.0](https://togithub.com/googleapis/google-cloud-node/compare/redis-cluster-v0.10.0...redis-cluster-v0.11.0) (2026-06-16) ### Features * Local OwlBot generation batch 1 ([#8612](https://togithub.com/googleapis/google-cloud-node/issues/8612)) ([b4d5da7](https://togithub.com/googleapis/google-cloud-node/commit/b4d5da72a41c4d961eaeee7b7633c7885ecb9166)) </details> <details><summary>resource-manager: 6.3.0</summary> ## [6.3.0](https://togithub.com/googleapis/google-cloud-node/compare/resource-manager-v6.2.2...resource-manager-v6.3.0) (2026-06-16) ### Features * Local OwlBot generation batch 1 ([#8612](https://togithub.com/googleapis/google-cloud-node/issues/8612)) ([b4d5da7](https://togithub.com/googleapis/google-cloud-node/commit/b4d5da72a41c4d961eaeee7b7633c7885ecb9166)) </details> <details><summary>retail: 4.4.0</summary> ## [4.4.0](https://togithub.com/googleapis/google-cloud-node/compare/retail-v4.3.1...retail-v4.4.0) (2026-06-16) ### Features * Local OwlBot generation batch 1 ([#8612](https://togithub.com/googleapis/google-cloud-node/issues/8612)) ([b4d5da7](https://togithub.com/googleapis/google-cloud-node/commit/b4d5da72a41c4d961eaeee7b7633c7885ecb9166)) </details> <details><summary>run: 3.3.0</summary> ## [3.3.0](https://togithub.com/googleapis/google-cloud-node/compare/run-v3.2.1...run-v3.3.0) (2026-06-16) ### Features * Local OwlBot generation batch 1 ([#8612](https://togithub.com/googleapis/google-cloud-node/issues/8612)) ([b4d5da7](https://togithub.com/googleapis/google-cloud-node/commit/b4d5da72a41c4d961eaeee7b7633c7885ecb9166)) </details> <details><summary>scheduler: 5.4.0</summary> ## [5.4.0](https://togithub.com/googleapis/google-cloud-node/compare/scheduler-v5.3.2...scheduler-v5.4.0) (2026-06-16) ### Features * Local OwlBot generation batch 2 ([#8613](https://togithub.com/googleapis/google-cloud-node/issues/8613)) ([243fb1a](https://togithub.com/googleapis/google-cloud-node/commit/243fb1a66876934bd68ca96e420937ae8adeb77d)) </details> <details><summary>secret-manager: 6.2.0</summary> ## [6.2.0](https://togithub.com/googleapis/google-cloud-node/compare/secret-manager-v6.1.3...secret-manager-v6.2.0) (2026-06-16) ### Features * Local OwlBot generation batch 2 ([#8613](https://togithub.com/googleapis/google-cloud-node/issues/8613)) ([243fb1a](https://togithub.com/googleapis/google-cloud-node/commit/243fb1a66876934bd68ca96e420937ae8adeb77d)) ### Bug Fixes * **google-cloud-secretmanager:** Improve librarian.js script an re-add missing functions ([#8424](https://togithub.com/googleapis/google-cloud-node/issues/8424)) ([13d03c1](https://togithub.com/googleapis/google-cloud-node/commit/13d03c1f0f07f92770d44490050ab65498b4a8ff)) </details> <details><summary>securesourcemanager: 0.10.0</summary> ## [0.10.0](https://togithub.com/googleapis/google-cloud-node/compare/securesourcemanager-v0.9.1...securesourcemanager-v0.10.0) (2026-06-16) ### Features * Local OwlBot generation batch 2 ([#8613](https://togithub.com/googleapis/google-cloud-node/issues/8613)) ([243fb1a](https://togithub.com/googleapis/google-cloud-node/commit/243fb1a66876934bd68ca96e420937ae8adeb77d)) </details> <details><summary>security-private-ca: 7.2.0</summary> ## [7.2.0](https://togithub.com/googleapis/google-cloud-node/compare/security-private-ca-v7.1.0...security-private-ca-v7.2.0) (2026-06-16) ### Features * Local OwlBot generation batch 2 ([#8613](https://togithub.com/googleapis/google-cloud-node/issues/8613)) ([243fb1a](https://togithub.com/googleapis/google-cloud-node/commit/243fb1a66876934bd68ca96e420937ae8adeb77d)) </details> <details><summary>publicca: 2.3.0</summary> ## [2.3.0](https://togithub.com/googleapis/google-cloud-node/compare/publicca-v2.2.2...publicca-v2.3.0) (2026-06-16) ### Features * Local OwlBot generation batch 2 ([#8613](https://togithub.com/googleapis/google-cloud-node/issues/8613)) ([243fb1a](https://togithub.com/googleapis/google-cloud-node/commit/243fb1a66876934bd68ca96e420937ae8adeb77d)) </details> <details><summary>security-center: 9.4.0</summary> ## [9.4.0](https://togithub.com/googleapis/google-cloud-node/compare/security-center-v9.3.2...security-center-v9.4.0) (2026-06-16) ### Features * Local OwlBot generation batch 3 ([#8614](https://togithub.com/googleapis/google-cloud-node/issues/8614)) ([fae15ec](https://togithub.com/googleapis/google-cloud-node/commit/fae15ecca725f8e978341156e2c99c623ce74fcc)) </details> <details><summary>securitycentermanagement: 0.8.0</summary> ## [0.8.0](https://togithub.com/googleapis/google-cloud-node/compare/securitycentermanagement-v0.7.2...securitycentermanagement-v0.8.0) (2026-06-16) ### Features * Local OwlBot generation batch 3 ([#8614](https://togithub.com/googleapis/google-cloud-node/issues/8614)) ([fae15ec](https://togithub.com/googleapis/google-cloud-node/commit/fae15ecca725f8e978341156e2c99c623ce74fcc)) </details> <details><summary>service-directory: 6.2.0</summary> ## [6.2.0](https://togithub.com/googleapis/google-cloud-node/compare/service-directory-v6.1.3...service-directory-v6.2.0) (2026-06-16) ### Features * Local OwlBot generation batch 3 ([#8614](https://togithub.com/googleapis/google-cloud-node/issues/8614)) ([fae15ec](https://togithub.com/googleapis/google-cloud-node/commit/fae15ecca725f8e978341156e2c99c623ce74fcc)) </details> <details><summary>servicehealth: 0.8.0</summary> ## [0.8.0](https://togithub.com/googleapis/google-cloud-node/compare/servicehealth-v0.7.2...servicehealth-v0.8.0) (2026-06-16) ### Features * Local OwlBot generation batch 3 ([#8614](https://togithub.com/googleapis/google-cloud-node/issues/8614)) ([fae15ec](https://togithub.com/googleapis/google-cloud-node/commit/fae15ecca725f8e978341156e2c99c623ce74fcc)) </details> <details><summary>shell: 4.2.0</summary> ## [4.2.0](https://togithub.com/googleapis/google-cloud-node/compare/shell-v4.1.2...shell-v4.2.0) (2026-06-16) ### Features * Local OwlBot generation batch 3 ([#8614](https://togithub.com/googleapis/google-cloud-node/issues/8614)) ([fae15ec](https://togithub.com/googleapis/google-cloud-node/commit/fae15ecca725f8e978341156e2c99c623ce74fcc)) </details> <details><summary>speech: 7.4.0</summary> ## [7.4.0](https://togithub.com/googleapis/google-cloud-node/compare/speech-v7.3.2...speech-v7.4.0) (2026-06-16) ### Features * Local OwlBot generation batch 4 ([#8615](https://togithub.com/googleapis/google-cloud-node/issues/8615)) ([f629251](https://togithub.com/googleapis/google-cloud-node/commit/f629251e27e51aa06003b4846a497d5a7c411cc2)) </details> <details><summary>storagebatchoperations: 0.5.0</summary> ## [0.5.0](https://togithub.com/googleapis/google-cloud-node/compare/storagebatchoperations-v0.4.0...storagebatchoperations-v0.5.0) (2026-06-16) ### Features * Local OwlBot generation batch 4 ([#8615](https://togithub.com/googleapis/google-cloud-node/issues/8615)) ([f629251](https://togithub.com/googleapis/google-cloud-node/commit/f629251e27e51aa06003b4846a497d5a7c411cc2)) </details> <details><summary>storageinsights: 2.3.0</summary> ## [2.3.0](https://togithub.com/googleapis/google-cloud-node/compare/storageinsights-v2.2.2...storageinsights-v2.3.0) (2026-06-16) ### Features * Local OwlBot generation batch 4 ([#8615](https://togithub.com/googleapis/google-cloud-node/issues/8615)) ([f629251](https://togithub.com/googleapis/google-cloud-node/commit/f629251e27e51aa06003b4846a497d5a7c411cc2)) </details> <details><summary>support: 2.4.0</summary> ## [2.4.0](https://togithub.com/googleapis/google-cloud-node/compare/support-v2.3.0...support-v2.4.0) (2026-06-16) ### Features * Local OwlBot generation batch 4 ([#8615](https://togithub.com/googleapis/google-cloud-node/issues/8615)) ([f629251](https://togithub.com/googleapis/google-cloud-node/commit/f629251e27e51aa06003b4846a497d5a7c411cc2)) </details> <details><summary>talent: 7.2.0</summary> ## [7.2.0](https://togithub.com/googleapis/google-cloud-node/compare/talent-v7.1.3...talent-v7.2.0) (2026-06-16) ### Features * Regenerated google-cloud-talent ([#8616](https://togithub.com/googleapis/google-cloud-node/issues/8616)) ([8d87b39](https://togithub.com/googleapis/google-cloud-node/commit/8d87b39babf85a341506a1f4918a18a835887990)) </details> <details><summary>workstations: 2.3.0</summary> ## [2.3.0](https://togithub.com/googleapis/google-cloud-node/compare/workstations-v2.2.2...workstations-v2.3.0) (2026-06-16) ### Features * Migrate google-cloud-workstations to librarian ([#8480](https://togithub.com/googleapis/google-cloud-node/issues/8480)) ([127ce8d](https://togithub.com/googleapis/google-cloud-node/commit/127ce8d7a8fb8e3b56a25c0b3b3122c20aee81d5)) </details> <details><summary>containeranalysis: 6.8.0</summary> ## [6.8.0](https://togithub.com/googleapis/google-cloud-node/compare/containeranalysis-v6.7.2...containeranalysis-v6.8.0) (2026-06-16) ### Features * Migrate google-devtools-containeranalysis to librarian ([#8534](https://togithub.com/googleapis/google-cloud-node/issues/8534)) ([48cfd70](https://togithub.com/googleapis/google-cloud-node/commit/48cfd703e8632bc2b219a298a98301de23dc3ea9)) ### Bug Fixes * Update librarian.js for containeranalysis to fix postproccessing issue ([#8489](https://togithub.com/googleapis/google-cloud-node/issues/8489)) ([9f7d7b9](https://togithub.com/googleapis/google-cloud-node/commit/9f7d7b9132694b89908243d7c284c0a6e121826d)) </details> <details><summary>grafeas: 6.2.0</summary> ## [6.2.0](https://togithub.com/googleapis/google-cloud-node/compare/grafeas-v6.1.2...grafeas-v6.2.0) (2026-06-16) ### Features * Regenerated google-cloud-monitoring ([#8618](https://togithub.com/googleapis/google-cloud-node/issues/8618)) ([4b5aff4](https://togithub.com/googleapis/google-cloud-node/commit/4b5aff4b65b3729f3742d25ba0674bad0943d456)) </details> <details><summary>ces: 0.4.1</summary> ## [0.4.1](https://togithub.com/googleapis/google-cloud-node/compare/ces-v0.4.0...ces-v0.4.1) (2026-06-16) ### Bug Fixes * **php:** Remove abandoned deps ([602338b](https://togithub.com/googleapis/google-cloud-node/commit/602338ba5a448a7fe8b5a8c60dcb68adad39e20e)) </details> <details><summary>mapmanagement: 0.1.0</summary> ## 0.1.0 (2026-06-16) ### Features * Add initial files for google.maps.mapmanagement.v2beta ([#8066](https://togithub.com/googleapis/google-cloud-node/issues/8066)) ([6f9710c](https://togithub.com/googleapis/google-cloud-node/commit/6f9710c504c5272dfb59a77c7da98235ed9cf3ff)) ### Bug Fixes * Change the copyright year for files in the packages folder ([#8109](https://togithub.com/googleapis/google-cloud-node/issues/8109)) ([c1a03fe](https://togithub.com/googleapis/google-cloud-node/commit/c1a03fe604662091be283055c7d34052c64d6334)) </details> --- This PR was generated with [Release Please](https://togithub.com/googleapis/release-please). See [documentation](https://togithub.com/googleapis/release-please#release-please).
During the previous autogeneration run (commit ea7ec63 ), the generator updated its output format to include trailing commas in path template declarations. This formatting change caused the regex in librarian.js to fail silently when trying to match and replace the templates, leaving the v1 client with missing properties and causing runtime crashes when accessing version path helpers. This PR updates librarian.js with a regex that matches both formatting styles and adds verification checks that throw an error and set a non-zero exit code if any replacement fails, preventing silent failures in future generation runs.