Add setup_presubmit_repos.py to reproduce BCR presubmit locally (#3550)

This script will create test repos based on presubmit.yml file of given
repo and print out commands to reproduce the presubmit builds.

Requires https://github.com/bazelbuild/continuous-integration/pull/2155

Fixes https://github.com/bazelbuild/bazel-central-registry/issues/1686

An example run on `protobuf@29.2`:

```
$ bazel run //tools:setup_presubmit_repos -- --module protobuf@29.2
INFO: Invocation ID: 61e8900e-69df-4cb4-82a2-7f6db491c75e
INFO: Options provided by the client:
  Inherited 'common' options: --isatty=1 --terminal_columns=260
INFO: Reading rc options for 'run' from /Users/pcloudy/.bazelrc:
  Inherited 'build' options: --verbose_failures --announce_rc --disk_cache=/tmp/bazel_disk_cache --repository_cache=/tmp/bazel_repository_cache
INFO: Analyzed target //tools:setup_presubmit_repos (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
Target //tools:setup_presubmit_repos up-to-date:
  bazel-bin/tools/setup_presubmit_repos
INFO: Elapsed time: 0.164s, Critical Path: 0.00s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
INFO: Running command line: bazel-bin/tools/setup_presubmit_repos <args omitted>
2025-01-09 14:50:35,148 - INFO: Testing using registry at: /Users/pcloudy/workspace/bazel-central-registry
2025-01-09 14:50:35,151 - INFO: Creating anonymous module repo at: /Users/pcloudy/workspace/bazel-central-registry/temp_test_repos/protobuf/29.2/anonymous_module
2025-01-09 14:50:35,152 - INFO: Anonymous module repo ready at: /Users/pcloudy/workspace/bazel-central-registry/temp_test_repos/protobuf/29.2/anonymous_module

To reproduce the build, follow these steps (make sure Bazelisk is installed as bazel):

    export USE_BAZEL_VERSION=7.x
    cd /Users/pcloudy/workspace/bazel-central-registry/temp_test_repos/protobuf/29.2/anonymous_module
    bazel build --host_cxxopt=-std=c++14 --cxxopt=-std=c++14 -- @protobuf//:protobuf @protobuf//:protobuf_lite @protobuf//:protobuf_python @protobuf//:protobuf_java @protobuf//:protoc @protobuf//:test_messages_proto2_cc_proto @protobuf//:test_messages_proto3_cc_proto

Make sure to check /Users/pcloudy/workspace/bazel-central-registry/modules/protobuf/29.2/presubmit.yml for additional build and test configurations.

2025-01-09 14:50:35,152 - INFO: Creating test module repo at: /Users/pcloudy/workspace/bazel-central-registry/temp_test_repos/protobuf/29.2/test_module
2025-01-09 14:50:36,439 - INFO: Test module repo ready at: /Users/pcloudy/workspace/bazel-central-registry/temp_test_repos/protobuf/29.2/test_module/output/protobuf-29.2/examples

To reproduce the build, follow these steps (make sure Bazelisk is installed as bazel):

    export USE_BAZEL_VERSION=7.x
    cd /Users/pcloudy/workspace/bazel-central-registry/temp_test_repos/protobuf/29.2/test_module/output/protobuf-29.2/examples
    bazel build --host_cxxopt=-std=c++14 --cxxopt=-std=c++14 -- //...

Make sure to check /Users/pcloudy/workspace/bazel-central-registry/modules/protobuf/29.2/presubmit.yml for additional build and test configurations.
```
7 files changed
tree: 99355b9a22dab94301967ffb2c9ff40228569f7c
  1. .bazelci/
  2. .github/
  3. docs/
  4. modules/
  5. tools/
  6. .bazelignore
  7. .bazelversion
  8. .editorconfig
  9. .git-blame-ignore-revs
  10. .gitattributes
  11. .gitignore
  12. .pre-commit-config.yaml
  13. .ruff.toml
  14. AUTHORS
  15. bazel_registry.json
  16. BUILD
  17. LICENSE
  18. metadata.schema.json
  19. MODULE.bazel
  20. README.md
  21. WORKSPACE
README.md

Bazel Central Registry

Overview

The default Bazel registry for the Bzlmod external dependency system of Bazel. It is the recommended place to find and publish your favorite Bazel projects. Visit https://registry.bazel.build to check what modules are already available!

Contributing

To contribute, check our BCR policies and contribution guidelines.

Depending on the BCR infrastructure (and how not to)

The core infrastructure of the Bazel Central Registry depends on GitHub and Google Cloud. Bazel users who enable Bzlmod depend on the BCR by default. While we try to keep the BCR infrastructure simple and reliable, we assume no liability for any damages caused by build failures due to potential BCR infrastructure failures.

If you consider it necessary, you can do the following to avoid depending on the BCR infrastructure while still making use of the information checked into the BCR.

  • Clone the BCR repository or mirror the content to your own infrastructure and use the --registry option to change the default Bazel registry to your own.
  • Host your own mirror for all source archive URLs and add the mirror URL in ./bazel_registry.json. You can run bazel run //tools:print_all_src_urls to get the list of source URLs to mirror for all Bazel modules checked into the BCR. For example, https://foo.com/bar.zip should be mirrored to https://<your mirror>/foo.com/bar.zip.