build/bake: preserve tag refs in git contexts#231
Merged
Conversation
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
vvoland
approved these changes
Jun 11, 2026
tonistiigi
approved these changes
Jun 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This change preserves Git tag names when the reusable workflows build from a tag event by passing the event SHA as the Git context checksum. Non-tag refs continue to use
fetch-by-commit, so the existing branch and pull request behavior is unchanged.Projects like Buildx and BuildKit derive their version metadata from the Git ref that BuildKit checks out. When the Git context only uses the commit SHA, the built binary reports the short SHA as the version instead of the tag name.
The failing case was reproduced with https://github.com/docker/buildx/actions/runs/27313485396/job/80688869371#step:11:476:
That build produced ldflags with
github.com/docker/buildx/version.Version=89b455a, so the binary version was based only on the commit SHA.The working query case was reproduced with:
That keeps the tag ref available for version metadata while still validating that the tag resolves to the expected commit.
You can add this after the paragraph that says projects derive version metadata from the Git ref:
The important detail is that the Git context
refis not only a pin. It's also the ref name that BuildKit resolves and checks out for the source. In the failing workflow invocation,ref=89b455a9e38ca3808e94190ce5c54193c9cb2e06tells BuildKit to resolve the source directly by commit SHA. The checkout is therefore identified by that commit, not byrefs/tags/v0.35.0-rc1, so the Buildx version generation cannot recover the release tag from the ref that selected the source.Using
ref=refs/tags/v0.35.0-rc1&checksum=89b455a9e38ca3808e94190ce5c54193c9cb2e06separates the human version identity from the immutable commit validation. Therefremains the tag ref, so BuildKit resolves the source through the tag and the Buildx version metadata seesv0.35.0-rc1. Thechecksumthen asserts that this tag must resolve to the expected event commit. If the tag points anywhere else, Git context resolution fails before the build starts. This preserves the tag version in the binary while still pinning the source to the exact commit that triggered the workflow.