Skip to content

Commit

Permalink
chore: update generation config (#10955)
Browse files Browse the repository at this point in the history
* chore: update repo level params

* downgrade

* add log

* update script name

* update title

* capitalize word

* add comments

* remove major version limitation
  • Loading branch information
JoeWang1127 authored Jun 11, 2024
1 parent 5a10656 commit 89b548f
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 10 deletions.
File renamed without changes.
39 changes: 34 additions & 5 deletions generation/update_googleapis_commit.sh → .github/scripts/update_generation_config.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,12 +1,32 @@
#!/bin/bash
set -e
# This script should be run at the root of the repository.
# This script is used to update googleapis commit to latest in generation
# configuration at the time of running and create a pull request.
# This script is used to update googleapis_commitish, gapic_generator_version,
# and libraries_bom_version in generation configuration at the time of running
# and create a pull request.

# The following commands need to be installed before running the script:
# 1. git
# 2. gh
# 3. jq

# Utility functions
# Get the latest released version of a Maven artifact.
function get_latest_released_version() {
local group_id=$1
local artifact_id=$2
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)
echo "${latest}"
}

# Update a key to a new value in the generation config.
function update_config() {
local key_word=$1
local new_value=$2
local file=$3
echo "Update ${key_word} to ${new_value} in ${file}"
sed -i -e "s/^${key_word}.*$/${key_word}: ${new_value}/" "${file}"
}

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

current_branch="generate-libraries-${base_branch}"
title="chore: update googleapis commit at $(date)"
title="chore: Update generation configuration at $(date)"

# try to find a open pull request associated with the branch
pr_num=$(gh pr list -s open -H "${current_branch}" -q . --json number | jq ".[] | .number")
Expand All @@ -72,12 +92,20 @@ git pull
latest_commit=$(git rev-parse HEAD)
popd
rm -rf tmp-googleapis
sed -i -e "s/^googleapis_commitish.*$/googleapis_commitish: ${latest_commit}/" "${generation_config}"
update_config "googleapis_commitish" "${latest_commit}" "${generation_config}"

# update gapic-generator-java version to the latest
latest_version=$(get_latest_released_version "com.google.api" "gapic-generator-java")
update_config "gapic_generator_version" "${latest_version}" "${generation_config}"

# update libraries-bom version to the latest
latest_version=$(get_latest_released_version "com.google.cloud" "libraries-bom")
update_config "libraries_bom_version" "${latest_version}" "${generation_config}"

git add "${generation_config}"
changed_files=$(git diff --cached --name-only)
if [[ "${changed_files}" == "" ]]; then
echo "The latest googleapis commit is not changed."
echo "The latest generation config is not changed."
echo "Skip committing to the pull request."
exit 0
fi
Expand All @@ -89,4 +117,5 @@ if [ -z "${pr_num}" ]; then
gh pr create --title "${title}" --head "${current_branch}" --body "${title}" --base "${base_branch}"
else
git push
gh pr edit "${pr_num}" --title "${title}" --body "${title}"
fi
2 changes: 1 addition & 1 deletion .github/workflows/hermetic_library_generation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
set -x
[ -z "$(git config user.email)" ] && git config --global user.email "cloud-java-bot@google.com"
[ -z "$(git config user.name)" ] && git config --global user.name "cloud-java-bot"
bash generation/hermetic_library_generation.sh \
bash .github/scripts/hermetic_library_generation.sh \
--target_branch "${base_ref}" \
--current_branch "${head_ref}" \
--image_tag "${library_generation_image_tag}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
# limitations under the License.
# GitHub action job to test core java library features on
# downstream client libraries before they are released.
name: Update googleapis commit
name: Update generation configuration
on:
schedule:
- cron: '0 2 * * *'
workflow_dispatch:

jobs:
update-googleapis-commit:
update-generation-config:
runs-on: ubuntu-22.04
env:
# the branch into which the pull request is merged
Expand All @@ -29,13 +29,13 @@ jobs:
- uses: actions/checkout@v4
with:
token: ${{ secrets.CLOUD_JAVA_BOT_TOKEN }}
- name: Update googleapis commit to latest
- name: Update params in generation config to latest
shell: bash
run: |
set -x
[ -z "$(git config user.email)" ] && git config --global user.email "cloud-java-bot@google.com"
[ -z "$(git config user.name)" ] && git config --global user.name "cloud-java-bot"
bash generation/update_googleapis_commit.sh \
bash .github/scripts/update_generation_config.sh.sh \
--base_branch "${base_branch}"\
--repo ${{ github.repository }}
env:
Expand Down

0 comments on commit 89b548f

Please sign in to comment.