2
2
set -e
3
3
# This script should be run at the root of the repository.
4
4
# This script is used to, when a pull request changes the generation
5
- # configuration (generation_config.yaml by default):
5
+ # configuration (generation_config.yaml by default) or Dockerfile :
6
6
# 1. Find whether the last commit in this pull request contains changes to
7
- # the generation configuration and exit early if it doesn't have such a change
8
- # since the generation result would be the same.
7
+ # the generation configuration and Dockerfile and exit early if it doesn't have
8
+ # such a change since the generation result would be the same.
9
9
# 2. Compare generation configurations in the current branch (with which the
10
10
# pull request associated) and target branch (into which the pull request is
11
11
# merged);
17
17
# 1. git
18
18
# 2. gh
19
19
# 3. docker
20
+ # 4. mvn
20
21
21
22
# The parameters of this script is:
22
23
# 1. target_branch, the branch into which the pull request is merged.
73
74
74
75
workspace_name=" /workspace"
75
76
baseline_generation_config=" baseline_generation_config.yaml"
77
+ docker_file=" library_generation.Dockerfile"
76
78
message=" chore: generate libraries at $( date) "
77
79
78
80
git checkout " ${target_branch} "
79
81
git checkout " ${current_branch} "
80
82
# if the last commit doesn't contain changes to generation configuration,
81
83
# do not generate again as the result will be the same.
82
84
change_of_last_commit=" $( git diff-tree --no-commit-id --name-only HEAD~1..HEAD -r) "
83
- if [[ ! (" ${change_of_last_commit} " == * " ${generation_config} " * ) ]]; then
84
- echo " The last commit doesn't contain any changes to the generation_config.yaml, skipping the whole generation process." || true
85
+ if [[ ! (" ${change_of_last_commit} " == * " ${generation_config} " * || " ${change_of_last_commit} " == * " ${docker_file} " * ) ]]; then
86
+ echo " The last commit doesn't contain any changes to the generation_config.yaml or Dockerfile , skipping the whole generation process." || true
85
87
exit 0
86
88
fi
87
89
# copy generation configuration from target branch to current branch.
88
90
git show " ${target_branch} " :" ${generation_config} " > " ${baseline_generation_config} "
89
91
config_diff=$( diff " ${generation_config} " " ${baseline_generation_config} " || true)
90
92
93
+ # install generator locally since we're using a SNAPSHOT version.
94
+ mvn -V -B -ntp clean install -DskipTests
95
+
96
+ # build image locally since we want to include latest change.
97
+ docker build \
98
+ -f .cloudbuild/library_generation/library_generation.Dockerfile \
99
+ -t gcr.io/cloud-devrel-public-resources/java-library-generation:" ${image_tag} " \
100
+ .
91
101
# run hermetic code generation docker image.
92
102
docker run \
93
103
--rm \
@@ -103,7 +113,7 @@ rm -rdf output googleapis "${baseline_generation_config}"
103
113
git add --all -- ' :!pr_description.txt'
104
114
changed_files=$( git diff --cached --name-only)
105
115
if [[ " ${changed_files} " == " " ]]; then
106
- echo " There is no generated code change with the generation config change ${config_diff} ."
116
+ echo " There is no generated code change with the generation config and Dockerfile change ${config_diff} ."
107
117
echo " Skip committing to the pull request."
108
118
exit 0
109
119
fi
0 commit comments