Skip to content

Commit 9ee2b08

Browse files
authored
Publish binaries on releases (#292)
Fixes #290 Fixes #289 --- ### Type of change - Bug fix (change which fixes an issue) ### Test plan - Covered by existing test cases - Manual testing; please provide instructions so we can reproduce:
1 parent 334dd44 commit 9ee2b08

File tree

19 files changed

+310
-81
lines changed

19 files changed

+310
-81
lines changed

.github/workflows/ci.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,10 @@ jobs:
3535
steps:
3636
- uses: actions/checkout@v4
3737
- run: patch --dry-run -p1 < .bcr/patches/*.patch
38+
39+
test-release:
40+
runs-on: ubuntu-latest
41+
steps:
42+
- uses: actions/checkout@v4
43+
- working-directory: e2e/use_release
44+
run: ./minimal_download_test.sh

MODULE.bazel

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@ bazel_dep(name = "bazel_skylib", version = "1.4.2")
1313
bazel_dep(name = "rules_python", version = "0.29.0")
1414
bazel_dep(name = "platforms", version = "0.0.7")
1515

16-
archive_override(
17-
module_name = "rules_python",
18-
urls = "https://github.com/bazelbuild/rules_python/archive/52381415be9d3618130f02a821aef50de1e3af09.tar.gz",
19-
integrity = "sha256-pYfEFNWqygSEElDYgJsuIeDYn9oll/rZB0GcR+6rirA=",
20-
strip_prefix = "rules_python-52381415be9d3618130f02a821aef50de1e3af09",
21-
)
16+
tools = use_extension("//py:extensions.bzl", "py_tools")
17+
tools.rules_py_tools()
18+
use_repo(tools, "rules_py_tools")
2219

2320
register_toolchains(
21+
"@rules_py_tools//:all",
22+
23+
# Register the "from source" toolchains last, so there's no accidental dependency on Rust
24+
# For manual testing: comment these out to force use of pre-built binaries.
2425
"@aspect_rules_py//py/private/toolchain/venv/...",
2526
"@aspect_rules_py//py/private/toolchain/unpack/...",
2627
)

e2e/use_release/.bazelversion

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../.bazelversion

e2e/use_release/BUILD.bazel

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
load("@aspect_rules_py//py:defs.bzl", "py_binary")
2+
3+
py_binary(
4+
name = "main",
5+
srcs = ["__main__.py"],
6+
)

e2e/use_release/MODULE.bazel

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
bazel_dep(name = "aspect_rules_py", version = "0.7.0")
2+
3+
local_path_override(
4+
module_name = "aspect_rules_py",
5+
path = "../..",
6+
)
7+
8+
tools = use_extension("@aspect_rules_py//py:extensions.bzl", "py_tools")
9+
tools.rules_py_tools(is_prerelease = False)
10+
use_repo(tools, "rules_py_tools")

e2e/use_release/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Test releases
2+
3+
This is currently a manual test we can perform _after_ publishing a release.
4+
5+
It asserts that the release_prep.sh constructed a correct tarball of the ruleset (the "Bazel Module")
6+
and that usage of a release has the correct minimal toolchain behaviors.

e2e/use_release/WORKSPACE.bazel

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Override http_archive for local testing
2+
local_repository(
3+
name = "aspect_rules_py",
4+
path = "../..",
5+
)
6+
7+
# Fetches the rules_py dependencies.
8+
# If you want to have a different version of some dependency,
9+
# you should fetch it *before* calling this.
10+
# Alternatively, you can skip calling this function, so long as you've
11+
# already fetched all the dependencies.
12+
load("@aspect_rules_py//py:repositories.bzl", "rules_py_dependencies", "rules_py_toolchains")
13+
14+
rules_py_dependencies(register_toolchains = False)
15+
16+
# Force use of pre-built release binaries regardless of the content of /tools/version.bzl
17+
rules_py_toolchains(is_prerelease = False)
18+
19+
# "Installation" for rules_python
20+
load("@rules_python//python:repositories.bzl", "py_repositories", "python_register_toolchains")
21+
22+
python_register_toolchains(
23+
name = "python_toolchain",
24+
python_version = "3.9",
25+
)
26+
27+
py_repositories()

e2e/use_release/WORKSPACE.bzlmod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# This file replaces WORKSPACE.bazel under --enable_bzlmod

e2e/use_release/__main__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
print("hello world")
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/env bash
2+
3+
set -o errexit -o pipefail -o nounset
4+
5+
OS="$(uname | tr '[:upper:]' '[:lower:]')"
6+
ARCH="$(arch)"
7+
ALLOWED="rules_py_tools.${OS}_${ARCH}"
8+
if [ "$ARCH" == "x86_64" ]; then
9+
ALLOWED="rules_py_tools.${OS}_amd64"
10+
fi
11+
12+
# This test references pre-built artifacts from a prior release.
13+
# Will need to bump this version in the future when there are breaking changes.
14+
export RULES_PY_RELEASE_VERSION=0.7.0
15+
16+
#############
17+
# Test bzlmod
18+
(
19+
cd ../..
20+
patch -p1 < .bcr/patches/*.patch
21+
)
22+
OUTPUT_BASE=$(mktemp -d)
23+
output=$(bazel "--output_base=$OUTPUT_BASE" run --enable_bzlmod //:main)
24+
if [[ "$output" != "hello world" ]]; then
25+
>&2 echo "ERROR: bazel command did not produce expected output"
26+
exit 1
27+
fi
28+
externals=$(ls $OUTPUT_BASE/external)
29+
30+
if echo "$externals" | grep -v "${ALLOWED}" | grep -v ".marker" | grep rules_py_tools.
31+
then
32+
>&2 echo "ERROR: rules_py binaries were fetched for platform other than ${ALLOWED}"
33+
exit 1
34+
fi
35+
if echo "$externals" | grep rust
36+
then
37+
>&2 echo "ERROR: we fetched a rust repository"
38+
exit 1
39+
fi
40+
41+
#############
42+
# Test WORKSPACE
43+
OUTPUT_BASE=$(mktemp -d)
44+
output=$(bazel "--output_base=$OUTPUT_BASE" run --noenable_bzlmod //:main)
45+
if [[ "$output" != "hello world" ]]; then
46+
>&2 echo "ERROR: bazel command did not produce expected output"
47+
exit 1
48+
fi
49+
50+
externals=$(ls $OUTPUT_BASE/external)
51+
52+
if echo "$externals" | grep -v "${ALLOWED}" | grep -v ".marker" | grep rules_py_tools.
53+
then
54+
>&2 echo "ERROR: rules_py binaries were fetched for platform other than ${ALLOWED}"
55+
exit 1
56+
fi
57+
if echo "$externals" | grep rust
58+
then
59+
>&2 echo "ERROR: we fetched a rust repository"
60+
exit 1
61+
fi

0 commit comments

Comments
 (0)