Skip to content

Commit 9ead407

Browse files
committed
invert grep in script
1 parent 7291fd3 commit 9ead407

1 file changed

Lines changed: 21 additions & 22 deletions

File tree

generation/set_owlbot_config.sh

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -44,32 +44,31 @@ if grep --quiet 'owl-bot-staging/$1' "${OWLBOT_FILE}"; then
4444
fi
4545

4646
# This section is specifically around the generated snippet directories
47-
# If snippets are already being copied, exit out
48-
if grep -q samples/snippets/generated ${OWLBOT_FILE}; then
49-
echo "module ${module_name} already copies generated snippets"
50-
exit 1
51-
fi
47+
# If snippets are already being copied, skip
48+
if ! grep -q samples/snippets/generated ${OWLBOT_FILE}; then
49+
# Insert into `deep-remove-regex:` section
50+
deep_remove_regex="- \"\/${module_name}\/samples\/snippets\/generated\""
51+
entry_before_deep_remove_regex="${module_name}\/google-.*\/src"
52+
sed -i "/${entry_before_deep_remove_regex}/a ${deep_remove_regex}" ${OWLBOT_FILE}
5253

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 "/${entry_before_deep_remove_regex}/a ${deep_remove_regex}" ${OWLBOT_FILE}
5754

55+
# Insert into `deep-copy-regex:` section
56+
proto_path=$(grep -oPm1 '(?<=source: ").*(?=\(v.*\))' "${OWLBOT_FILE}")
57+
deep_copy_regex="- source: \"${proto_path}(v.*)/.*-java/samples/snippets/generated\"\n dest: \"/owl-bot-staging/${module_name}/\$1/samples/snippets/generated\""
5858

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\""
59+
entry_before_deep_copy_regex="dest: \"\/owl-bot-staging\/${module_name}\/\$1\/google-"
6260

63-
entry_before_deep_copy_regex="dest: \"\/owl-bot-staging\/${module_name}\/\$1\/google-"
61+
# echo ${proto_path}
62+
sed -i "/${entry_before_deep_copy_regex}/a ${deep_copy_regex}" ${OWLBOT_FILE}
6463

65-
# echo ${proto_path}
66-
sed -i "/${entry_before_deep_copy_regex}/a ${deep_copy_regex}" ${OWLBOT_FILE}
64+
# Remove duplicate lines
65+
perl -i -ne 'if ( /^\s*#/ ) { print } else { print if ! $SEEN{$_}++}' ${OWLBOT_FILE}
6766

68-
# Remove duplicate lines
69-
perl -i -ne 'if ( /^\s*#/ ) { print } else { print if ! $SEEN{$_}++}' ${OWLBOT_FILE}
67+
# Add back new lines between sections
68+
sed -i 's/deep-copy-regex/\n&/g' ${OWLBOT_FILE}
69+
sed -i 's/deep-remove-regex/\n&/g' ${OWLBOT_FILE}
70+
sed -i 's/deep-preserve-regex/\n&/g' ${OWLBOT_FILE}
71+
sed -i 's/api-name/\n&/g' ${OWLBOT_FILE}
72+
73+
fi
7074

71-
# Add back new lines between sections
72-
sed -i 's/deep-copy-regex/\n&/g' ${OWLBOT_FILE}
73-
sed -i 's/deep-remove-regex/\n&/g' ${OWLBOT_FILE}
74-
sed -i 's/deep-preserve-regex/\n&/g' ${OWLBOT_FILE}
75-
sed -i 's/api-name/\n&/g' ${OWLBOT_FILE}

0 commit comments

Comments
 (0)