sourceconditiontarget

✔

✔

✗

Description

The bazelregistry resource reads a module’s metadata.json from a Bazel registry (the Bazel Central Registry by default) and returns a published version.

source

Returns the version matching versionfilter.

condition

Checks that the version exists in the registry.

target

Not supported - a target fails with target not supported for the plugin bazelregistry. To write the version into a MODULE.bazel, use bazelmod.

Note
An scm attached to a condition is ignored, with a warning (the lookup is always remote).

Parameters

NameTypeDescriptionRequired
modulestring

“module” defines the name of the Bazel module to query from the registry.

compatible:

  • source
  • condition

remark:

  • it is required.

example:

  • module: rules_go
  • module: rules_python
  • module: gazelle
urlstring

“url” defines a custom registry URL.

compatible:

  • source
  • condition

default: https://raw.githubusercontent.com/bazelbuild/bazel-central-registry/main/modules/{module}/metadata.json

remark:

  • the URL must contain the “{module}” placeholder, which is replaced with the module name.
  • when unset, the official Bazel Central Registry is used.

example:

  • url: https://raw.githubusercontent.com/bazelbuild/bazel-central-registry/main/modules/{module}/metadata.json
  • url: https://mycompany.com/bazel-registry/modules/{module}/metadata.json
versionfilterobject

“versionfilter” defines the version pattern and its kind, such as regex, semver or latest.

compatible:

  • source

default: kind: latest

remark:

  • yanked versions are ignored.
  • with the default filter, the highest semantic version is returned.
    kindstring

“kind” defines the versioning scheme used to select a version.

default: latest

remark:

  • accepted values are “latest”, “semver”, “regex”, “regex/semver”, “time”, “regex/time”, “lex” and “pep440”.
  • “latest” returns the last version of the list.
  • “lex” sorts the versions lexicographically and returns the last one.
  • “pep440” follows https://peps.python.org/pep-0440/

example:

  • kind: semver
    patternstring

“pattern” defines the version pattern, according to “kind”.

default:

  • latest: “latest”
  • semver and pep440: “*”
  • regex: “.*”
  • time and regex/time: “2006-01-02”

remark:

  • for “latest”, “latest” returns the last version, any other value must match a version exactly.
  • for “semver” and “regex/semver”, it is a semantic versioning constraint.
  • for “pep440”, it is a pep440 version specifier.
  • for “regex”, it is a regular expression.
  • for “time” and “regex/time”, it is a Go date layout.
  • ignored by “lex”.

example:

  • pattern: ~1.2
  • pattern: “>=1.0.0 <2.0.0”
  • pattern: ^v\d+.\d+.\d+$
    regexstring

“regex” defines the regular expression extracting the version from each entry.

remark:

  • only used by the kinds “regex/semver” and “regex/time”.
  • the value of the first capture group is used as the version.

example:

  • regex: ^v(\d+.\d+.\d+)$
    replaceallobject

“replaceall” applies a regular expression replacement to each version before filtering.

remark:

  • only used by the kinds “regex”, “regex/semver” and “regex/time”.
  • the replacement runs before “pattern” or “regex” is evaluated.

example:

replaceall:
  pattern: "_"
  replacement: "."

turns “curl-8_15_0” into “curl-8.15.0”.

    strictboolean

“strict” enforces strict semantic versioning rules when parsing versions.

default: false

remark:

  • only used by the kinds “semver” and “regex/semver”.

module is mandatory; omitting it aborts the run with wrong spec content, preceded by bazelregistry module undefined.

versionfilter

Defaults to kind: latest. See the "Version Filtering" page.

Custom registries

url points at a private registry. It is a template, not a base URL, it must contain the {module} placeholder, which is replaced with the module name:

spec:
  module: rules_python
  url: https://mycompany.example.com/bazel-registry/modules/{module}/metadata.json

The default is the Bazel Central Registry:

https://raw.githubusercontent.com/bazelbuild/bazel-central-registry/main/modules/{module}/metadata.json

Example

sources:
  rules_python:
    name: Get latest version of Bazel module rules_python
    kind: bazelregistry
    spec:
      module: rules_python
      versionfilter:
        kind: semver
        pattern: '>=0.25.0'