From 48f8857c642792150e2474418b1dbf545c162f8d Mon Sep 17 00:00:00 2001 From: Tomo Suzuki Date: Tue, 26 Jul 2022 12:23:37 -0400 Subject: [PATCH] ci: adjust owlbot-java for monorepo (#1500) --- docker/owlbot/java/bin/entrypoint.sh | 110 +++++++++++++++++++-------- 1 file changed, 80 insertions(+), 30 deletions(-) diff --git a/docker/owlbot/java/bin/entrypoint.sh b/docker/owlbot/java/bin/entrypoint.sh index 717e8f0cb..a3721cc75 100755 --- a/docker/owlbot/java/bin/entrypoint.sh +++ b/docker/owlbot/java/bin/entrypoint.sh @@ -15,33 +15,83 @@ set -e -# templates -echo "Generating templates..." -/owlbot/bin/write_templates.sh -echo "...done" - -# write or restore pom.xml files -echo "Generating missing pom.xml..." -/owlbot/bin/write_missing_pom_files.sh -echo "...done" - -# write or restore clirr-ignored-differences.xml -echo "Generating clirr-ignored-differences.xml..." -/owlbot/bin/write_clirr_ignore.sh -echo "...done" - -# fix license headers -echo "Fixing missing license headers..." -/owlbot/bin/fix_license_headers.sh -echo "...done" - -# TODO: re-enable this once we resolve thrashing -# restore license headers years -# echo "Restoring copyright years..." -# /owlbot/bin/restore_license_headers.sh -# echo "...done" - -# ensure formatting on all .java files in the repository -echo "Reformatting source..." -/owlbot/bin/format_source.sh -echo "...done" +# Runs template and etc in current working directory +function processModule() { + # templates + echo "Generating templates..." + /owlbot/bin/write_templates.sh + echo "...done" + + # write or restore pom.xml files + echo "Generating missing pom.xml..." + /owlbot/bin/write_missing_pom_files.sh + echo "...done" + + # write or restore clirr-ignored-differences.xml + echo "Generating clirr-ignored-differences.xml..." + /owlbot/bin/write_clirr_ignore.sh + echo "...done" + + # fix license headers + echo "Fixing missing license headers..." + /owlbot/bin/fix_license_headers.sh + echo "...done" + + # TODO: re-enable this once we resolve thrashing + # restore license headers years + # echo "Restoring copyright years..." + # /owlbot/bin/restore_license_headers.sh + # echo "...done" + + # ensure formatting on all .java files in the repository + echo "Reformatting source..." + /owlbot/bin/format_source.sh + echo "...done" +} + +if [ "$(ls */.OwlBot.yaml|wc -l)" -gt 1 ];then + # Monorepo (googleapis/google-cloud-java) has multiple OwlBot.yaml config + # files in the modules. + echo "Processing monorepo" + if [ -d owl-bot-staging ]; then + # The content of owl-bot-staging is controlled by Owlbot.yaml files in + # each module in the monorepo + echo "Extracting contents from owl-bot-staging" + for module in $(ls owl-bot-staging); do + if [ ! -d "$module" ]; then + continue + fi + # This relocation allows us continue to use owlbot.py without modification + # after monorepo migration. + mv "owl-bot-staging/$module" "$module/owl-bot-staging" + pushd "$module" + processModule + popd + done + rm -r owl-bot-staging + else + echo "In monorepo but no owl-bot-staging." \ + "Formatting changes in the last commit" + # Find the files that were touched by the last commit. + last_commit=$(git log -1 --format=%H) + # [A]dded, [C]reated, [M]odified, and [R]enamed + changed_files=$(git show --name-only --no-renames --diff-filter=ACMR \ + "${last_commit}") + changed_modules=$(echo "$changed_files" |grep -E '.java$' |cut -d '/' -f 1 \ + |sort -u) + for module in ${changed_modules}; do + if [ ! -f "$module/.OwlBot.yaml" ]; then + # Changes irrelevant to Owlbot-generated module (such as .github) do not + # need formatting + continue + fi + pushd "$module" + processModule + popd + done + fi +else + # Split repository + echo "Processing a split repo" + processModule +fi \ No newline at end of file