xref: /aosp_15_r20/external/google-cloud-java/generation/update_owlbot_postprocessor_config.sh (revision 55e87721aa1bc457b326496a7ca40f3ea1a63287)
1#!/bin/bash
2
3# For each module:
4# Removes and excludes all OwlBot Post-Processor templates (https://github.com/googleapis/synthtool/tree/master/synthtool/gcp/templates/java_library),
5# except for README.md
6
7set -e
8
9for dir in $(find . -mindepth 2 -maxdepth 2 -name owlbot.py | sort | xargs dirname ); do
10  pushd "$dir"
11
12  # form a perl command to replace java.common_templates() invocation
13  perl_command='s/java\.common_templates\(.*\)/java.common_templates(monorepo=True, excludes=['
14  comma=""
15  for exclusion in '.github/*' '.kokoro/*' 'samples/*' 'CODE_OF_CONDUCT.md' 'CONTRIBUTING.md' 'LICENSE' 'SECURITY.md' 'java.header' 'license-checks.xml' 'renovate.json' '.gitignore'; do
16    perl_command+="${comma}\n    $(echo "\"${exclusion}\"" | sed 's/\//\\\//g')"
17    comma=","
18
19    # delete files and directories
20    if [[ ${exclusion: -2} == '/*' && ${exclusion%??} != 'samples' ]]; then
21      rm -rf "${exclusion%??}" || true
22    else
23      rm "${exclusion}" || true
24    fi
25  done
26  perl_command+='\n])/s'
27  # execute the replacement in owlbot.py
28  perl -i -0pe "$perl_command" 'owlbot.py'
29
30  popd
31
32done
33