Skip to content

Commit 3c59412

Browse files
committed
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
1 parent 3a352fe commit 3c59412

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

sdk-platform-java/.github/scripts/hermetic_library_generation.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,21 @@ changed_libraries="$(cat "${changed_libraries_file}")"
123123
echo "Changed libraries are: ${changed_libraries:-"No changed library"}."
124124

125125
# run hermetic code generation docker image.
126+
# Attempt to pull the image to see if it exists on release PRs.
127+
if [[ "$current_branch" =~ ^release-please-- ]]; then
128+
echo "Detected release PR branch: $current_branch"
129+
if ! docker pull gcr.io/cloud-devrel-public-resources/java-library-generation:"${image_tag}"; then
130+
echo "Image not found for version ${image_tag}. Falling back to previous version from ${target_branch}."
131+
previous_tag=$(git show "${target_branch}":.github/workflows/hermetic_library_generation.yaml | grep "image_tag:" | cut -d ':' -f 2 | cut -d '#' -f 1 | xargs)
132+
if [ -n "$previous_tag" ]; then
133+
echo "Using previous image version: $previous_tag"
134+
image_tag="$previous_tag"
135+
else
136+
echo "Failed to extract previous version from ${target_branch}. Proceeding with original tag."
137+
fi
138+
fi
139+
fi
140+
126141
docker run \
127142
--rm \
128143
-u "$(id -u):$(id -g)" \

0 commit comments

Comments
 (0)