Skip to content

Commit 0b12990

Browse files
committed
Add automated Bazel Central Registry publishing on release
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
1 parent ac8b124 commit 0b12990

File tree

6 files changed

+161
-0
lines changed

6 files changed

+161
-0
lines changed

.bcr/README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Bazel Central Registry (BCR) Publishing
2+
3+
This directory contains template files for automated publishing to the [Bazel Central Registry (BCR)](https://github.com/bazelbuild/bazel-central-registry).
4+
5+
## Overview
6+
7+
When a new release tag is created, the GitHub Actions workflow automatically:
8+
1. Generates a BCR entry using these templates
9+
2. Creates attestations for the generated files
10+
3. Opens a pull request against the Bazel Central Registry
11+
12+
## Files
13+
14+
- **metadata.template.json**: Contains repository metadata and maintainer information
15+
- **source.template.json**: Defines the source archive location and format
16+
- **presubmit.yml**: Specifies BCR CI tests to validate the module
17+
18+
## Workflow
19+
20+
The publish workflow is triggered by:
21+
- Release publication (automatic)
22+
- Manual workflow dispatch (for retries or re-publishing)
23+
24+
See `.github/workflows/publish.yaml` and `.github/workflows/release.yml` for the workflow configuration.
25+
26+
## Requirements
27+
28+
The workflow requires a `BCR_PUBLISH_TOKEN` secret to be configured in the repository settings. This should be a GitHub Personal Access Token with:
29+
- `repo` scope
30+
- `workflow` scope
31+
32+
The token should be created by someone with write access to a fork of the bazel-central-registry.
33+
34+
## References
35+
36+
- [Publish to BCR documentation](https://github.com/bazel-contrib/publish-to-bcr)
37+
- [BCR templates](https://github.com/bazel-contrib/publish-to-bcr/tree/main/templates)
38+
- [Bazel Central Registry](https://github.com/bazelbuild/bazel-central-registry)

.bcr/metadata.template.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"homepage": "https://github.com/google/flatbuffers",
3+
"maintainers": [
4+
{
5+
"name": "Derek Bailey",
6+
"github": "dbaileychess",
7+
"github_user_id": 1477247
8+
},
9+
{
10+
"name": "mering",
11+
"github": "mering",
12+
"github_user_id": 133344217
13+
}
14+
],
15+
"_comment": "maintainers will be emailed if a BCR release fails; add additional maintainers as needed",
16+
"repository": [
17+
"github:google/flatbuffers"
18+
],
19+
"versions": [],
20+
"yanked_versions": {}
21+
}

.bcr/presubmit.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
matrix:
3+
bazel:
4+
- 7.x
5+
- 8.x
6+
tasks:
7+
verify_ubuntu2004:
8+
name: Test Ubuntu 20.04
9+
platform: ubuntu2004
10+
bazel: ${{ bazel }}
11+
environment:
12+
CC: clang
13+
SWIFT_VERSION: "5.8"
14+
SWIFT_HOME: "$HOME/swift-$SWIFT_VERSION"
15+
PATH: "$PATH:$SWIFT_HOME/usr/bin"
16+
shell_commands:
17+
- "echo --- Downloading and extracting Swift $SWIFT_VERSION to $SWIFT_HOME"
18+
- "mkdir $SWIFT_HOME"
19+
- "curl https://download.swift.org/swift-${SWIFT_VERSION}-release/ubuntu2004/swift-${SWIFT_VERSION}-RELEASE/swift-${SWIFT_VERSION}-RELEASE-ubuntu20.04.tar.gz | tar xvz --strip-components=1 -C $SWIFT_HOME"
20+
build_targets:
21+
- "@flatbuffers//:*"
22+
verify_ubuntu2204:
23+
name: Test Ubuntu 22.04
24+
platform: ubuntu2204
25+
bazel: ${{ bazel }}
26+
environment:
27+
CC: clang
28+
SWIFT_VERSION: "5.8"
29+
SWIFT_HOME: "$HOME/swift-$SWIFT_VERSION"
30+
PATH: "$PATH:$SWIFT_HOME/usr/bin"
31+
shell_commands:
32+
- "echo --- Downloading and extracting Swift $SWIFT_VERSION to $SWIFT_HOME"
33+
- "mkdir $SWIFT_HOME"
34+
- "curl https://download.swift.org/swift-${SWIFT_VERSION}-release/ubuntu2204/swift-${SWIFT_VERSION}-RELEASE/swift-${SWIFT_VERSION}-RELEASE-ubuntu22.04.tar.gz | tar xvz --strip-components=1 -C $SWIFT_HOME"
35+
build_targets:
36+
- "@flatbuffers//:*"
37+
verify_macos:
38+
name: Test macOS
39+
platform: macos
40+
bazel: ${{ bazel }}
41+
xcode_version: "15.2"
42+
build_targets:
43+
- "@flatbuffers//:*"

.bcr/source.template.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"url": "https://github.com/{OWNER}/{REPO}/archive/refs/tags/{TAG}.tar.gz",
3+
"integrity": "",
4+
"strip_prefix": "{REPO}-{VERSION}"
5+
}

.github/workflows/publish.yaml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Publish to BCR
2+
3+
on:
4+
# Run the publish workflow after a successful release
5+
workflow_call:
6+
inputs:
7+
tag_name:
8+
required: true
9+
type: string
10+
# In case of problems, let release engineers retry by manually dispatching
11+
# the workflow from the GitHub UI
12+
workflow_dispatch:
13+
inputs:
14+
tag_name:
15+
description: 'Tag name to publish (e.g., v25.2.10)'
16+
required: true
17+
type: string
18+
19+
jobs:
20+
publish:
21+
uses: bazel-contrib/publish-to-bcr/.github/workflows/publish.yaml@v1.0.0
22+
with:
23+
tag_name: ${{ inputs.tag_name }}
24+
# GitHub repository which is a fork of the upstream where the Pull Request will be opened.
25+
# This should be set to your fork of bazel-central-registry
26+
registry_fork: google/bazel-central-registry
27+
# Enable attestation support
28+
attest: true
29+
# Open the pull request as a draft
30+
draft: true
31+
permissions:
32+
contents: write
33+
# Necessary for attestation
34+
id-token: write
35+
# Necessary for attestation
36+
attestations: write
37+
secrets:
38+
# Necessary to push to the BCR fork, and to open a pull request against a registry
39+
publish_token: ${{ secrets.BCR_PUBLISH_TOKEN }}

.github/workflows/release.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,18 @@ jobs:
150150
with:
151151
path: ./rust/flexbuffers
152152
registry-token: ${{ secrets.CARGO_TOKEN }}
153+
154+
publish-bcr:
155+
name: Publish to BCR
156+
# Run after all other publish jobs succeed to ensure we only publish to BCR
157+
# if all package publications were successful
158+
needs: [publish-npm, publish-pypi, publish-nuget, publish-maven, publish-maven-kotlin, publish-crates]
159+
uses: ./.github/workflows/publish.yaml
160+
with:
161+
tag_name: ${{ github.event.release.tag_name }}
162+
permissions:
163+
contents: write
164+
id-token: write
165+
attestations: write
166+
secrets:
167+
publish_token: ${{ secrets.BCR_PUBLISH_TOKEN }}

0 commit comments

Comments
 (0)