Skip to content

Commit

Permalink
invert grep in script
Browse files Browse the repository at this point in the history
  • Loading branch information
alicejli committed Nov 28, 2022
1 parent a304a7a commit ba31a4a
Showing 1 changed file with 21 additions and 22 deletions.
43 changes: 21 additions & 22 deletions generation/set_owlbot_config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}

0 comments on commit ba31a4a

Please sign in to comment.