Skip to content

build: fall back to previous image version on release PRs#12848

Open
meltsufin wants to merge 9 commits intomainfrom
release-please--fix-12825
Open

build: fall back to previous image version on release PRs#12848
meltsufin wants to merge 9 commits intomainfrom
release-please--fix-12825

Conversation

@meltsufin
Copy link
Copy Markdown
Member

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

@meltsufin meltsufin requested a review from a team as a code owner April 18, 2026 02:03
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a fallback mechanism for the hermetic library generation script. When a release PR branch is detected, the script attempts to pull the specified Docker image; if it fails, it tries to extract and use the image tag from the target branch's workflow configuration. The review feedback suggests improving the robustness of the tag extraction logic to better handle potential multiple matches, comments, or colons within the YAML file.

Comment thread sdk-platform-java/.github/scripts/hermetic_library_generation.sh Outdated
@meltsufin meltsufin force-pushed the release-please--fix-12825 branch from 6880d59 to def6f2d Compare April 18, 2026 02:16
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
@meltsufin
Copy link
Copy Markdown
Member Author

Fallback validated in a separate release simulation PR #12849:

+ [[ release-please--simulation =~ ^release-please-- ]]
+ echo 'Detected release PR branch: release-please--simulation'
+ docker pull gcr.io/cloud-devrel-public-resources/java-library-generation:9.99.9
Detected release PR branch: release-please--simulation
Error response from daemon: manifest for gcr.io/cloud-devrel-public-resources/java-library-generation:9.99.9 not found: manifest unknown: Failed to fetch "9.99.9"
+ echo 'Image not found for version 9.99.9. Falling back to previous version from main.'
Image not found for version 9.99.9. Falling back to previous version from main.
++ git show main:.github/workflows/hermetic_library_generation.yaml
++ grep -m 1 '^[[:space:]]*image_tag:'
++ cut -d : -f 2-
++ cut -d '#' -f 1
++ xargs
+ previous_tag=2.71.0
+ '[' -n 2.71.0 ']'
+ echo 'Using previous image version: 2.71.0'
+ image_tag=2.71.0
Using previous image version: 2.71.0
++ id -u
++ id -g
++ pwd
+ docker run --rm -u 1001:1001 -v /home/runner/work/google-cloud-java/google-cloud-java:/workspace -v /tmp/tmp.dG9h7KnPTo:/workspace/googleapis -e GENERATOR_VERSION=2.71.0 gcr.io/cloud-devrel-public-resources/java-library-generation:2.71.0 --generation-config-path=/workspace/generation_config.yaml --library-names= --api-definitions-path=/workspace/googleapis
Unable to find image 'gcr.io/cloud-devrel-public-resources/java-library-generation:2.71.0' locally
2.71.0: Pulling from cloud-devrel-public-resources/java-library-generation

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)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main branch is updated through a snapshot version of the container. Using an old version brings the change back.

Blake wrote:

The flow after migration is: 
every commit to main triggers a Cloud Build job -> 
create a snapshot hermetic image -> 
nightly generation uses the latest snapshot image to regenerate the whole repo 
-> google-cloud-java release

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you clarify what is the problem?
Since Release Please PRs only update versions and changelogs and do not modify the generator itself, using the previously pushed image from the latest commit in main should be safe. It should not produce regressions because the generation logic is identical to what produced the current state of main.

Copy link
Copy Markdown
Member

@suztomo suztomo Apr 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using the previously pushed image from the latest commit in main

If that's the case (it's using the latest pushed snapshot image), then that's good. I was under the impression that the "previous image version" to be the one published in the previous release cycle (2 weeks ago). Can you confirm which is the case?

For reference, I got 2.71.0 from this command:

suztomo@suztomo:~/migration-work/google-cloud-java$ 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
2.71.0

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since Release Please PRs only update versions and changelogs and do not modify the generator itself

But the image contains the generator, I think this does introduce risks as @suztomo mentioned.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we just use the "latest" tag? The intention is more clear than these if-statements and $(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).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@blakeli0 Can you please explain the risk a bit more? As far as I understand, the image gets rebuilt on push to main and tagged with :latest and :{version}. The version tag is floating to the latest build from that branch. So, a release pull request targeting that branch should be able to use the latest image at last version safely because it should have no functional difference with the release commit version of the generator.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the script checking for previous SNAPSHOT versions as well? If yes, then we should be good.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it should always use gapic-generator-java:current version, which would at times have -SNAPSHOT.

@meltsufin meltsufin requested a review from suztomo April 20, 2026 15:45
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)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since Release Please PRs only update versions and changelogs and do not modify the generator itself

But the image contains the generator, I think this does introduce risks as @suztomo mentioned.


# 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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could create release-please PRs from CLI as well.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fine, as long as the branch prefix is release-please--.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But that means we have to remember using release-please-- as the branch name, is there any harm we do this for every branches?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You shouldn't have to use the Release Please CLI going forward which should eliminate the need to remember the branch prefix. The risk of always falling back is that if someone configures and invalid generator version, they won't get a CI failure as feedback.

Copy link
Copy Markdown
Member

@suztomo suztomo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving but please consider whether to use the "latest" tag.

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)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we just use the "latest" tag? The intention is more clear than these if-statements and $(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).

@meltsufin
Copy link
Copy Markdown
Member Author

Approving but please consider whether to use the "latest" tag.

@suztomo I think using the version in the target branch is more robust because it allows the code to support multiple branches with different versions of the generator.

@meltsufin meltsufin requested a review from blakeli0 April 21, 2026 00:53
@meltsufin meltsufin force-pushed the release-please--fix-12825 branch from 9a162ab to ef92609 Compare April 21, 2026 02:01
Comment thread generation_config.yaml
@@ -1,4 +1,3 @@
gapic_generator_version: 2.70.0
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@blakeli0 Note that I'm removing this version declaration because it's confusing as it doesn't get updated, and it's not used anyway.

@sonarqubecloud
Copy link
Copy Markdown

@sonarqubecloud
Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Library-generation fails on release PRs

3 participants