1
1
#! /bin/bash
2
2
set -e
3
3
# This script should be run at the root of the repository.
4
- # This script is used to update googleapis commit to latest in generation
5
- # configuration at the time of running and create a pull request.
4
+ # This script is used to update googleapis_commitish, gapic_generator_version,
5
+ # and libraries_bom_version in generation configuration at the time of running
6
+ # and create a pull request.
6
7
7
8
# The following commands need to be installed before running the script:
8
9
# 1. git
9
10
# 2. gh
11
+ # 3. jq
12
+
13
+ # Utility functions
14
+ # Get the latest released version of a Maven artifact.
15
+ function get_latest_released_version() {
16
+ local group_id=$1
17
+ local artifact_id=$2
18
+ latest=$( curl -s " https://search.maven.org/solrsearch/select?q=g:${group_id} +AND+a:${artifact_id} &core=gav&rows=500&wt=json" | jq -r ' .response.docs[] | select(.v | test("^[0-9]+(\\.[0-9]+)*$")) | .v' | sort -V | tail -n 1)
19
+ echo " ${latest} "
20
+ }
21
+
22
+ # Update a key to a new value in the generation config.
23
+ function update_config() {
24
+ local key_word=$1
25
+ local new_value=$2
26
+ local file=$3
27
+ echo " Update ${key_word} to ${new_value} in ${file} "
28
+ sed -i -e " s/^${key_word} .*$/${key_word} : ${new_value} /" " ${file} "
29
+ }
30
+
31
+ # Update an action to a new version in GitHub action.
32
+ function update_action() {
33
+ local key_word=$1
34
+ local new_value=$2
35
+ local file=$3
36
+ echo " Update ${key_word} to ${new_value} in ${file} "
37
+ # use a different delimiter because the key_word contains "/".
38
+ sed -i -e " s|${key_word} @v.*$|${key_word} @v${new_value} |" " ${file} "
39
+ }
10
40
11
41
# The parameters of this script is:
12
42
# 1. base_branch, the base branch of the result pull request.
13
43
# 2. repo, organization/repo-name, e.g., googleapis/google-cloud-java
14
44
# 3. [optional] generation_config, the path to the generation configuration,
15
45
# the default value is generation_config.yaml in the repository root.
46
+ # 4. [optional] workflow, the library generation workflow file,
47
+ # the default value is .github/workflows/hermetic_library_generation.yaml.
16
48
while [[ $# -gt 0 ]]; do
17
49
key=" $1 "
18
50
case " ${key} " in
@@ -28,6 +60,10 @@ case "${key}" in
28
60
generation_config=" $2 "
29
61
shift
30
62
;;
63
+ --workflow)
64
+ workflow=" $2 "
65
+ shift
66
+ ;;
31
67
* )
32
68
echo " Invalid option: [$1 ]"
33
69
exit 1
@@ -51,8 +87,13 @@ if [ -z "${generation_config}" ]; then
51
87
echo " Use default generation config: ${generation_config} "
52
88
fi
53
89
90
+ if [ -z " ${workflow} " ]; then
91
+ workflow=" .github/workflows/hermetic_library_generation.yaml"
92
+ echo " Use default library generation workflow file: ${workflow} "
93
+ fi
94
+
54
95
current_branch=" generate-libraries-${base_branch} "
55
- title=" chore: update googleapis commit at $( date) "
96
+ title=" chore: Update generation configuration at $( date) "
56
97
57
98
git checkout " ${base_branch} "
58
99
# Try to find a open pull request associated with the branch
@@ -80,12 +121,25 @@ git pull
80
121
latest_commit=$( git rev-parse HEAD)
81
122
popd
82
123
rm -rf tmp-googleapis
83
- sed -i -e " s/^googleapis_commitish.*$/googleapis_commitish: ${latest_commit} /" " ${generation_config} "
124
+ update_config " googleapis_commitish" " ${latest_commit} " " ${generation_config} "
125
+
126
+ # Update gapic-generator-java version to the latest
127
+ latest_version=$( get_latest_released_version " com.google.api" " gapic-generator-java" )
128
+ update_config " gapic_generator_version" " ${latest_version} " " ${generation_config} "
129
+
130
+ # Update composite action version to latest gapic-generator-java version
131
+ update_action " googleapis/sdk-platform-java/.github/scripts" \
132
+ " ${latest_version} " \
133
+ " ${workflow} "
134
+
135
+ # Update libraries-bom version to the latest
136
+ latest_version=$( get_latest_released_version " com.google.cloud" " libraries-bom" )
137
+ update_config " libraries_bom_version" " ${latest_version} " " ${generation_config} "
84
138
85
- git add " ${generation_config} "
139
+ git add " ${generation_config} " " ${workflow} "
86
140
changed_files=$( git diff --cached --name-only)
87
141
if [[ " ${changed_files} " == " " ]]; then
88
- echo " The latest googleapis commit is not changed."
142
+ echo " The latest generation config is not changed."
89
143
echo " Skip committing to the pull request."
90
144
else
91
145
git commit -m " ${title} "
@@ -110,4 +164,5 @@ if [ -z "${pr_num}" ]; then
110
164
gh pr create --title " ${title} " --head " ${current_branch} " --body " ${title} " --base " ${base_branch} "
111
165
else
112
166
git push
167
+ gh pr edit " ${pr_num} " --title " ${title} " --body " ${title} "
113
168
fi
0 commit comments