Skip to content

Commit 2782f68

Browse files
alexeagleaaylward
andauthored
Fix download filename for RC versions (#37)
* fix filename for rc versions * chore: restore example * chore: format --------- Co-authored-by: Andy Aylward <[email protected]>
1 parent 606c851 commit 2782f68

File tree

3 files changed

+50
-3
lines changed

3 files changed

+50
-3
lines changed

protoc/private/BUILD.bazel

+3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
2+
load(":prebuilt_protoc_toolchain_test.bzl", "release_version_to_artifact_name_test_suite")
23

34
bzl_library(
45
name = "versions",
56
srcs = ["versions.bzl"],
67
visibility = ["//protoc:__subpackages__"],
78
)
9+
10+
release_version_to_artifact_name_test_suite()

protoc/private/prebuilt_protoc_toolchain.bzl

+16-3
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,27 @@ GOOGLE_PROTOBUF_DEP_EDGES = {
2222
"wrappers": [],
2323
}
2424

25+
def release_version_to_artifact_name(release_version, platform):
26+
# versions have a "v" prefix like "v28.0"
27+
stripped_version = release_version.removeprefix("v")
28+
29+
# release candidate versions like "v29.0-rc3" have artifact names
30+
# like "protoc-29.0-rc-3-osx-x86_64.zip"
31+
artifact_version = stripped_version.replace("rc", "rc-")
32+
33+
return "{}-{}-{}.zip".format(
34+
"protoc",
35+
artifact_version,
36+
platform,
37+
)
38+
2539
def _prebuilt_protoc_repo_impl(rctx):
2640
release_version = rctx.attr.version
2741
if release_version == "LATEST":
2842
release_version = PROTOC_VERSIONS.keys()[0]
2943

30-
filename = "{}-{}-{}.zip".format(
31-
"protoc",
32-
release_version.removeprefix("v"),
44+
filename = release_version_to_artifact_name(
45+
release_version,
3346
rctx.attr.platform,
3447
)
3548
url = "https://github.com/protocolbuffers/protobuf/releases/download/{}/{}".format(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"""Unit test suite for version-to-artifact-name resolution helper.
2+
3+
Based on the example at https://bazel.build/rules/testing#testing-starlark-utilities
4+
"""
5+
6+
load("@bazel_skylib//lib:unittest.bzl", "asserts", "unittest")
7+
load(":prebuilt_protoc_toolchain.bzl", "release_version_to_artifact_name")
8+
load(":versions.bzl", "PROTOC_VERSIONS")
9+
10+
def _release_version_to_artifact_name_test_impl(ctx):
11+
env = unittest.begin(ctx)
12+
count = 0
13+
14+
for release_version in PROTOC_VERSIONS:
15+
artifact_name = release_version_to_artifact_name(release_version, "linux-x86_64")
16+
artifact_dict = PROTOC_VERSIONS[release_version]
17+
18+
# there should be a linux-x86_64 artifact in every release
19+
asserts.true(env, artifact_name in artifact_dict, "'{}' not found for release version '{}'".format(artifact_name, release_version))
20+
count += 1
21+
22+
asserts.true(env, count > 0, "no versions tested")
23+
return unittest.end(env)
24+
25+
release_version_to_artifact_name_test = unittest.make(_release_version_to_artifact_name_test_impl)
26+
27+
def release_version_to_artifact_name_test_suite():
28+
unittest.suite(
29+
"release_version_to_artifact_name_tests",
30+
release_version_to_artifact_name_test,
31+
)

0 commit comments

Comments
 (0)