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 committish 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
+ }
10
30
11
31
# The parameters of this script is:
12
32
# 1. base_branch, the base branch of the result pull request.
@@ -52,7 +72,7 @@ if [ -z "${generation_config}" ]; then
52
72
fi
53
73
54
74
current_branch=" generate-libraries-${base_branch} "
55
- title=" chore: update googleapis committish at $( date) "
75
+ title=" chore: Update generation configuration at $( date) "
56
76
57
77
# try to find a open pull request associated with the branch
58
78
pr_num=$( gh pr list -s open -H " ${current_branch} " -q . --json number | jq " .[] | .number" )
@@ -72,12 +92,20 @@ git pull
72
92
latest_commit=$( git rev-parse HEAD)
73
93
popd
74
94
rm -rf tmp-googleapis
75
- sed -i -e " s/^googleapis_commitish.*$/googleapis_commitish: ${latest_commit} /" " ${generation_config} "
95
+ update_config " googleapis_commitish" " ${latest_commit} " " ${generation_config} "
96
+
97
+ # update gapic-generator-java version to the latest
98
+ latest_version=$( get_latest_released_version " com.google.api" " gapic-generator-java" )
99
+ update_config " gapic_generator_version" " ${latest_version} " " ${generation_config} "
100
+
101
+ # update libraries-bom version to the latest
102
+ latest_version=$( get_latest_released_version " com.google.cloud" " libraries-bom" )
103
+ update_config " libraries_bom_version" " ${latest_version} " " ${generation_config} "
76
104
77
105
git add " ${generation_config} "
78
106
changed_files=$( git diff --cached --name-only)
79
107
if [[ " ${changed_files} " == " " ]]; then
80
- echo " The latest googleapis commit is not changed."
108
+ echo " The latest generation config is not changed."
81
109
echo " Skip committing to the pull request."
82
110
exit 0
83
111
fi
@@ -89,4 +117,5 @@ if [ -z "${pr_num}" ]; then
89
117
gh pr create --title " ${title} " --head " ${current_branch} " --body " ${title} " --base " ${base_branch} "
90
118
else
91
119
git push
120
+ gh pr edit " ${pr_num} " --title " ${title} " --body " ${title} "
92
121
fi
0 commit comments