Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/preview.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:

- name: Test python
run: |
bazel test --incompatible_use_python_toolchains=false --python_path=$(which python) //libs/wrappers/python:rtbot_test
bazelisk test --incompatible_use_python_toolchains=false --python_path=$(which python) //libs/wrappers/python:rtbot_test

- name: Test javascript
run: bazelisk test //libs/wrappers/javascript:test
91 changes: 51 additions & 40 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,9 @@ jobs:
- name: Test finance
run: |
bazelisk test //libs/finance/test
# - name: Test python
# run: |
# # TODO: make sure we don't have to build the wheel and install it
# # in order to make the test to pass
# bazelisk build //libs/core/wrappers/python:rtbot_wheel
# pip install --force-reinstall dist/bin/libs/core/wrappers/python/rtbot-_VERSION_-py3-none-manylinux2014_x86_64.whl
# bazelisk test //libs/core/wrappers/python:rtbot_test
- name: Test python
run: |
bazelisk test --incompatible_use_python_toolchains=false --python_path=$(which python) //libs/wrappers/python:rtbot_test
- name: Test javascript
run: |
bazelisk test //libs/wrappers/javascript:test
Expand Down Expand Up @@ -93,13 +89,12 @@ jobs:
path: dist/bin/libs/api/jsonschema

build_wheels:
name: Build wheel on ${{ matrix.os }}
name: Build wheel on ${{ matrix.os }} Python ${{ matrix.python-version }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-20.04, macOS-11, windows-2019]
# TODO: add more python versions later, when we can afford the cost
#python: [3.11]
os: [ubuntu-20.04, macOS-12]
python-version: ["3.10", "3.11", "3.12", "3.13"]
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2.2.4
Expand All @@ -109,21 +104,49 @@ jobs:
- args: [--frozen-lockfile]
- uses: actions/setup-python@v4
with:
python-version: 3.11 #${{ matrix.python }}
python-version: ${{ matrix.python-version }}
- name: Mount bazel caches
uses: actions/cache@v3
with:
path: |
"~/.cache/bazel"
key: bazel-cache-${{ matrix.os }}
key: bazel-cache-${{ matrix.os }}-py${{ matrix.python-version }}
- uses: bazelbuild/setup-bazelisk@v2
- name: Build wheel
run: |
bazelisk build --stamp //libs/wrappers/python:rtbot_wheel
- name: Rename wheel with platform tag
run: |
cd dist/bin/libs/wrappers/python/
WHEEL_FILE="rtbot.whl"
if [ -f "$WHEEL_FILE" ]; then
# Extract version from wheel metadata
VERSION=$(python -c "
import zipfile, re
with zipfile.ZipFile('$WHEEL_FILE', 'r') as z:
for name in z.namelist():
if '.dist-info/METADATA' in name:
# Extract version from rtbot-VERSION.dist-info/METADATA
dist_info_dir = name.split('/')[0]
version = dist_info_dir.replace('rtbot-', '').replace('.dist-info', '')
print(version)
break
")
# Determine platform tag
if [ "${{ runner.os }}" = "Linux" ]; then
PLATFORM="manylinux2014_x86_64"
else
PLATFORM="macosx_10_9_x86_64"
fi
# Create properly named wheel
NEW_NAME="rtbot-${VERSION}-py3-none-${PLATFORM}.whl"
cp "$WHEEL_FILE" "$NEW_NAME"
echo "Created wheel: $NEW_NAME"
fi
- uses: actions/upload-artifact@v3
with:
name: wheel-${{ matrix.os }}.tar
path: dist/bin/libs/wrappers/python/rtbot-*.whl
name: wheel-${{ matrix.os }}-py${{ matrix.python-version }}
path: dist/bin/libs/wrappers/python/rtbot-*-py3-none-*.whl

publish:
needs:
Expand All @@ -149,18 +172,12 @@ jobs:
run: |
GIT_TAG=${{ github.ref_name }}
echo "version=${GIT_TAG:1}" >> $GITHUB_OUTPUT
- uses: actions/download-artifact@v3
with:
name: wheel-ubuntu-20.04.tar
path: wheel-linux
- uses: actions/download-artifact@v3
with:
name: wheel-macOS-11.tar
path: wheel-macos
- uses: actions/download-artifact@v3
# Download all wheel artifacts
- name: Download all wheel artifacts
uses: actions/download-artifact@v3
with:
name: wheel-windows-2019.tar
path: wheel-windows
path: wheels/
pattern: wheel-*
- uses: actions/download-artifact@v3
with:
name: npm-wasm.tar
Expand All @@ -173,18 +190,14 @@ jobs:
with:
name: jsonschema.tar
path: jsonschema
- name: Patch files before publishing
- name: Organize wheels for release
run: |
ls -l
cd wheel-linux
mv rtbot-_VERSION_-py3-none-manylinux2014_x86_64.whl rtbot-${{ steps.version.outputs.version }}-py3-none-manylinux2014_x86_64.whl
cd ..
cd wheel-macos
mv rtbot-_VERSION_-py3-none-macosx_10_7_x86_64.whl rtbot-${{ steps.version.outputs.version }}-py3-none-macosx_10_7_x86_64.whl
cd ..
cd wheel-windows
mv rtbot-_VERSION_-py3-none-win_amd64.whl rtbot-${{ steps.version.outputs.version }}-py3-none-win_amd64.whl
cd ..
ls -la wheels/
# Create directories for organizing wheels
mkdir -p wheel-organized
# Copy all wheels to organized directory
find wheels/ -name "*.whl" -exec cp {} wheel-organized/ \;
ls -la wheel-organized/
# copy repo readme to main npm package
cp README.md ./npm-rtbot
# package npm files, which will be used on the github release
Expand All @@ -208,7 +221,5 @@ jobs:
files: |
*.tar.gz
jsonschema/*
wheel-linux/*
wheel-macos/*
wheel-windows/*
wheel-organized/*
fail_on_unmatched_files: true
16 changes: 16 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ load("@aspect_rules_js//js:defs.bzl", "js_library")
load("@aspect_rules_ts//ts:defs.bzl", "ts_config")
load("@npm//:defs.bzl", "npm_link_all_packages")
load("@aspect_rules_js//npm:defs.bzl", "npm_link_package")
load("@bazel_skylib//rules:write_file.bzl", "write_file")
load("@aspect_bazel_lib//lib:expand_template.bzl", "expand_template")

package(default_visibility = ["//visibility:public"])

Expand Down Expand Up @@ -35,3 +37,17 @@ js_library(
name = "package_json",
srcs = ["package.json"],
)

# Global version computation that can be reused across all targets
write_file(
name = "version_tmpl",
out = "version.txt.tmpl",
content = ["{{RTBOT_VERSION}}"],
)

expand_template(
name = "version",
out = "version.txt",
stamp_substitutions = {"{{RTBOT_VERSION}}": "{{RTBOT_VERSION}}"},
template = ":version_tmpl",
)
21 changes: 13 additions & 8 deletions libs/wrappers/python/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ load("@pybind11_bazel//:build_defs.bzl", "pybind_extension")
load("@rules_python//python:packaging.bzl", "py_package", "py_wheel")
load("//tools/generator:generator.bzl", "rtbot_generate")
load("@aspect_bazel_lib//lib:copy_to_directory.bzl", "copy_to_directory")
load("@aspect_bazel_lib//lib:expand_template.bzl", "expand_template")
load("@bazel_skylib//rules:write_file.bzl", "write_file")
load("@py_deps//:requirements.bzl", "requirement")

package(default_visibility = ["//visibility:public"])
Expand Down Expand Up @@ -68,25 +70,28 @@ copy_to_directory(
}),
)

genrule(
name = "version",
outs = ["version.txt"],
cmd = "cat bazel-out/stable-status.txt | grep '^VERSION ' | cut -d' ' -f2 > $@",
stamp = 1,
)
# Use global version from root BUILD.bazel

py_wheel(
name = "rtbot_wheel",
name = "rtbot_wheel_base",
distribution = "rtbot",
python_tag = "py3",
stamp = 1,
strip_path_prefixes = [
"libs/wrappers/python",
],
version = "0.1.0", # We'll need to read from version file in setup.py
version = "{RTBOT_VERSION}", # Dynamic version from workspace status
deps = [":copy"],
)

genrule(
name = "rtbot_wheel",
srcs = [":rtbot_wheel_base", "//:version"],
outs = ["rtbot.whl"],
cmd = "cp $(location :rtbot_wheel_base) $(location rtbot.whl)",
stamp = 1,
)

py_test(
name = "rtbot_test",
srcs = ["rtbot_test.py"],
Expand Down
Loading
Loading