Skip to content

Commit 3d06cba

Browse files
authored
build: fall back to previous image version on release PRs (#12848)
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 2caf026 commit 3d06cba

8 files changed

Lines changed: 84 additions & 18 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,13 +321,13 @@ jobs:
321321
- name: validate generation configuration
322322
shell: bash
323323
run: |
324-
docker run \
325-
--rm \
324+
bash generation/run_generator_docker.sh "${library_generation_image_tag}" "${{ github.base_ref || 'main' }}" \
325+
-e GENERATOR_VERSION="${library_generation_image_tag}" \
326326
--quiet \
327327
-u "$(id -u):$(id -g)" \
328328
-v "$(pwd):${workspace_name}" \
329329
--entrypoint python \
330-
gcr.io/cloud-devrel-public-resources/java-library-generation:"${library_generation_image_tag}" \
330+
-- \
331331
/src/library_generation/cli/entry_point.py validate-generation-config
332332
env:
333333
library_generation_image_tag: 2.68.0

.github/workflows/generated_files_sync.yaml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,12 @@ jobs:
2727
- name: Generate root pom.xml file
2828
shell: bash
2929
run: |
30-
docker run \
31-
--rm \
30+
bash generation/run_generator_docker.sh "${library_generation_image_tag}" "${{ github.base_ref }}" \
3231
--quiet \
3332
-u "$(id -u):$(id -g)" \
3433
-v "$(pwd):/workspace" \
3534
--entrypoint python \
36-
gcr.io/cloud-devrel-public-resources/java-library-generation:"${library_generation_image_tag}" \
35+
-- \
3736
/src/library_generation/cli/generate_monorepo_root_pom.py \
3837
generate \
3938
--repository-path=/workspace
@@ -48,13 +47,12 @@ jobs:
4847
- name: Generate gapic-libraries-bom/pom.xml
4948
shell: bash
5049
run: |
51-
docker run \
52-
--rm \
50+
bash generation/run_generator_docker.sh "${library_generation_image_tag}" "${{ github.base_ref }}" \
5351
--quiet \
5452
-u "$(id -u):$(id -g)" \
5553
-v "$(pwd):/workspace" \
5654
--entrypoint python \
57-
gcr.io/cloud-devrel-public-resources/java-library-generation:"${library_generation_image_tag}" \
55+
-- \
5856
/src/library_generation/cli/generate_monorepo_gapic_bom.py \
5957
generate \
6058
--repository-path=/workspace \

.github/workflows/hermetic_library_generation.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ on:
2020
env:
2121
REPO_FULL_NAME: ${{ github.event.pull_request.head.repo.full_name }}
2222
GITHUB_REPOSITORY: ${{ github.repository }}
23+
# {x-version-update-start:gapic-generator-java:current}
24+
GENERATOR_VERSION: 2.71.0
25+
# {x-version-update-end}
2326
jobs:
2427
library_generation:
2528
runs-on: ubuntu-latest
@@ -44,4 +47,4 @@ jobs:
4447
head_ref: ${{ github.head_ref }}
4548
token: ${{ secrets.CLOUD_JAVA_BOT_GITHUB_TOKEN }}
4649
force_regenerate_all: ${{ github.event.pull_request.head.ref == 'generate-libraries-main' }}
47-
image_tag: 2.71.0 # {x-version-update:gapic-generator-java:current}
50+
image_tag: ${{ env.GENERATOR_VERSION }}

generation/run_generator_docker.sh

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/bin/bash
2+
# Copyright 2026 Google LLC
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
set -exo pipefail
17+
18+
REQUESTED_TAG="$1"
19+
TARGET_BRANCH="$2"
20+
shift 2
21+
22+
# Parse arguments using '--' as delimiter
23+
DOCKER_OPTS=()
24+
CONTAINER_CMD=()
25+
found_delimiter=false
26+
27+
for arg in "$@"; do
28+
if [ "$arg" == "--" ]; then
29+
found_delimiter=true
30+
continue
31+
fi
32+
if $found_delimiter; then
33+
CONTAINER_CMD+=("$arg")
34+
else
35+
DOCKER_OPTS+=("$arg")
36+
fi
37+
done
38+
39+
IMAGE_NAME="gcr.io/cloud-devrel-public-resources/java-library-generation"
40+
# Support both local git and GitHub Actions environment variables
41+
CURRENT_BRANCH="${GITHUB_HEAD_REF:-${GITHUB_REF_NAME:-$(git branch --show-current)}}"
42+
IMAGE_TAG="$REQUESTED_TAG"
43+
44+
# Fallback logic on Release PR branches
45+
if [[ "$CURRENT_BRANCH" =~ ^release-please-- ]]; then
46+
echo "Detected release PR branch: $CURRENT_BRANCH"
47+
if ! docker pull "${IMAGE_NAME}:${IMAGE_TAG}"; then
48+
echo "Image not found for version ${IMAGE_TAG}. Falling back to previous version from ${TARGET_BRANCH}."
49+
# Extract tag from target branch's versions.txt using explicit fetch
50+
git fetch origin "${TARGET_BRANCH}" --depth=1 || true
51+
PREVIOUS_TAG=$(git show FETCH_HEAD:versions.txt | grep "^gapic-generator-java:" | cut -d ':' -f 2 || true)
52+
if [ -n "$PREVIOUS_TAG" ]; then
53+
echo "Using previous image version: $PREVIOUS_TAG"
54+
IMAGE_TAG="$PREVIOUS_TAG"
55+
else
56+
echo "Failed to extract fallback tag. Proceeding with requested tag."
57+
fi
58+
fi
59+
fi
60+
61+
# Execute Docker run with proper ordering
62+
docker run --rm "${DOCKER_OPTS[@]}" "${IMAGE_NAME}:${IMAGE_TAG}" "${CONTAINER_CMD[@]}"

generation_config.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
gapic_generator_version: 2.70.0
21
googleapis_commitish: 62e4ecb2f4390728990514fea14aad0431881a52
32
libraries_bom_version: 26.79.0
43
libraries:

java-vectorsearch/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,20 @@ If you are using Maven without the BOM, add this to your dependencies:
4545
<dependency>
4646
<groupId>com.google.cloud</groupId>
4747
<artifactId>google-cloud-vectorsearch</artifactId>
48-
<version>0.12.0</version>
48+
<version>0.13.0</version>
4949
</dependency>
5050
```
5151

5252
If you are using Gradle without BOM, add this to your dependencies:
5353

5454
```Groovy
55-
implementation 'com.google.cloud:google-cloud-vectorsearch:0.12.0'
55+
implementation 'com.google.cloud:google-cloud-vectorsearch:0.13.0'
5656
```
5757

5858
If you are using SBT, add this to your dependencies:
5959

6060
```Scala
61-
libraryDependencies += "com.google.cloud" % "google-cloud-vectorsearch" % "0.12.0"
61+
libraryDependencies += "com.google.cloud" % "google-cloud-vectorsearch" % "0.13.0"
6262
```
6363

6464
## Authentication
@@ -181,7 +181,7 @@ Java is a registered trademark of Oracle and/or its affiliates.
181181
[javadocs]: https://cloud.google.com/java/docs/reference/google-cloud-vectorsearch/latest/overview
182182
[stability-image]: https://img.shields.io/badge/stability-preview-yellow
183183
[maven-version-image]: https://img.shields.io/maven-central/v/com.google.cloud/google-cloud-vectorsearch.svg
184-
[maven-version-link]: https://central.sonatype.com/artifact/com.google.cloud/google-cloud-vectorsearch/0.12.0
184+
[maven-version-link]: https://central.sonatype.com/artifact/com.google.cloud/google-cloud-vectorsearch/0.13.0
185185
[authentication]: https://github.com/googleapis/google-cloud-java#authentication
186186
[auth-scopes]: https://developers.google.com/identity/protocols/oauth2/scopes
187187
[predefined-iam-roles]: https://cloud.google.com/iam/docs/understanding-roles#predefined_roles

sdk-platform-java/.cloudbuild/library_generation/library_generation.Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ ARG GRPC_VERSION=1.80.0
4343
ENV HOME=/home
4444
ENV OS_ARCHITECTURE="linux-x86_64"
4545

46+
# {x-version-update-start:gapic-generator-java:current}
47+
ENV GENERATOR_VERSION="2.71.0"
48+
# {x-version-update-end}
49+
4650
# install OS tools
4751
RUN apt update && apt install -y curl unzip rsync jq nodejs npm git openjdk-17-jdk
4852

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ set -exo pipefail
2727
# the default value is generation_config.yaml in the repository root.
2828
# 5. [optional] showcase_mode, true if we wish to download the showcase api
2929
# definitions, which are necessary for generating the showcase library.
30+
IMAGE_NAME="gcr.io/cloud-devrel-public-resources/java-library-generation"
3031
while [[ $# -gt 0 ]]; do
3132
key="$1"
3233
case "${key}" in
@@ -123,13 +124,12 @@ changed_libraries="$(cat "${changed_libraries_file}")"
123124
echo "Changed libraries are: ${changed_libraries:-"No changed library"}."
124125

125126
# run hermetic code generation docker image.
126-
docker run \
127-
--rm \
127+
bash generation/run_generator_docker.sh "${image_tag}" "${target_branch}" \
128128
-u "$(id -u):$(id -g)" \
129129
-v "$(pwd):${workspace_name}" \
130130
-v "${api_def_dir}:${workspace_name}/googleapis" \
131131
-e GENERATOR_VERSION="${image_tag}" \
132-
gcr.io/cloud-devrel-public-resources/java-library-generation:"${image_tag}" \
132+
-- \
133133
--generation-config-path="${workspace_name}/${generation_config}" \
134134
--library-names="${changed_libraries}" \
135135
--api-definitions-path="${workspace_name}/googleapis"

0 commit comments

Comments
 (0)