Skip to content

Commit e65bfeb

Browse files
JoeWang1127lqiu96
authored andcommitted
chore: update action version in shell script (#11333)
* chore: update action version in shell script * update renovate * add workflow
1 parent ab51154 commit e65bfeb

File tree

2 files changed

+34
-10
lines changed

2 files changed

+34
-10
lines changed

.github/scripts/update_generation_config.sh

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
3648
while [[ $# -gt 0 ]]; do
3749
key="$1"
3850
case "${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}"
7288
fi
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+
7495
current_branch="generate-libraries-${base_branch}"
7596
title="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
7899
pr_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.
81102
if [ -z "${pr_num}" ]; then
82103
git checkout -b "${current_branch}"
@@ -85,7 +106,7 @@ else
85106
fi
86107

87108
mkdir tmp-googleapis
88-
# use partial clone because only commit history is needed.
109+
# Use partial clone because only commit history is needed.
89110
git clone --filter=blob:none https://github.com/googleapis/googleapis.git tmp-googleapis
90111
pushd tmp-googleapis
91112
git pull
@@ -94,15 +115,20 @@ popd
94115
rm -rf tmp-googleapis
95116
update_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
98119
latest_version=$(get_latest_released_version "com.google.api" "gapic-generator-java")
99120
update_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
102128
latest_version=$(get_latest_released_version "com.google.cloud" "libraries-bom")
103129
update_config "libraries_bom_version" "${latest_version}" "${generation_config}"
104130

105-
git add "${generation_config}"
131+
git add "${generation_config}" "${workflow}"
106132
changed_files=$(git diff --cached --name-only)
107133
if [[ "${changed_files}" == "" ]]; then
108134
echo "The latest generation config is not changed."

renovate.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,10 @@
6565
{
6666
"fileMatch": [
6767
".github/workflows/ci.yaml",
68-
".github/workflows/generated_files_sync.yaml",
69-
".github/workflows/hermetic_library_generation.yaml"
68+
".github/workflows/generated_files_sync.yaml"
7069
],
7170
"matchStrings": [
72-
"library_generation_image_tag\\s*:\\s*(?<currentValue>.*?)\\n",
73-
"uses: googleapis/sdk-platform-java/.github/scripts@v(?<currentValue>.+?)\\n"
71+
"library_generation_image_tag\\s*:\\s*(?<currentValue>.*?)\\n"
7472
],
7573
"depNameTemplate": "com.google.api:gapic-generator-java",
7674
"datasourceTemplate": "maven"

0 commit comments

Comments
 (0)