From 3c59412ad64926852d763a027926f22d8bf1eef5 Mon Sep 17 00:00:00 2001 From: Mike Eltsufin Date: Fri, 17 Apr 2026 21:54:26 -0400 Subject: [PATCH 1/4] build: fall back to previous image version on release PRs The library generation pipeline fails on release PRs because it attempts to pull a Docker image version that has not yet been built or pushed to the registry. This PR adds a fallback mechanism in hermetic_library_generation.sh to use the previous version of the image from the main branch if the requested version fails to pull on a release PR. To verify this in CI, this branch is named with the prefix 'release-please--' to simulate a release PR. Fixes #12825 --- .../scripts/hermetic_library_generation.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/sdk-platform-java/.github/scripts/hermetic_library_generation.sh b/sdk-platform-java/.github/scripts/hermetic_library_generation.sh index fc991aa3e94d..439c03c17155 100755 --- a/sdk-platform-java/.github/scripts/hermetic_library_generation.sh +++ b/sdk-platform-java/.github/scripts/hermetic_library_generation.sh @@ -123,6 +123,21 @@ changed_libraries="$(cat "${changed_libraries_file}")" echo "Changed libraries are: ${changed_libraries:-"No changed library"}." # run hermetic code generation docker image. +# Attempt to pull the image to see if it exists on release PRs. +if [[ "$current_branch" =~ ^release-please-- ]]; then + echo "Detected release PR branch: $current_branch" + if ! docker pull gcr.io/cloud-devrel-public-resources/java-library-generation:"${image_tag}"; then + echo "Image not found for version ${image_tag}. Falling back to previous version from ${target_branch}." + previous_tag=$(git show "${target_branch}":.github/workflows/hermetic_library_generation.yaml | grep "image_tag:" | cut -d ':' -f 2 | cut -d '#' -f 1 | xargs) + if [ -n "$previous_tag" ]; then + echo "Using previous image version: $previous_tag" + image_tag="$previous_tag" + else + echo "Failed to extract previous version from ${target_branch}. Proceeding with original tag." + fi + fi +fi + docker run \ --rm \ -u "$(id -u):$(id -g)" \ From 5fa7830dd283820ac3b9cc5fd4b4ba834e6a57fa Mon Sep 17 00:00:00 2001 From: Mike Eltsufin Date: Fri, 17 Apr 2026 22:07:04 -0400 Subject: [PATCH 2/4] build: extract image name to variable in hermetic script --- .../.github/scripts/hermetic_library_generation.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sdk-platform-java/.github/scripts/hermetic_library_generation.sh b/sdk-platform-java/.github/scripts/hermetic_library_generation.sh index 439c03c17155..06e0f9cb7f46 100755 --- a/sdk-platform-java/.github/scripts/hermetic_library_generation.sh +++ b/sdk-platform-java/.github/scripts/hermetic_library_generation.sh @@ -27,6 +27,7 @@ set -exo pipefail # the default value is generation_config.yaml in the repository root. # 5. [optional] showcase_mode, true if we wish to download the showcase api # definitions, which are necessary for generating the showcase library. +IMAGE_NAME="gcr.io/cloud-devrel-public-resources/java-library-generation" while [[ $# -gt 0 ]]; do key="$1" case "${key}" in @@ -126,7 +127,7 @@ echo "Changed libraries are: ${changed_libraries:-"No changed library"}." # Attempt to pull the image to see if it exists on release PRs. if [[ "$current_branch" =~ ^release-please-- ]]; then echo "Detected release PR branch: $current_branch" - if ! docker pull gcr.io/cloud-devrel-public-resources/java-library-generation:"${image_tag}"; then + if ! docker pull "${IMAGE_NAME}:${image_tag}"; then echo "Image not found for version ${image_tag}. Falling back to previous version from ${target_branch}." previous_tag=$(git show "${target_branch}":.github/workflows/hermetic_library_generation.yaml | grep "image_tag:" | cut -d ':' -f 2 | cut -d '#' -f 1 | xargs) if [ -n "$previous_tag" ]; then @@ -144,7 +145,7 @@ docker run \ -v "$(pwd):${workspace_name}" \ -v "${api_def_dir}:${workspace_name}/googleapis" \ -e GENERATOR_VERSION="${image_tag}" \ - gcr.io/cloud-devrel-public-resources/java-library-generation:"${image_tag}" \ + "${IMAGE_NAME}:${image_tag}" \ --generation-config-path="${workspace_name}/${generation_config}" \ --library-names="${changed_libraries}" \ --api-definitions-path="${workspace_name}/googleapis" From 823b98cc5348341ab37b22c556e4042137bd75b0 Mon Sep 17 00:00:00 2001 From: Mike Eltsufin Date: Fri, 17 Apr 2026 22:10:12 -0400 Subject: [PATCH 3/4] build: improve robustness of fallback version extraction --- .../.github/scripts/hermetic_library_generation.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk-platform-java/.github/scripts/hermetic_library_generation.sh b/sdk-platform-java/.github/scripts/hermetic_library_generation.sh index 06e0f9cb7f46..879c7e2bb056 100755 --- a/sdk-platform-java/.github/scripts/hermetic_library_generation.sh +++ b/sdk-platform-java/.github/scripts/hermetic_library_generation.sh @@ -129,7 +129,7 @@ if [[ "$current_branch" =~ ^release-please-- ]]; then echo "Detected release PR branch: $current_branch" if ! docker pull "${IMAGE_NAME}:${image_tag}"; then echo "Image not found for version ${image_tag}. Falling back to previous version from ${target_branch}." - previous_tag=$(git show "${target_branch}":.github/workflows/hermetic_library_generation.yaml | grep "image_tag:" | cut -d ':' -f 2 | cut -d '#' -f 1 | xargs) + previous_tag=$(git show "${target_branch}":.github/workflows/hermetic_library_generation.yaml | grep -m 1 "^[[:space:]]*image_tag:" | cut -d ':' -f 2- | cut -d '#' -f 1 | xargs) if [ -n "$previous_tag" ]; then echo "Using previous image version: $previous_tag" image_tag="$previous_tag" From c1395d2cc9685fd8c00b770e8ac4ead613c004eb Mon Sep 17 00:00:00 2001 From: Mike Eltsufin Date: Fri, 17 Apr 2026 22:42:33 -0400 Subject: [PATCH 4/4] build: prevent script termination on empty fallback match --- .../.github/scripts/hermetic_library_generation.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk-platform-java/.github/scripts/hermetic_library_generation.sh b/sdk-platform-java/.github/scripts/hermetic_library_generation.sh index 879c7e2bb056..a17e7d6fcafc 100755 --- a/sdk-platform-java/.github/scripts/hermetic_library_generation.sh +++ b/sdk-platform-java/.github/scripts/hermetic_library_generation.sh @@ -129,7 +129,7 @@ if [[ "$current_branch" =~ ^release-please-- ]]; then echo "Detected release PR branch: $current_branch" if ! docker pull "${IMAGE_NAME}:${image_tag}"; then echo "Image not found for version ${image_tag}. Falling back to previous version from ${target_branch}." - previous_tag=$(git show "${target_branch}":.github/workflows/hermetic_library_generation.yaml | grep -m 1 "^[[:space:]]*image_tag:" | cut -d ':' -f 2- | cut -d '#' -f 1 | xargs) + previous_tag=$(git show "${target_branch}":.github/workflows/hermetic_library_generation.yaml | grep -m 1 "^[[:space:]]*image_tag:" | cut -d ':' -f 2- | cut -d '#' -f 1 | xargs || true) if [ -n "$previous_tag" ]; then echo "Using previous image version: $previous_tag" image_tag="$previous_tag"