Skip to content

Commit 0a3196b

Browse files
mtsokolcopybara-github
authored andcommitted
GitHub Actions build refactor
This PR cleans up the wheel build process for array_record and migrates changes present in https://github.com/iindyk/array_record/tree/main 20 commits ahead of main. Here's a job that I ran for it: https://github.com/mtsokol/array_record/actions/runs/16147213833 Ported from #162 PiperOrigin-RevId: 781211931
1 parent 85ceac5 commit 0a3196b

17 files changed

+319
-142
lines changed

.bazelrc

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# This workflow builds ArrayRecord wheels and uploads them as artifacts.
2+
3+
name: Build & Publish Template
4+
5+
on:
6+
workflow_call:
7+
inputs:
8+
pypi_project_url:
9+
required: true
10+
type: string
11+
is_nightly:
12+
required: true
13+
type: boolean
14+
15+
defaults:
16+
run:
17+
shell: bash
18+
19+
permissions:
20+
contents: read
21+
22+
jobs:
23+
build-and-test:
24+
name: "Python ${{ matrix.python-version }} on ${{ matrix.os }}"
25+
runs-on: "${{ matrix.os }}"
26+
27+
strategy:
28+
fail-fast: false
29+
matrix:
30+
python-version: ["3.10", "3.11", "3.12", "3.13"]
31+
os: [ubuntu-22.04, ubuntu-22.04-arm, macos-14]
32+
33+
env:
34+
USE_BAZEL_VERSION: "7.2.1"
35+
steps:
36+
- name: Set up Bazel
37+
uses: bazel-contrib/setup-bazel@0.15.0
38+
- name: Check Bazel installation
39+
run: |
40+
which bazel
41+
bazel version
42+
- name: Set up Python
43+
uses: actions/setup-python@v5
44+
with:
45+
python-version: ${{ matrix.python-version }}
46+
- uses: "actions/checkout@v3"
47+
- name: Create directory
48+
run: |
49+
mkdir -p /tmp/array_record
50+
cp -r . /tmp/array_record
51+
- name: Build package
52+
run: |
53+
set -xe
54+
export PYTHON_VERSION=${{ matrix.python-version }}
55+
export PYTHON_MAJOR_VERSION=$(echo $PYTHON_VERSION | cut -d. -f1)
56+
export PYTHON_MINOR_VERSION=$(echo $PYTHON_VERSION | cut -d. -f2)
57+
export BAZEL_VERSION="7.2.1"
58+
export OUTPUT_DIR="/tmp/array_record"
59+
export SOURCE_DIR="/tmp/array_record"
60+
. "${SOURCE_DIR}"'/oss/runner_common.sh'
61+
build_and_test_array_record
62+
- name: Upload ArrayRecord artifacts
63+
uses: actions/upload-artifact@v4
64+
with:
65+
name: built-array-record-wheels-${{ matrix.os }}-${{ matrix.python-version }}
66+
path: /tmp/array_record/all_dist/*.whl
67+
68+
publish-wheel:
69+
runs-on: ubuntu-22.04
70+
needs: build-and-test
71+
permissions:
72+
id-token: write
73+
environment:
74+
name: pypi
75+
url: ${{ inputs.pypi_project_url }}
76+
steps:
77+
- name: Download ArrayRecord artifacts
78+
uses: actions/download-artifact@v4
79+
with:
80+
pattern: built-array-record-wheels-*
81+
path: dist/
82+
merge-multiple: true
83+
- name: Publish package distributions to PyPI
84+
uses: pypa/gh-action-pypi-publish@release/v1
85+
with:
86+
attestations: false
87+
verbose: true
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: Build and Publish Release
2+
3+
on: workflow_dispatch
4+
5+
jobs:
6+
call-workflow:
7+
uses: ./.github/workflows/build_and_publish_template.yml
8+
permissions:
9+
contents: read
10+
id-token: write
11+
with:
12+
pypi_project_url: https://pypi.org/project/array-record
13+
is_nightly: false

.github/workflows/python-tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
runs-on: ubuntu-latest
1010
strategy:
1111
matrix:
12-
python-version: ['3.9', '3.10', '3.11']
12+
python-version: ['3.10', '3.11', '3.12', '3.13']
1313
env:
1414
DOCKER_BUILDKIT: 1
1515
TMP_FOLDER: /tmp/array_record
@@ -19,7 +19,7 @@ jobs:
1919
run: |
2020
docker build --progress=plain --no-cache \
2121
--build-arg PYTHON_VERSION=${{ matrix.python-version }} \
22-
-t array_record:latest - < oss/build.Dockerfile
22+
-t array_record:latest - < oss/Dockerfile
2323
- name: Build wheels and test
2424
run: |
2525
docker run --rm -a stdin -a stdout -a stderr \

BUILD

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
# ArrayRecord is a new file format for IO intensive applications.
22
# It supports efficient random access and various compression algorithms.
33

4-
load("@rules_python//python:pip.bzl", "compile_pip_requirements")
4+
load("@python//3.10:defs.bzl", compile_pip_requirements_3_10 = "compile_pip_requirements")
5+
load("@python//3.11:defs.bzl", compile_pip_requirements_3_11 = "compile_pip_requirements")
6+
load("@python//3.12:defs.bzl", compile_pip_requirements_3_12 = "compile_pip_requirements")
7+
load("@python//3.13:defs.bzl", compile_pip_requirements_3_13 = "compile_pip_requirements")
58

69

710
package(default_visibility = ["//visibility:public"])
@@ -15,8 +18,26 @@ py_library(
1518
srcs = ["setup.py"],
1619
)
1720

18-
compile_pip_requirements(
19-
name = "requirements",
20-
requirements_in = "requirements.in",
21-
requirements_txt = "requirements_lock.txt",
21+
compile_pip_requirements_3_10(
22+
name = "requirements_3_10",
23+
requirements_in = "test_requirements.in",
24+
requirements_txt = "test_requirements_lock_3_10.txt",
25+
)
26+
27+
compile_pip_requirements_3_11(
28+
name = "requirements_3_11",
29+
requirements_in = "test_requirements.in",
30+
requirements_txt = "test_requirements_lock_3_11.txt",
31+
)
32+
33+
compile_pip_requirements_3_12(
34+
name = "requirements_3_12",
35+
requirements_in = "test_requirements.in",
36+
requirements_txt = "test_requirements_lock_3_12.txt",
37+
)
38+
39+
compile_pip_requirements_3_13(
40+
name = "requirements_3_13",
41+
requirements_in = "test_requirements.in",
42+
requirements_txt = "test_requirements_lock_3_13.txt",
2243
)

MODULE.bazel

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414

1515
# TODO(fchern): automate version string alignment with setup.py
16-
VERSION = "0.6.0"
16+
VERSION = "0.7.3"
1717

1818
module(
1919
name = "array_record",
@@ -32,21 +32,52 @@ bazel_dep(name = "eigen", version = "3.4.0.bcr.3")
3232
bazel_dep(name = "riegeli", version = "0.0.0-20241218-3385e3c")
3333
bazel_dep(name = "pybind11_bazel", version = "2.12.0")
3434

35-
PYTHON_VERSION = "3.10"
35+
http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
3636

37-
python = use_extension("@rules_python//python/extensions:python.bzl", "python")
38-
python.toolchain(
39-
ignore_root_user_error = True, # Required for our containerized CI environments.
40-
python_version = PYTHON_VERSION,
37+
http_archive(
38+
name = "pybind11",
39+
build_file = "@pybind11_bazel//:pybind11.BUILD",
40+
sha256 = "201966a61dc826f1b1879a24a3317a1ec9214a918c8eb035be2f30c3e9cfbdcb",
41+
strip_prefix = "pybind11-2.10.3",
42+
urls = ["https://github.com/pybind/pybind11/archive/refs/tags/v2.10.3.zip"],
4143
)
4244

45+
SUPPORTED_PYTHON_VERSIONS = [
46+
"3.10",
47+
"3.11",
48+
"3.12",
49+
"3.13",
50+
]
51+
52+
DEFAULT_PYTHON_VERSION = "3.10"
53+
54+
python_configure = use_extension("@pybind11_bazel//:python_configure.bzl", "extension")
55+
use_repo(python_configure, "local_config_python")
56+
57+
python = use_extension("@rules_python//python/extensions:python.bzl", "python")
58+
59+
[
60+
python.toolchain(
61+
ignore_root_user_error = True,
62+
is_default = python_version == DEFAULT_PYTHON_VERSION,
63+
python_version = python_version,
64+
)
65+
for python_version in SUPPORTED_PYTHON_VERSIONS
66+
]
67+
68+
use_repo(python, python = "python_versions")
69+
4370
pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
4471

4572
# requirements_lock.txt is generated by
4673
# bazel run //:requirements.update
47-
pip.parse(
48-
hub_name = "pypi",
49-
python_version = PYTHON_VERSION,
50-
requirements_lock = "//:requirements_lock.txt",
51-
)
74+
[
75+
pip.parse(
76+
hub_name = "pypi",
77+
python_version = version,
78+
requirements_lock = "test_requirements_lock_" + version.replace(".", "_") + ".txt",
79+
)
80+
for version in SUPPORTED_PYTHON_VERSIONS
81+
]
82+
5283
use_repo(pip, "pypi")

cpp/array_record_reader.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class ChunkOffset {
8080
public:
8181
virtual ~ChunkOffset() {}
8282
virtual uint64_t operator[](size_t idx) const = 0;
83-
virtual size_t size() const = 0;
83+
virtual uint64_t size() const = 0;
8484
bool empty() const { return size() == 0; }
8585
};
8686

oss/.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# Bazel outputs
7+
bazel-array_record
8+
bazel-bin
9+
bazel-out
10+
bazel-testlogs
11+
12+
MODULE.bazel.lock
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ ARG AUDITWHEEL_PLATFORM
66
FROM quay.io/pypa/${AUDITWHEEL_PLATFORM}
77

88
ARG PYTHON_VERSION
9-
ARG PYTHON_BIN
109
ARG BAZEL_VERSION
1110

1211
ENV DEBIAN_FRONTEND=noninteractive
1312

1413
RUN ulimit -n 1024 && yum install -y rsync
15-
ENV PATH="${PYTHON_BIN}:${PATH}"
14+
ENV PYTHON_BIN_PATH=/opt/python/cp${PYTHON_VERSION}-cp${PYTHON_VERSION}/bin
15+
ENV PATH="${PYTHON_BIN_PATH}:${PATH}"
16+
17+
ENV PYTHON_BIN=${PYTHON_BIN_PATH}/python
1618

1719
# Download the correct bazel version and make sure it's on path.
1820
RUN BAZEL_ARCH_SUFFIX="$(uname -m | sed s/aarch64/arm64/)" \
@@ -21,7 +23,7 @@ RUN BAZEL_ARCH_SUFFIX="$(uname -m | sed s/aarch64/arm64/)" \
2123

2224
# Install dependencies needed for array_record.
2325
RUN --mount=type=cache,target=/root/.cache \
24-
${PYTHON_BIN}/python -m pip install -U \
26+
$PYTHON_BIN -m pip install -U \
2527
absl-py \
2628
auditwheel \
2729
etils[epath] \

oss/build_whl.sh

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,12 @@
11
#!/bin/bash
2+
23
# Build wheel for the python version specified by $PYTHON_VERSION.
34
# Optionally, can set the environment variable $PYTHON_BIN to refer to a
45
# specific python interpreter.
56

67
set -e -x
78

8-
if [ -z ${PYTHON_BIN} ]; then
9-
if [ -z ${PYTHON_VERSION} ]; then
10-
PYTHON_BIN=$(which python3)
11-
else
12-
PYTHON_BIN=$(which python${PYTHON_VERSION})
13-
fi
14-
fi
15-
16-
PYTHON_MAJOR_VERSION=$(${PYTHON_BIN} -c 'import sys; print(sys.version_info.major)')
17-
PYTHON_MINOR_VERSION=$(${PYTHON_BIN} -c 'import sys; print(sys.version_info.minor)')
18-
PYTHON_VERSION="${PYTHON_MAJOR_VERSION}.${PYTHON_MINOR_VERSION}"
19-
export PYTHON_VERSION="${PYTHON_VERSION}"
9+
OUTPUT_DIR="${OUTPUT_DIR:-/tmp/array_record}"
2010

2111
function write_to_bazelrc() {
2212
echo "$1" >> .bazelrc
@@ -31,6 +21,8 @@ function main() {
3121
write_to_bazelrc "build --host_cxxopt=-std=c++17"
3222
write_to_bazelrc "build --experimental_repo_remote_exec"
3323
write_to_bazelrc "build --python_path=\"${PYTHON_BIN}\""
24+
write_to_bazelrc "test --python_path=\"${PYTHON_BIN}\""
25+
PLATFORM="$(uname)"
3426

3527
if [ -n "${CROSSTOOL_TOP}" ]; then
3628
write_to_bazelrc "build --crosstool_top=${CROSSTOOL_TOP}"
@@ -39,8 +31,8 @@ function main() {
3931

4032
export USE_BAZEL_VERSION="${BAZEL_VERSION}"
4133
bazel clean
42-
bazel build ...
43-
bazel test --verbose_failures --test_output=errors ...
34+
bazel build ... --action_env MACOSX_DEPLOYMENT_TARGET='11.0' --action_env PYTHON_BIN_PATH="${PYTHON_BIN}"
35+
bazel test --verbose_failures --test_output=errors ... --action_env PYTHON_BIN_PATH="${PYTHON_BIN}"
4436

4537
DEST="/tmp/array_record/all_dist"
4638
# Create the directory, then do dirname on a non-existent file inside it to
@@ -68,7 +60,11 @@ function main() {
6860

6961
pushd ${TMPDIR}
7062
echo $(date) : "=== Building wheel"
71-
${PYTHON_BIN} setup.py bdist_wheel --python-tag py3${PYTHON_MINOR_VERSION}
63+
if [ "$(uname)" = "Darwin" ]; then
64+
"$PYTHON_BIN" setup.py bdist_wheel --python-tag py3"${PYTHON_MINOR_VERSION}" --plat-name macosx_11_0_"$(uname -m)"
65+
else
66+
"$PYTHON_BIN" setup.py bdist_wheel --python-tag py3"${PYTHON_MINOR_VERSION}"
67+
fi
7268

7369
if [ -n "${AUDITWHEEL_PLATFORM}" ]; then
7470
echo $(date) : "=== Auditing wheel"
@@ -83,4 +79,4 @@ function main() {
8379
echo $(date) : "=== Output wheel file is in: ${DEST}"
8480
}
8581

86-
main
82+
main

0 commit comments

Comments
 (0)