Skip to content

Commit b646d4c

Browse files
authored
chore: fix e2e (#3)
* chore: fix e2e * chore: fix * chore: copy code review improvements from upstream bazelbuild/rules_proto#205
1 parent 4d62f0b commit b646d4c

File tree

5 files changed

+21
-9
lines changed

5 files changed

+21
-9
lines changed

.github/workflows/mirror_protoc_release.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ on:
33
# Trigger manually in the UI
44
workflow_dispatch:
55
# Trigger daily at 06:10 UTC
6+
# Note, the create-pull-request action only sends a PR if there's a code change,
7+
# so a no-op execution of the mirror_protoc_releases script on most days will
8+
# not create a pull request.
69
schedule:
710
- cron: "10 6 * * *"
811

MODULE.bazel

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ register_toolchains(
3939
)
4040

4141
# Shows how a typical Python user fetches all the dependencies of their app, including the protobuf runtime
42-
pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
42+
pip = use_extension(
43+
"@rules_python//python/extensions:pip.bzl",
44+
"pip",
45+
dev_dependency = True,
46+
)
4347
pip.parse(
4448
hub_name = "pypi",
4549
python_version = "3.11",

protoc/extensions.bzl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ def _proto_extension_impl(module_ctx):
1919
if mod.is_root:
2020
protoc_toolchains(toolchain.name, register = False, google_protobuf = toolchain.google_protobuf, version = toolchain.version)
2121
root_name = toolchain.name
22-
else:
23-
registrations[toolchain.name] = toolchain.version
24-
for name, version in registrations.items():
22+
elif toolchain.name not in registrations.keys():
23+
registrations[toolchain.name] = toolchain
24+
for name, toolchain in registrations.items():
2525
if name != root_name:
26-
protoc_toolchains(name, register = False, version = version)
26+
protoc_toolchains(name, register = False, google_protobuf = toolchain.google_protobuf, version = toolchain.version)
2727

2828
protoc = module_extension(
2929
implementation = _proto_extension_impl,

protoc/private/mirror_protoc_release.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ map(select(.tag_name == $version))[0]
3030
# Create a file that looks like a checksums.txt from a shasum command, i.e.
3131
# sha384-RVFu8PJJCOSXwYTqH7FyWRSgsP1AAjcEa+VViddVTgtd9wYvZjQoQ8jmlFxwfFw+ protobuf-26.0-rc3.tar.gz
3232
# sha384-JYSXGTSBfwUU6UzqazUTkT3lTZDzx10YdaNQYjojrT7X1Ro1fA+T4tjJw0e8UISV protobuf-26.0-rc3.zip
33+
#
34+
# Note, this follows https://en.wikipedia.org/wiki/Trust_on_first_use
35+
# in that we assume that a release is not tampered for 24h until we mirror it, then afterward
36+
# we are guaranteed that whatever we initially trusted does not change.
3337
CHECKSUMS=$(mktemp)
3438
for url in $(jq --arg version $VERSION --raw-output "$DOWNLOAD_URLS_FILTER" <$RELEASES); do
3539
sha=$(curl -sSL $url | shasum -b -a 384 | awk "{ print \$1 }" | xxd -r -p | base64)

protoc/toolchain.bzl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def _google_protobuf_alias_repo_impl(rctx):
2323
alias(name = "any_proto", actual = "@{0}//:any_proto")
2424
""".format(rctx.attr.alias_to))
2525

26-
_google_protobuf_alias_repo = repository_rule(_google_protobuf_alias_repo_impl, attrs={"alias_to": attr.string()})
26+
_google_protobuf_alias_repo = repository_rule(_google_protobuf_alias_repo_impl, attrs = {"alias_to": attr.string()})
2727

2828
def protoc_toolchains(name, version, google_protobuf = None, alias_to = "osx-aarch_64", register = True):
2929
"""A utility method to load all Protobuf toolchains.
@@ -42,13 +42,14 @@ def protoc_toolchains(name, version, google_protobuf = None, alias_to = "osx-aar
4242

4343
for platform in PROTOC_PLATFORMS.keys():
4444
prebuilt_protoc_repo(
45-
# We must replace hyphen with underscore to workaround rules_python
45+
# We must replace hyphen with underscore to workaround rules_python
4646
# File "/output-base/external/rules_python~override/python/private/proto/py_proto_library.bzl", line 62, column 17, in _py_proto_aspect_impl
47-
# Error in fail: Cannot generate Python code for a .proto whose path contains '-'
47+
# Error in fail: Cannot generate Python code for a .proto whose path contains '-'
4848
# (external/_main~protoc~toolchains_protoc_hub.osx-aarch_64/include/google/protobuf/any.proto).
4949
name = ".".join([name, platform.replace("-", "_")]),
5050
platform = platform,
51-
version = version)
51+
version = version,
52+
)
5253
protoc_toolchains_repo(name = name, user_repository_name = name)
5354
if register:
5455
native.register_toolchains("@{}//:all".format(name))

0 commit comments

Comments
 (0)