Skip to content

Commit 6887de3

Browse files
committed
update config scripts and yamls
1 parent b1229b9 commit 6887de3

File tree

3 files changed

+76
-5
lines changed

3 files changed

+76
-5
lines changed
File renamed without changes.

generation/update_googleapis_committish.sh renamed to .github/scripts/update_generation_config.sh

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,32 @@
11
#!/bin/bash
22
set -e
33
# 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.
67

78
# The following commands need to be installed before running the script:
89
# 1. git
910
# 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+
}
1030

1131
# The parameters of this script is:
1232
# 1. base_branch, the base branch of the result pull request.
@@ -52,7 +72,7 @@ if [ -z "${generation_config}" ]; then
5272
fi
5373

5474
current_branch="generate-libraries-${base_branch}"
55-
title="chore: update googleapis committish at $(date)"
75+
title="chore: Update generation configuration at $(date)"
5676

5777
# try to find a open pull request associated with the branch
5878
pr_num=$(gh pr list -s open -H "${current_branch}" -q . --json number | jq ".[] | .number")
@@ -72,12 +92,20 @@ git pull
7292
latest_commit=$(git rev-parse HEAD)
7393
popd
7494
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}"
76104

77105
git add "${generation_config}"
78106
changed_files=$(git diff --cached --name-only)
79107
if [[ "${changed_files}" == "" ]]; then
80-
echo "The latest googleapis commit is not changed."
108+
echo "The latest generation config is not changed."
81109
echo "Skip committing to the pull request."
82110
exit 0
83111
fi
@@ -89,4 +117,5 @@ if [ -z "${pr_num}" ]; then
89117
gh pr create --title "${title}" --head "${current_branch}" --body "${title}" --base "${base_branch}"
90118
else
91119
git push
120+
gh pr edit "${pr_num}" --title "${title}" --body "${title}"
92121
fi
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Copyright 2024 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
# GitHub action job to test core java library features on
15+
# downstream client libraries before they are released.
16+
name: Update generation configuration
17+
on:
18+
schedule:
19+
- cron: '0 2 * * *'
20+
workflow_dispatch:
21+
22+
jobs:
23+
update-generation-config:
24+
runs-on: ubuntu-22.04
25+
env:
26+
# the branch into which the pull request is merged
27+
base_branch: main
28+
steps:
29+
- uses: actions/checkout@v4
30+
with:
31+
token: ${{ secrets.CLOUD_JAVA_BOT_TOKEN }}
32+
- name: Update params in generation config to latest
33+
shell: bash
34+
run: |
35+
set -x
36+
[ -z "$(git config user.email)" ] && git config --global user.email "[email protected]"
37+
[ -z "$(git config user.name)" ] && git config --global user.name "cloud-java-bot"
38+
bash .github/scripts/update_generation_config.sh.sh \
39+
--base_branch "${base_branch}"\
40+
--repo ${{ github.repository }}
41+
env:
42+
GH_TOKEN: ${{ secrets.CLOUD_JAVA_BOT_TOKEN }}

0 commit comments

Comments
 (0)