@@ -17,14 +17,11 @@ set -e
1717# 1. git
1818# 2. gh
1919# 3. docker
20- # 4. mvn
2120
2221# The parameters of this script is:
2322# 1. target_branch, the branch into which the pull request is merged.
2423# 2. current_branch, the branch with which the pull request is associated.
25- # 3. [optional] image_tag, the tag of gcr.io/cloud-devrel-public-resources/java-library-generation.
26- # The value will be parsed from the generation configuration if not specified.
27- # 4. [optional] generation_config, the path to the generation configuration,
24+ # 3. [optional] generation_config, the path to the generation configuration,
2825# the default value is generation_config.yaml in the repository root.
2926while [[ $# -gt 0 ]]; do
3027key=" $1 "
@@ -37,10 +34,6 @@ case "${key}" in
3734 current_branch=" $2 "
3835 shift
3936 ;;
40- --image_tag)
41- image_tag=" $2 "
42- shift
43- ;;
4437 --generation_config)
4538 generation_config=" $2 "
4639 shift
@@ -54,22 +47,18 @@ shift
5447done
5548
5649if [ -z " ${target_branch} " ]; then
57- echo " missing required argument --target_branch"
50+ echo " Missing required argument --target_branch"
5851 exit 1
5952fi
6053
6154if [ -z " ${current_branch} " ]; then
62- echo " missing required argument --current_branch"
55+ echo " Missing required argument --current_branch"
6356 exit 1
6457fi
6558
6659if [ -z " ${generation_config} " ]; then
6760 generation_config=generation_config.yaml
68- echo " Use default generation config: ${generation_config} "
69- fi
70-
71- if [ -z " ${image_tag} " ]; then
72- image_tag=$( grep " gapic_generator_version" " ${generation_config} " | cut -d ' :' -f 2 | xargs)
61+ echo " Using default generation config: ${generation_config} "
7362fi
7463
7564workspace_name=" /workspace"
@@ -85,10 +74,14 @@ if [[ ! ("${change_of_last_commit}" == *"${generation_config}"*) ]]; then
8574 echo " The last commit doesn't contain any changes to the generation_config.yaml, skipping the whole generation process." || true
8675 exit 0
8776fi
77+
8878# copy generation configuration from target branch to current branch.
8979git show " ${target_branch} " :" ${generation_config} " > " ${baseline_generation_config} "
9080config_diff=$( diff " ${generation_config} " " ${baseline_generation_config} " || true)
9181
82+ # parse image tag from the generation configuration.
83+ image_tag=$( grep " gapic_generator_version" " ${generation_config} " | cut -d ' :' -f 2 | xargs)
84+
9285# get .m2 folder so it's mapped into the docker container
9386m2_folder=$( dirname " $( mvn help:evaluate -Dexpression=settings.localRepository -q -DforceStdout) " )
9487
@@ -101,8 +94,15 @@ docker run \
10194 gcr.io/cloud-devrel-public-resources/java-library-generation:" ${image_tag} " \
10295 --baseline-generation-config-path=" ${workspace_name} /${baseline_generation_config} " \
10396 --current-generation-config-path=" ${workspace_name} /${generation_config} "
97+
10498# commit the change to the pull request.
105- git add java-* pom.xml gapic-libraries-bom/pom.xml versions.txt
99+ if [[ $( basename " $( pwd) " ) == " google-cloud-java" ]]; then
100+ git add java-* pom.xml gapic-libraries-bom/pom.xml versions.txt
101+ else
102+ # The image leaves intermediate folders and files it works with. Here we remove them
103+ rm -rdf output googleapis " ${baseline_generation_config} "
104+ git add --all -- ' :!pr_description.txt'
105+ fi
106106changed_files=$( git diff --cached --name-only)
107107if [[ " ${changed_files} " == " " ]]; then
108108 echo " There is no generated code change with the generation config change ${config_diff} ."
@@ -118,4 +118,4 @@ git push
118118if [[ -f " pr_description.txt" ]]; then
119119 pr_num=$( gh pr list -s open -H " ${current_branch} " -q . --json number | jq " .[] | .number" )
120120 gh pr edit " ${pr_num} " --body " $( cat pr_description.txt) "
121- fi
121+ fi
0 commit comments