diff --git a/.bcr/README.md b/.bcr/README.md new file mode 100644 index 00000000000..a605a36ed36 --- /dev/null +++ b/.bcr/README.md @@ -0,0 +1,24 @@ +# Configuration to use Publish to BCR + +This directory contains a set of templates required by the [publish-to-bcr](https://github.com/bazel-contrib/publish-to-bcr/tree/main) plugin, which will publish a released version of **gRPC-Gateway** as a new module in the [Bazel Central Registry](https://registry.bazel.build/). + +The plugin aims to eliminate a manual publishing process for the module and initiate the process when a release is created. + +## Publish to BCR template files + +The configuration consists of three files placed in the `.bcr` directory: + +* `.bcr/metadata.template.json`: that describes the repository and maintainers' information. +* `.bcr/presubmit.yml`: describes the targets that will be built and tested on specific platforms and bazel versions to test the module. +* `.bcr/source.template.json`: that will automatically substitute values for the repository, owner, and tag based on the repository and release data. + +_For more information regarding the files that form a BCR entry, check the following references:_ + +* [Bazel registries](https://bazel.build/external/registry). +* [External dependencies overview](https://bazel.build/external/overview). + +## Result + +The final result of this process is the creation of a PR in the BCR repository to publish the released version. + +Once these templates are populated, the `publish-to-bcr` app should be configured as described [here](https://github.com/bazel-contrib/publish-to-bcr/tree/main?tab=readme-ov-file#how-it-works). diff --git a/.bcr/metadata.template.json b/.bcr/metadata.template.json new file mode 100644 index 00000000000..4b15db0e83c --- /dev/null +++ b/.bcr/metadata.template.json @@ -0,0 +1,13 @@ +{ + "homepage": "https://grpc-ecosystem.github.io/grpc-gateway", + "maintainers": [ + { + "name": "Johan Brandhorst-Satzkorn", + "email": "johan.brandhorst@gmail.com", + "github": "johanbrandhorst" + } + ], + "repository": ["github:grpc-ecosystem/grpc-gateway"], + "versions": [], + "yanked_versions": {} +} diff --git a/.bcr/presubmit.yml b/.bcr/presubmit.yml new file mode 100644 index 00000000000..3ffd08e0b23 --- /dev/null +++ b/.bcr/presubmit.yml @@ -0,0 +1,14 @@ +bcr_test_module: + module_path: "MODULE.bazel" + matrix: + platform: ["debian11", "macos", "macos_arm64", "ubuntu2404", "windows"] + bazel: [6.x, 7.x, 8.x] + tasks: + run_tests: + name: "Build and test grpc-gateway module" + platform: ${{ platform }} + bazel: ${{ bazel }} + build_targets: + - "//..." + test_targets: + - "//..." diff --git a/.bcr/source.template.json b/.bcr/source.template.json new file mode 100644 index 00000000000..20374716f33 --- /dev/null +++ b/.bcr/source.template.json @@ -0,0 +1,5 @@ +{ + "integrity": "", + "strip_prefix": "{REPO}-{VERSION}", + "url": "https://github.com/{OWNER}/{REPO}/releases/download/{TAG}/{REPO}-{TAG}.tar.gz" +} diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 00000000000..92044233978 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,35 @@ +# Publish new releases to Bazel Central Registry. +name: Publish to BCR +on: + # Run the publish workflow after a successful release + # Will be triggered from the release.yaml workflow + workflow_call: + inputs: + tag_name: + required: true + type: string + secrets: + publish_token: + required: true + # In case of problems, let release engineers retry by manually dispatching + # the workflow from the GitHub UI + workflow_dispatch: + inputs: + tag_name: + description: git tag being released + required: true + type: string +jobs: + publish: + uses: bazel-contrib/publish-to-bcr/.github/workflows/publish.yaml@v0.1.0 + with: + tag_name: ${{ inputs.tag_name }} + # GitHub repository which is a fork of the upstream where the Pull Request will be opened. + registry_fork: grpc-ecosystem/bazel-central-registry + permissions: + attestations: write + contents: write + id-token: write + secrets: + # Necessary to push to the BCR fork, and to open a pull request against a registry + publish_token: ${{ secrets.publish_token || secrets.BCR_PUBLISH_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9e325b335fc..0fb45806c78 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -60,3 +60,12 @@ jobs: compile-generator: true # Workaround for https://github.com/slsa-framework/slsa-github-generator/issues/1163 base64-subjects: "${{ needs.goreleaser.outputs.hashes }}" upload-assets: ${{ github.event_name == 'push' }} # upload to a new release when pushing via tag + # Job to publish the release to the Bazel Central Registry. + publish: + needs: [goreleaser] + uses: .github/workflows/publish.yaml + with: + tag_name: ${{ github.ref_name }} + secrets: + # Necessary to push to the BCR fork, and to open a pull request against a registry + publish_token: ${{ secrets.publish_token || secrets.BCR_PUBLISH_TOKEN }} \ No newline at end of file diff --git a/renovate.json b/renovate.json index 7f5ed72f2a9..96420e1cef0 100644 --- a/renovate.json +++ b/renovate.json @@ -9,6 +9,18 @@ "postUpdateOptions": [ "gomodTidy" ], + "customManagers": [ + { + "customType": "regex", + "fileMatch": [".bcr/presubmit.yml"], + "matchStrings": [ + "bazel:\\s*\\[(?[0-9.x,\\s]+)\\]" + ], + "depNameTemplate": "Bazel", + "datasourceTemplate": "bazel", + "versioningTemplate": "regex:^\\d+\\.x$" + } + ], "packageRules": [ { "updateTypes": [ @@ -44,6 +56,15 @@ "slsa-framework/slsa-github-generator" ], "pinDigests": false + }, + { + "matchManagers": [ + "github-actions" + ], + "matchPackageNames": [ + "bazel-contrib/publish-to-bcr" + ], + "automerge": true } ] }