|
10 | 10 | # |
11 | 11 | # To apply the change to all OwlBot configuration files in all modules: |
12 | 12 | # $ for F in `find . -maxdepth 2 -name '.OwlBot.yaml'`; do sh generation/set_owlbot_config.sh $F; done |
13 | | -OWLBOT_FILE=$1 |
| 13 | + |
| 14 | +for F in `find . -maxdepth 2 -name '.OwlBot.yaml'`; |
| 15 | +do |
| 16 | + |
| 17 | +OWLBOT_FILE=$F |
14 | 18 |
|
15 | 19 | if [ -z "${OWLBOT_FILE}" ]; then |
16 | 20 | echo "Please specify file name" |
@@ -42,3 +46,34 @@ sed -i.bak "s|\"/samples|\"/${module_name}/samples|" "${OWLBOT_FILE}" && rm "${O |
42 | 46 | if grep --quiet 'owl-bot-staging/$1' "${OWLBOT_FILE}"; then |
43 | 47 | sed -i.bak "s|owl-bot-staging|owl-bot-staging/${module_name}|" "${OWLBOT_FILE}" && rm "${OWLBOT_FILE}".bak |
44 | 48 | fi |
| 49 | + |
| 50 | +# This section is specifically around the generated snippet directories |
| 51 | +# If snippets are already being copied, skip |
| 52 | +if ! grep -q samples/snippets/generated ${OWLBOT_FILE}; then |
| 53 | +# Insert into `deep-remove-regex:` section |
| 54 | +deep_remove_regex="- \"\/${module_name}\/samples\/snippets\/generated\"" |
| 55 | +entry_before_deep_remove_regex="${module_name}\/google-.*\/src" |
| 56 | +sed -i.bak "/${entry_before_deep_remove_regex}/a ${deep_remove_regex}" ${OWLBOT_FILE} && rm "${OWLBOT_FILE}".bak |
| 57 | + |
| 58 | + |
| 59 | +# Insert into `deep-copy-regex:` section |
| 60 | +proto_path=$(grep -oPm1 '(?<=source: ").*(?=\(v.*\))' "${OWLBOT_FILE}") |
| 61 | +deep_copy_regex="- source: \"${proto_path}(v.*)/.*-java/samples/snippets/generated\"\n dest: \"/owl-bot-staging/${module_name}/\$1/samples/snippets/generated\"" |
| 62 | + |
| 63 | +entry_before_deep_copy_regex="dest: \"\/owl-bot-staging\/${module_name}\/\$1\/google-" |
| 64 | + |
| 65 | +# echo ${proto_path} |
| 66 | +sed -i.bak "/${entry_before_deep_copy_regex}/a ${deep_copy_regex}" ${OWLBOT_FILE} && rm "${OWLBOT_FILE}".bak |
| 67 | + |
| 68 | +# Remove duplicate lines |
| 69 | +perl -i -ne 'if ( /^\s*#/ ) { print } else { print if ! $SEEN{$_}++}' ${OWLBOT_FILE} |
| 70 | + |
| 71 | +# Add back new lines between sections |
| 72 | +sed -i.bak 's/deep-copy-regex/\n&/g' ${OWLBOT_FILE} && rm "${OWLBOT_FILE}".bak |
| 73 | +sed -i.bak 's/deep-remove-regex/\n&/g' ${OWLBOT_FILE} && rm "${OWLBOT_FILE}".bak |
| 74 | +sed -i.bak 's/deep-preserve-regex/\n&/g' ${OWLBOT_FILE} && rm "${OWLBOT_FILE}".bak |
| 75 | +sed -i.bak 's/api-name/\n&/g' ${OWLBOT_FILE} && rm "${OWLBOT_FILE}".bak |
| 76 | + |
| 77 | +fi |
| 78 | + |
| 79 | +done |
0 commit comments