|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Adds module directory name into the paths in a OwlBot configuration file so |
| 4 | +# that the paths correctly reference the files under the modules in this monorepo. |
| 5 | +# |
| 6 | +# Usage: |
| 7 | +# set_owlbot_config.sh <.OwlBot.yaml path from the root> |
| 8 | +# Example: |
| 9 | +# $ set_owlbot_config.sh java-dataform/.OwlBot.yaml |
| 10 | +# |
| 11 | +# To apply the change to all OwlBot configuration files in all modules: |
| 12 | +# $ for F in `find . -maxdepth 2 -name '.OwlBot.yaml'`; do sh generation/set_owlbot_config.sh $F; done |
| 13 | +OWLBOT_FILE=$1 |
| 14 | + |
| 15 | +if [ -z "${OWLBOT_FILE}" ]; then |
| 16 | + echo "Please specify file name" |
| 17 | + exit 1 |
| 18 | +fi |
| 19 | + |
| 20 | +if [ ! -r "${OWLBOT_FILE}" ]; then |
| 21 | + echo "File not found" |
| 22 | + exit 1 |
| 23 | +fi |
| 24 | + |
| 25 | +dir_name=$(dirname "${OWLBOT_FILE}") |
| 26 | +module_name=$(basename "${dir_name}") |
| 27 | + |
| 28 | +if [ ! -d "${module_name}" ]; then |
| 29 | + echo "module ${module_name} does not exist" |
| 30 | + exit 1 |
| 31 | +fi |
| 32 | + |
| 33 | +# For deep-remove-regex and deep-preserve-regex fields |
| 34 | +sed -i "s|\"/grpc-google|\"/${module_name}/grpc-google|" "${OWLBOT_FILE}" |
| 35 | +sed -i "s|\"/proto-google|\"/${module_name}/proto-google|" "${OWLBOT_FILE}" |
| 36 | +sed -i "s|\"/google-\.\*|\"/${module_name}/google-.*|" "${OWLBOT_FILE}" |
| 37 | +sed -i "s|\"/google-cloud|\"/${module_name}/google-cloud|" "${OWLBOT_FILE}" |
| 38 | +sed -i "s|\"/samples|\"/${module_name}/samples|" "${OWLBOT_FILE}" |
| 39 | + |
| 40 | +# In monorepo, the staging directory structure tells the destination module to |
| 41 | +# which the OwlBot Java postprocessor copies the files. |
| 42 | +if grep --quiet 'owl-bot-staging/$1' "${OWLBOT_FILE}"; then |
| 43 | + sed -i "s|owl-bot-staging|owl-bot-staging/${module_name}|" "${OWLBOT_FILE}" |
| 44 | +fi |