@@ -28,11 +28,23 @@ function update_config() {
2828 sed -i -e " s/^${key_word} .*$/${key_word} : ${new_value} /" " ${file} "
2929}
3030
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+ }
40+
3141# The parameters of this script is:
3242# 1. base_branch, the base branch of the result pull request.
3343# 2. repo, organization/repo-name, e.g., googleapis/google-cloud-java
3444# 3. [optional] generation_config, the path to the generation configuration,
3545# 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.
3648while [[ $# -gt 0 ]]; do
3749key=" $1 "
3850case " ${key} " in
@@ -48,6 +60,10 @@ case "${key}" in
4860 generation_config=" $2 "
4961 shift
5062 ;;
63+ --workflow)
64+ workflow=" $2 "
65+ shift
66+ ;;
5167 * )
5268 echo " Invalid option: [$1 ]"
5369 exit 1
@@ -71,12 +87,17 @@ if [ -z "${generation_config}" ]; then
7187 echo " Use default generation config: ${generation_config} "
7288fi
7389
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+
7495current_branch=" generate-libraries-${base_branch} "
7596title=" chore: Update generation configuration at $( date) "
7697
77- # try to find a open pull request associated with the branch
98+ # Try to find a open pull request associated with the branch
7899pr_num=$( gh pr list -s open -H " ${current_branch} " -q . --json number | jq " .[] | .number" )
79- # create a branch if there's no open pull request associated with the
100+ # Create a branch if there's no open pull request associated with the
80101# branch; otherwise checkout the pull request.
81102if [ -z " ${pr_num} " ]; then
82103 git checkout -b " ${current_branch} "
85106fi
86107
87108mkdir tmp-googleapis
88- # use partial clone because only commit history is needed.
109+ # Use partial clone because only commit history is needed.
89110git clone --filter=blob:none https://github.com/googleapis/googleapis.git tmp-googleapis
90111pushd tmp-googleapis
91112git pull
@@ -94,15 +115,20 @@ popd
94115rm -rf tmp-googleapis
95116update_config " googleapis_commitish" " ${latest_commit} " " ${generation_config} "
96117
97- # update gapic-generator-java version to the latest
118+ # Update gapic-generator-java version to the latest
98119latest_version=$( get_latest_released_version " com.google.api" " gapic-generator-java" )
99120update_config " gapic_generator_version" " ${latest_version} " " ${generation_config} "
100121
101- # update libraries-bom version to the latest
122+ # Update composite action version to latest gapic-generator-java version
123+ update_action " googleapis/sdk-platform-java/.github/scripts" \
124+ " ${latest_version} " \
125+ " ${workflow} "
126+
127+ # Update libraries-bom version to the latest
102128latest_version=$( get_latest_released_version " com.google.cloud" " libraries-bom" )
103129update_config " libraries_bom_version" " ${latest_version} " " ${generation_config} "
104130
105- git add " ${generation_config} "
131+ git add " ${generation_config} " " ${workflow} "
106132changed_files=$( git diff --cached --name-only)
107133if [[ " ${changed_files} " == " " ]]; then
108134 echo " The latest generation config is not changed."
0 commit comments