Skip to content

Commit e19560f

Browse files
committed
Add BCR boilerplate
1 parent 833edb6 commit e19560f

File tree

14 files changed

+519
-109
lines changed

14 files changed

+519
-109
lines changed

.bcr/metadata.template.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"homepage": "https://github.com/protocolbuffers/protobuf-javascript",
3+
"maintainers": [
4+
{
5+
"name": "Stephanie DiBenedetto",
6+
"email": "[email protected]",
7+
"github": "dibenede"
8+
},
9+
{
10+
"name": "Paul Cody",
11+
"email": "[email protected]",
12+
"github": "pcj"
13+
}
14+
],
15+
"repository": [
16+
"github:protocolbuffers/protobuf-javascript"
17+
],
18+
"versions": [],
19+
"yanked_versions": {}
20+
}

.bcr/presubmit.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
bcr_test_module:
2+
module_path: "e2e/bcr"
3+
matrix:
4+
platform: ["debian11", "ubuntu2404", "macos"]
5+
bazel: [7.x, 8.x]
6+
tasks:
7+
run_tests:
8+
name: "Run test module"
9+
platform: ${{ platform }}
10+
bazel: ${{ bazel }}
11+
test_targets:
12+
- "//..."

.bcr/source.template.json

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

.github/workflows/publish.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Publish new releases to Bazel Central Registry.
2+
name: Publish to BCR
3+
on:
4+
# Run the publish workflow after a successful release
5+
# Will be triggered from the release.yaml workflow
6+
workflow_call:
7+
inputs:
8+
tag_name:
9+
required: true
10+
type: string
11+
secrets:
12+
publish_token:
13+
required: true
14+
# In case of problems, let release engineers retry by manually dispatching
15+
# the workflow from the GitHub UI
16+
workflow_dispatch:
17+
inputs:
18+
tag_name:
19+
description: git tag being released
20+
required: true
21+
type: string
22+
jobs:
23+
publish:
24+
uses: bazel-contrib/publish-to-bcr/.github/workflows/[email protected]
25+
with:
26+
draft: false
27+
tag_name: ${{ inputs.tag_name }}
28+
# GitHub repository which is a fork of the upstream where the Pull Request will be opened.
29+
registry_fork: protocolbuffers/bazel-central-registry
30+
permissions:
31+
attestations: write
32+
contents: write
33+
id-token: write
34+
secrets:
35+
# Necessary to push to the BCR fork, and to open a pull request against a registry
36+
publish_token: ${{ secrets.publish_token || secrets.BCR_PUBLISH_TOKEN }}

.github/workflows/release.yaml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Cut a release whenever a new tag is pushed to the repo.
2+
name: Release
3+
on:
4+
# Can be triggered from the tag.yaml workflow
5+
workflow_call:
6+
inputs:
7+
tag_name:
8+
required: true
9+
type: string
10+
secrets:
11+
publish_token:
12+
required: true
13+
# Or, developers can manually push a tag from their clone
14+
push:
15+
tags:
16+
- "v*.*.*"
17+
permissions:
18+
id-token: write
19+
attestations: write
20+
contents: write
21+
jobs:
22+
release:
23+
uses: bazel-contrib/.github/.github/workflows/[email protected]
24+
with:
25+
prerelease: false
26+
release_files: protobuf-javascript-*.tar.gz
27+
tag_name: ${{ inputs.tag_name || github.ref_name }}
28+
secrets: inherit
29+
publish:
30+
needs: release
31+
uses: ./.github/workflows/publish.yaml
32+
with:
33+
tag_name: ${{ inputs.tag_name || github.ref_name }}
34+
secrets:
35+
publish_token: ${{ secrets.publish_token || secrets.BCR_PUBLISH_TOKEN }}

.github/workflows/release_prep.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
#!/usr/bin/env bash
3+
4+
set -o errexit -o nounset -o pipefail
5+
6+
# Set by GH actions, see
7+
# https://docs.github.com/en/actions/learn-github-actions/environment-variables#default-environment-variables
8+
readonly TAG=$1
9+
# The prefix is chosen to match what GitHub generates for source archives.
10+
# This guarantees that users can easily switch from a released artifact to a source archive
11+
# with minimal differences in their code (e.g. strip_prefix remains the same)
12+
readonly PREFIX="protobuf_javascript-${TAG}"
13+
readonly ARCHIVE="${PREFIX}.tar.gz"
14+
15+
# NB: configuration for 'git archive' is in /.gitattributes
16+
git archive --format=tar --prefix=${PREFIX}/ ${TAG} | gzip > $ARCHIVE
17+
SHA=$(shasum -a 256 $ARCHIVE | awk '{print $1}')
18+
19+
# The stdout of this program will be used as the top of the release notes for this release.
20+
cat << EOF
21+
## Using bzlmod with Bazel 7 or later:
22+
23+
Add to your \`MODULE.bazel\` file:
24+
25+
\`\`\`starlark
26+
bazel_dep(name = "protobuf_javascript", version = "${TAG}")
27+
\`\`\`
28+
EOF

MODULE.bazel.lock

Lines changed: 6 additions & 109 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

e2e/bcr/.bazelrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build --cxxopt=-std=c++17 --host_cxxopt=-std=c++17

e2e/bcr/BUILD.bazel

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
load("@protobuf//bazel:proto_library.bzl", "proto_library")
2+
load("@rules_shell//shell:sh_test.bzl", "sh_test")
3+
4+
proto_library(
5+
name = "simple_proto",
6+
srcs = ["simple.proto"],
7+
)
8+
9+
genrule(
10+
name = "simple_js",
11+
srcs = [":simple_proto"],
12+
outs = ["simple.js"],
13+
cmd = """
14+
$(location @protobuf//:protoc) \
15+
--descriptor_set_in=$(location :simple_proto) \
16+
--plugin=protoc-gen-js=$(location @protobuf_javascript//generator:protoc-gen-js) \
17+
--js_out=$(RULEDIR) \
18+
simple.proto
19+
""",
20+
tools = [
21+
"@protobuf//:protoc",
22+
"@protobuf_javascript//generator:protoc-gen-js",
23+
],
24+
)
25+
26+
sh_test(
27+
name = "simple_js_test",
28+
srcs = ["simple_js_test.sh"],
29+
data = [":simple.js"],
30+
)

e2e/bcr/MODULE.bazel

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
"MODULE.bazel file for bcr smoke test"
2+
3+
bazel_dep(name = "rules_shell", version = "0.6.1")
4+
bazel_dep(name = "protobuf", version = "33.0")
5+
bazel_dep(name = "protobuf_javascript", version = "0.0.0", dev_dependency = True)
6+
local_path_override(module_name = "protobuf_javascript", path = "../..")

0 commit comments

Comments
 (0)