diff --git a/.github/scripts/update_generation_config.sh b/.github/scripts/update_generation_config.sh index 93e1a47bea..2acad04855 100644 --- a/.github/scripts/update_generation_config.sh +++ b/.github/scripts/update_generation_config.sh @@ -1,32 +1,12 @@ #!/bin/bash -set -ex +set -e # This script should be run at the root of the repository. -# 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. +# This script is used to update googleapis commit to latest 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. @@ -72,50 +52,62 @@ if [ -z "${generation_config}" ]; then fi current_branch="generate-libraries-${base_branch}" -title="chore: Update generation configuration at $(date)" +title="chore: update googleapis commit at $(date)" -# try to find a open pull request associated with the branch +git checkout "${base_branch}" +# 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") -# create a branch if there's no open pull request associated with the +# Create a branch if there's no open pull request associated with the # branch; otherwise checkout the pull request. if [ -z "${pr_num}" ]; then git checkout -b "${current_branch}" + # Push the current branch to remote so that we can + # compare the commits later. + git push -u origin "${current_branch}" else gh pr checkout "${pr_num}" fi +# Only allow fast-forward merging; exit with non-zero result if there's merging +# conflict. +git merge -m "chore: merge ${base_branch} into ${current_branch}" "${base_branch}" + mkdir tmp-googleapis -# use partial clone because only commit history is needed. +# Use partial clone because only commit history is needed. git clone --filter=blob:none https://github.com/googleapis/googleapis.git tmp-googleapis pushd tmp-googleapis git pull latest_commit=$(git rev-parse HEAD) popd rm -rf tmp-googleapis -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}" +sed -i -e "s/^googleapis_commitish.*$/googleapis_commitish: ${latest_commit}/" "${generation_config}" git add "${generation_config}" changed_files=$(git diff --cached --name-only) if [[ "${changed_files}" == "" ]]; then - echo "The latest generation config is not changed." + echo "The latest googleapis commit is not changed." echo "Skip committing to the pull request." +else + git commit -m "${title}" +fi + +# There are potentially at most two commits: merge commit and change commit. +# We want to exit the script if no commit happens (otherwise this will be an +# infinite loop). +# `git cherry` is a way to find whether the local branch has commits that are +# not in the remote branch. +# If we find any such commit, push them to remote branch. +unpushed_commit=$(git cherry -v "origin/${current_branch}" | wc -l) +if [[ "${unpushed_commit}" -eq 0 ]]; then + echo "No unpushed commits, exit" exit 0 fi -git commit -m "${title}" + if [ -z "${pr_num}" ]; then git remote add remote_repo https://cloud-java-bot:"${GH_TOKEN}@github.com/${repo}.git" - git fetch -q --unshallow remote_repo + git fetch -q remote_repo git push -f remote_repo "${current_branch}" 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/README.md b/README.md index c1b80b33e8..08372906aa 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ If you are using Maven without the BOM, add this to your dependencies: If you are using Gradle 5.x or later, add this to your dependencies: ```Groovy -implementation platform('com.google.cloud:libraries-bom:26.50.0') +implementation platform('com.google.cloud:libraries-bom:26.51.0') implementation 'com.google.cloud:google-cloud-bigtable' ``` diff --git a/generation_config.yaml b/generation_config.yaml index c885f1fb10..d150ade6ee 100644 --- a/generation_config.yaml +++ b/generation_config.yaml @@ -1,6 +1,6 @@ -gapic_generator_version: 2.50.0 -googleapis_commitish: 349841abac6c3e580ccce6e3d6fcc182ed2512c2 -libraries_bom_version: 26.50.0 +gapic_generator_version: 2.51.0 +googleapis_commitish: f4eff5440fd07389f820d22d2a55690c6390dc6d +libraries_bom_version: 26.51.0 template_excludes: - .gitignore - .kokoro/presubmit/integration.cfg diff --git a/renovate.json b/renovate.json index 3c5874c1a2..837f09eaa2 100644 --- a/renovate.json +++ b/renovate.json @@ -73,11 +73,10 @@ }, { "packagePatterns": [ - "^com.google.api:gapic-generator-java", "^com.google.cloud:sdk-platform-java-config", "^com.google.cloud:gapic-libraries-bom" ], - "groupName": "sdk-platform-java dependencies" + "groupName": "shared dependencies" } ], "regexManagers": [ @@ -109,16 +108,6 @@ "matchStrings": ["uses: googleapis/sdk-platform-java/java-shared-dependencies/unmanaged-dependency-check@google-cloud-shared-dependencies/v(?.+?)\\n"], "depNameTemplate": "com.google.cloud:sdk-platform-java-config", "datasourceTemplate": "maven" - }, - { - "fileMatch": [ - ".github/workflows/hermetic_library_generation.yaml" - ], - "matchStrings": [ - "uses: googleapis/sdk-platform-java/.github/scripts@v(?.+?)\\n" - ], - "depNameTemplate": "com.google.api:gapic-generator-java", - "datasourceTemplate": "maven" } ], "semanticCommits": true,