Skip to content

Commit 4c7fd88

Browse files
fix: correct deep-remove and deep-preserve regexes (#2572)
In this PR we fix the `deep-remove` and `deep-preserve` regexes in `.OwlBot.yaml` files in the monorepo by creating a temporary `.OwlBot.hermetic.yaml` with the corrected paths. ### Why? Because the paths specified in `deep-remove-regex` and `deep-preserve-regex` [start from the library name](https://github.com/googleapis/google-cloud-java/blob/14f7146c98fdf03de2f113215e03347a21e83f9a/java-alloydb/.OwlBot.yaml#L17), so if we run `copy-code` from inside a library, these regexes won't match any files. ### What about deep-copy? We don't need to correct the library path because `copy-code` sends the files from `googleapis-gen` (or our built temp folder in our case) to the `owl-bot-staging` folder. These regexes don't deal with the monorepo, they deal with the source repo, which for our case is the temp folder we build after calling generate_library. This is why `deep-copy` was always being "respected". ### Proof After running `python generate_repo.py generate --generation-config-yaml google-cloud-java/generation_config.yaml --repository-path google-cloud-java --target-library-api-shortname merchantapi &> out`, we get ![image](https://github.com/googleapis/sdk-platform-java/assets/22083784/087e0df1-baf3-4939-94e0-61027797d19e) --------- Co-authored-by: Joe Wang <[email protected]>
1 parent 993f5ac commit 4c7fd88

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

library_generation/postprocess_library.sh

+21-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,22 @@ fi
6262
# we determine the location of the .OwlBot.yaml file by checking if the target
6363
# folder is a monorepo folder or not
6464
if [[ "${is_monorepo}" == "true" ]]; then
65-
owlbot_yaml_relative_path=".OwlBot.yaml"
65+
# the deep-remove-regex and deep-preserve-regex of the .OwlBot.yaml
66+
# files in the monorepo libraries assume that `copy-code` is run
67+
# from the root of the monorepo. However, we call `copy-code` from inside each
68+
# library, so a path like `/java-asset/google-.*/src` will not have
69+
# any effect. We solve this by creating a temporary owlbot yaml with
70+
# the patched paths.
71+
# For example, we convert
72+
# - "/java-asset/google-.*/src"
73+
# to
74+
# - "/google-.*/src"
75+
76+
library_name=$(basename "${postprocessing_target}")
77+
cat "${postprocessing_target}/.OwlBot.yaml" \
78+
| sed "s/- \"\/${library_name}/ - \"/" \
79+
> "${postprocessing_target}/.OwlBot.hermetic.yaml"
80+
owlbot_yaml_relative_path=".OwlBot.hermetic.yaml"
6681
else
6782
owlbot_yaml_relative_path=".github/.OwlBot.yaml"
6883
fi
@@ -109,6 +124,11 @@ docker run --rm \
109124
--source-repo="${preprocessed_libraries_binding}" \
110125
--config-file="${owlbot_yaml_relative_path}"
111126

127+
# clean the custom owlbot yaml
128+
if [[ "${is_monorepo}" == "true" ]]; then
129+
rm "${postprocessing_target}/.OwlBot.hermetic.yaml"
130+
fi
131+
112132
# we clone the synthtool library and manually build it
113133
mkdir -p /tmp/synthtool
114134
pushd /tmp/synthtool

0 commit comments

Comments
 (0)