diff --git a/sdk-platform-java/.github/scripts/hermetic_library_generation.sh b/sdk-platform-java/.github/scripts/hermetic_library_generation.sh index fc991aa3e94d..a17e7d6fcafc 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 @@ -123,13 +124,28 @@ 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 "${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 || true) + 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)" \ -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"