From ba31a4a51672d1c574ef656ede57e816aefe0689 Mon Sep 17 00:00:00 2001 From: Alice Li Date: Fri, 18 Nov 2022 12:30:43 -0500 Subject: [PATCH] invert grep in script --- generation/set_owlbot_config.sh | 43 ++++++++++++++++----------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/generation/set_owlbot_config.sh b/generation/set_owlbot_config.sh index a7df0da5a3ee..67491ed742fe 100755 --- a/generation/set_owlbot_config.sh +++ b/generation/set_owlbot_config.sh @@ -44,32 +44,31 @@ if grep --quiet 'owl-bot-staging/$1' "${OWLBOT_FILE}"; then fi # This section is specifically around the generated snippet directories -# If snippets are already being copied, exit out -if grep -q samples/snippets/generated ${OWLBOT_FILE}; then - echo "module ${module_name} already copies generated snippets" - exit 1 - fi +# If snippets are already being copied, skip +if ! grep -q samples/snippets/generated ${OWLBOT_FILE}; then + # Insert into `deep-remove-regex:` section + deep_remove_regex="- \"\/${module_name}\/samples\/snippets\/generated\"" + entry_before_deep_remove_regex="${module_name}\/google-.*\/src" + sed -i "/${entry_before_deep_remove_regex}/a ${deep_remove_regex}" ${OWLBOT_FILE} -# Insert into `deep-remove-regex:` section -deep_remove_regex="- \"\/${module_name}\/samples\/snippets\/generated\"" -entry_before_deep_remove_regex="${module_name}\/google-.*\/src" -sed -i "/${entry_before_deep_remove_regex}/a ${deep_remove_regex}" ${OWLBOT_FILE} + # Insert into `deep-copy-regex:` section + proto_path=$(grep -oPm1 '(?<=source: ").*(?=\(v.*\))' "${OWLBOT_FILE}") + deep_copy_regex="- source: \"${proto_path}(v.*)/.*-java/samples/snippets/generated\"\n dest: \"/owl-bot-staging/${module_name}/\$1/samples/snippets/generated\"" -# Insert into `deep-copy-regex:` section -proto_path=$(grep -oPm1 '(?<=source: ").*(?=\(v.*\))' "${OWLBOT_FILE}") -deep_copy_regex="- source: \"${proto_path}(v.*)/.*-java/samples/snippets/generated\"\n dest: \"/owl-bot-staging/${module_name}/\$1/samples/snippets/generated\"" + entry_before_deep_copy_regex="dest: \"\/owl-bot-staging\/${module_name}\/\$1\/google-" -entry_before_deep_copy_regex="dest: \"\/owl-bot-staging\/${module_name}\/\$1\/google-" + # echo ${proto_path} + sed -i "/${entry_before_deep_copy_regex}/a ${deep_copy_regex}" ${OWLBOT_FILE} -# echo ${proto_path} -sed -i "/${entry_before_deep_copy_regex}/a ${deep_copy_regex}" ${OWLBOT_FILE} + # Remove duplicate lines + perl -i -ne 'if ( /^\s*#/ ) { print } else { print if ! $SEEN{$_}++}' ${OWLBOT_FILE} -# Remove duplicate lines -perl -i -ne 'if ( /^\s*#/ ) { print } else { print if ! $SEEN{$_}++}' ${OWLBOT_FILE} + # Add back new lines between sections + sed -i 's/deep-copy-regex/\n&/g' ${OWLBOT_FILE} + sed -i 's/deep-remove-regex/\n&/g' ${OWLBOT_FILE} + sed -i 's/deep-preserve-regex/\n&/g' ${OWLBOT_FILE} + sed -i 's/api-name/\n&/g' ${OWLBOT_FILE} + + fi -# Add back new lines between sections -sed -i 's/deep-copy-regex/\n&/g' ${OWLBOT_FILE} -sed -i 's/deep-remove-regex/\n&/g' ${OWLBOT_FILE} -sed -i 's/deep-preserve-regex/\n&/g' ${OWLBOT_FILE} -sed -i 's/api-name/\n&/g' ${OWLBOT_FILE} \ No newline at end of file