15
15
16
16
set -e
17
17
18
- # templates
19
- echo " Generating templates..."
20
- /owlbot/bin/write_templates.sh
21
- echo " ...done"
22
-
23
- # write or restore pom.xml files
24
- echo " Generating missing pom.xml..."
25
- /owlbot/bin/write_missing_pom_files.sh
26
- echo " ...done"
27
-
28
- # write or restore clirr-ignored-differences.xml
29
- echo " Generating clirr-ignored-differences.xml..."
30
- /owlbot/bin/write_clirr_ignore.sh
31
- echo " ...done"
32
-
33
- # fix license headers
34
- echo " Fixing missing license headers..."
35
- /owlbot/bin/fix_license_headers.sh
36
- echo " ...done"
37
-
38
- # TODO: re-enable this once we resolve thrashing
39
- # restore license headers years
40
- # echo "Restoring copyright years..."
41
- # /owlbot/bin/restore_license_headers.sh
42
- # echo "...done"
43
-
44
- # ensure formatting on all .java files in the repository
45
- echo " Reformatting source..."
46
- /owlbot/bin/format_source.sh
47
- echo " ...done"
18
+ # Runs template and etc in current working directory
19
+ function processModule() {
20
+ # templates
21
+ echo " Generating templates..."
22
+ /owlbot/bin/write_templates.sh
23
+ echo " ...done"
24
+
25
+ # write or restore pom.xml files
26
+ echo " Generating missing pom.xml..."
27
+ /owlbot/bin/write_missing_pom_files.sh
28
+ echo " ...done"
29
+
30
+ # write or restore clirr-ignored-differences.xml
31
+ echo " Generating clirr-ignored-differences.xml..."
32
+ /owlbot/bin/write_clirr_ignore.sh
33
+ echo " ...done"
34
+
35
+ # fix license headers
36
+ echo " Fixing missing license headers..."
37
+ /owlbot/bin/fix_license_headers.sh
38
+ echo " ...done"
39
+
40
+ # TODO: re-enable this once we resolve thrashing
41
+ # restore license headers years
42
+ # echo "Restoring copyright years..."
43
+ # /owlbot/bin/restore_license_headers.sh
44
+ # echo "...done"
45
+
46
+ # ensure formatting on all .java files in the repository
47
+ echo " Reformatting source..."
48
+ /owlbot/bin/format_source.sh
49
+ echo " ...done"
50
+ }
51
+
52
+ if [ " $( ls * /.OwlBot.yaml| wc -l) " -gt 1 ]; then
53
+ # Monorepo (googleapis/google-cloud-java) has multiple OwlBot.yaml config
54
+ # files in the modules.
55
+ echo " Processing monorepo"
56
+ if [ -d owl-bot-staging ]; then
57
+ # The content of owl-bot-staging is controlled by Owlbot.yaml files in
58
+ # each module in the monorepo
59
+ echo " Extracting contents from owl-bot-staging"
60
+ for module in $( ls owl-bot-staging) ; do
61
+ if [ ! -d " $module " ]; then
62
+ continue
63
+ fi
64
+ # This relocation allows us continue to use owlbot.py without modification
65
+ # after monorepo migration.
66
+ mv " owl-bot-staging/$module " " $module /owl-bot-staging"
67
+ pushd " $module "
68
+ processModule
69
+ popd
70
+ done
71
+ rm -r owl-bot-staging
72
+ else
73
+ echo " In monorepo but no owl-bot-staging." \
74
+ " Formatting changes in the last commit"
75
+ # Find the files that were touched by the last commit.
76
+ last_commit=$( git log -1 --format=%H)
77
+ # [A]dded, [C]reated, [M]odified, and [R]enamed
78
+ changed_files=$( git show --name-only --no-renames --diff-filter=ACMR \
79
+ " ${last_commit} " )
80
+ changed_modules=$( echo " $changed_files " | grep -E ' .java$' | cut -d ' /' -f 1 \
81
+ | sort -u)
82
+ for module in ${changed_modules} ; do
83
+ if [ ! -f " $module /.OwlBot.yaml" ]; then
84
+ # Changes irrelevant to Owlbot-generated module (such as .github) do not
85
+ # need formatting
86
+ continue
87
+ fi
88
+ pushd " $module "
89
+ processModule
90
+ popd
91
+ done
92
+ fi
93
+ else
94
+ # Split repository
95
+ echo " Processing a split repo"
96
+ processModule
97
+ fi
0 commit comments