Skip to content

Commit a6c8d66

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 a6c8d66

20 files changed

Lines changed: 375 additions & 190 deletions

.bazelrc

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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: false
10+
type: string
11+
upload_wheels:
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+
if: ${{ inputs.upload_wheels }}
70+
runs-on: ubuntu-22.04
71+
needs: build-and-test
72+
permissions:
73+
id-token: write
74+
environment:
75+
name: pypi
76+
url: ${{ inputs.pypi_project_url }}
77+
steps:
78+
- name: Download ArrayRecord artifacts
79+
uses: actions/download-artifact@v4
80+
with:
81+
pattern: built-array-record-wheels-*
82+
path: dist/
83+
merge-multiple: true
84+
- name: Publish package distributions to PyPI
85+
uses: pypa/gh-action-pypi-publish@release/v1
86+
with:
87+
attestations: false
88+
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+
upload_wheels: true

.github/workflows/python-tests.yml

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,7 @@ on:
55
branches: [main]
66

77
jobs:
8-
test:
9-
runs-on: ubuntu-latest
10-
strategy:
11-
matrix:
12-
python-version: ['3.9', '3.10', '3.11']
13-
env:
14-
DOCKER_BUILDKIT: 1
15-
TMP_FOLDER: /tmp/array_record
16-
steps:
17-
- uses: actions/checkout@v2
18-
- name: Build Docker image
19-
run: |
20-
docker build --progress=plain --no-cache \
21-
--build-arg PYTHON_VERSION=${{ matrix.python-version }} \
22-
-t array_record:latest - < oss/build.Dockerfile
23-
- name: Build wheels and test
24-
run: |
25-
docker run --rm -a stdin -a stdout -a stderr \
26-
--env PYTHON_VERSION=${{ matrix.python-version }} \
27-
--volume ${GITHUB_WORKSPACE}:${TMP_FOLDER} --name array_record array_record:latest \
28-
bash oss/build_whl.sh
29-
- name: Install in a blank Docker and test the import in Python
30-
run: |
31-
docker run --rm -a stdin -a stdout -a stderr \
32-
--env PYTHON_VERSION=${{ matrix.python-version }} \
33-
--volume ${GITHUB_WORKSPACE}:/root \
34-
python:${{ matrix.python-version }} bash -c "
35-
ARRAY_RECORD_VERSION=\$(python /root/setup.py --version 2>&1 /dev/null)
36-
SHORT_PYTHON_VERSION=\${PYTHON_VERSION//./}
37-
ARRAY_RECORD_WHEEL=\"/root/all_dist/array_record-\${ARRAY_RECORD_VERSION}-py\${SHORT_PYTHON_VERSION}-none-any.whl\"
38-
python -m pip install \${ARRAY_RECORD_WHEEL} &&
39-
python -c 'import array_record' &&
40-
python -c 'from array_record.python import array_record_data_source'
41-
"
8+
call-workflow:
9+
uses: ./.github/workflows/build_and_publish_template.yml
10+
with:
11+
upload_wheels: false

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: 34 additions & 13 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",
@@ -22,31 +22,52 @@ module(
2222
)
2323

2424
bazel_dep(name = "rules_proto", version = "7.0.2")
25-
bazel_dep(name = "rules_python", version = "0.40.0")
25+
bazel_dep(name = "rules_python", version = "0.37.0")
2626
bazel_dep(name = "platforms", version = "0.0.10")
27-
bazel_dep(name = "protobuf", version = "24.4") # aligns with pygrain
27+
bazel_dep(name = "protobuf", version = "28.3")
2828
bazel_dep(name = "googletest", version = "1.15.2")
2929
bazel_dep(name = "abseil-cpp", version = "20240722.0")
3030
bazel_dep(name = "abseil-py", version = "2.1.0")
3131
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+
SUPPORTED_PYTHON_VERSIONS = [
36+
"3.10",
37+
"3.11",
38+
"3.12",
39+
"3.13",
40+
]
41+
42+
DEFAULT_PYTHON_VERSION = "3.10"
43+
44+
python_configure = use_extension("@pybind11_bazel//:python_configure.bzl", "extension")
45+
use_repo(python_configure, "local_config_python")
3646

3747
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,
41-
)
48+
49+
[
50+
python.toolchain(
51+
ignore_root_user_error = True,
52+
is_default = python_version == DEFAULT_PYTHON_VERSION,
53+
python_version = python_version,
54+
)
55+
for python_version in SUPPORTED_PYTHON_VERSIONS
56+
]
57+
58+
use_repo(python, python = "python_versions")
4259

4360
pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
4461

4562
# requirements_lock.txt is generated by
4663
# bazel run //:requirements.update
47-
pip.parse(
48-
hub_name = "pypi",
49-
python_version = PYTHON_VERSION,
50-
requirements_lock = "//:requirements_lock.txt",
51-
)
64+
[
65+
pip.parse(
66+
hub_name = "pypi",
67+
python_version = version,
68+
requirements_lock = "test_requirements_lock_" + version.replace(".", "_") + ".txt",
69+
)
70+
for version in SUPPORTED_PYTHON_VERSIONS
71+
]
72+
5273
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/README.md

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,29 @@
1-
# Steps to build a new array_record pip package
1+
# Steps to build and publish a new `array_record` PyPI package
22

3-
1. Update the version number in setup.py
3+
`array_record` supports automatic publishing to PyPI via GitHub Actions.
4+
Once you're ready to create a new release you need to:
45

5-
2. In the root folder, run
6+
1. Update the version number in `setup.py`.
67

7-
```
8-
./oss/build_whl.sh
9-
```
10-
to use the current `python3` version. Otherwise, optionally set
11-
```
12-
PYTHON_VERSION=3.9 ./oss/build_whl.sh
13-
```
8+
2. Go to [GitHub Actions page](https://github.com/google/array_record/actions),
9+
select `Build and Publish Release` workflow, and run it. It will spin up a
10+
few test jobs, and once all of them complete successfully, a `publish-wheel`
11+
will start.
1412

15-
3. Wheels are in `all_dist/`.
13+
3. On completion you should notice a new release on
14+
https://pypi.org/project/array-record/#history.
15+
16+
---
17+
18+
If you want to build a wheel locally in your development environment in the root
19+
folder, run:
20+
21+
```sh
22+
./oss/build_whl.sh
23+
```
24+
to use the current `python3` version. Otherwise, optionally set:
25+
```sh
26+
PYTHON_VERSION=3.9 ./oss/build_whl.sh
27+
```
28+
29+
Wheels are in `all_dist/`.

0 commit comments

Comments
 (0)