feat: adopt repository_ctx.repo_metadata for Bazel 9#286
Merged
Conversation
The repository rule implementation returns the dict it considers the "canonical reproducible form" of the repo. Bazel compares each returned attribute against the declared one and emits a DEBUG message suggesting the user add any that differ. `url` is mutually exclusive with `repository`/`chart_name`/`version`, but the implementation returned all of them unconditionally. As a result: - importing via `url` suggested adding `chart_name`/`version` - importing via `repository` suggested adding `url` Both suggestions are rejected by the rule's own argument validation, so the DEBUG message is confusing and unactionable (see periareon#189). Return only the attributes that match the source type that was actually used so the suggested reproducible form is always a valid re-declaration. Fixes periareon#189
Bazel 9 deprecates returning a bare dict from a repository rule implementation in favor of `repository_ctx.repo_metadata`, which lets a repo additionally declare itself reproducible so Bazel can cache the fetched contents across workspaces. A chart pinned by `sha256` is reproducible: refetching with the same attributes yields identical output. Mark those repos `reproducible = True`; otherwise advertise the resolved `sha256` via `attrs_for_reproducibility` so users can pin it. `repo_metadata` was added in Bazel 8.3.0, so guard on its availability with `hasattr` and fall back to the legacy bare-dict return on older versions (the project still supports Bazel 7.x in CI).
abrisco
approved these changes
Jun 3, 2026
abrisco
left a comment
Collaborator
There was a problem hiding this comment.
Looks good to me, thanks! Just needs a rebase 😄
Contributor
Author
|
Thanks for the review! The PR has been rebased. |
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.
Note
Stacked on #285. That PR fixes the contents of the reproducibility dict, this one changes the mechanism used to return it. Review/merge after #285 (or together).
Issue
Bazel 9 deprecates returning a bare dict from a repository rule implementation in favor of
repository_ctx.repo_metadata. Beyond replacing the dict,repo_metadatalets a repo declare itself reproducible.helm_import_repositoryalready resolves asha256for every fetch. A chart pinned bysha256is reproducible by definition, so we mark itreproducible = True. When nosha256was supplied we instead advertise the resolved one viaattrs_for_reproducibility, exactly as the legacy bare-dict return did.The call is guarded with
hasattr, matching the approach in bazel-contrib/rules_python#3597 and bazel-contrib/rules_multitool#123:repo_metadatawas only added in Bazel 8.3.0, and this project still supports Bazel 7.x in CI.Testing
Verified with
bazel fetch --repo=@... --forceon Bazel 9.1.0 against the charts intests/test_deps.bzl:postgresql/grafana/rediswithsha256reproducible = True, no DEBUG, fetch cachedpostgresqlwithsha256removedsha256 = "...", fetch succeeds