diff --git a/generation/hermetic_library_generation.sh b/.github/scripts/hermetic_library_generation.sh similarity index 100% rename from generation/hermetic_library_generation.sh rename to .github/scripts/hermetic_library_generation.sh diff --git a/generation/update_googleapis_commit.sh b/.github/scripts/update_generation_config.sh old mode 100644 new mode 100755 similarity index 59% rename from generation/update_googleapis_commit.sh rename to .github/scripts/update_generation_config.sh index b950be9af453..561a313040f3 --- a/generation/update_googleapis_commit.sh +++ b/.github/scripts/update_generation_config.sh @@ -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. @@ -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") @@ -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 @@ -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 diff --git a/.github/workflows/hermetic_library_generation.yaml b/.github/workflows/hermetic_library_generation.yaml index 5e5dc24d851b..d2f2546a785b 100644 --- a/.github/workflows/hermetic_library_generation.yaml +++ b/.github/workflows/hermetic_library_generation.yaml @@ -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}" diff --git a/.github/workflows/update_googleapis_commit.yaml b/.github/workflows/update_generation_config.yaml similarity index 88% rename from .github/workflows/update_googleapis_commit.yaml rename to .github/workflows/update_generation_config.yaml index 42df660369d3..70b513312b7a 100644 --- a/.github/workflows/update_googleapis_commit.yaml +++ b/.github/workflows/update_generation_config.yaml @@ -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 @@ -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: