Skip to content

Fix portable wheel builds and validate wheels in PR CI #240

Fix portable wheel builds and validate wheels in PR CI

Fix portable wheel builds and validate wheels in PR CI #240

Workflow file for this run

# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
name: Pre-release Tesseract
on:
pull_request:
push:
branches:
- main
permissions:
contents: read
jobs:
create_version:
runs-on: ubuntu-24.04
outputs:
version: ${{ steps.create_version.outputs.version }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
with:
python-version: '3.11'
- id: create_version
name: Create version
run: |
version="$(python _version.py).dev$(date '+%Y%m%d%H%M%S')"
echo "$version"
echo "version=$version" >> "$GITHUB_OUTPUT"
build_linux_wheels:
name: Linux wheels (${{ matrix.python-version }})
runs-on: ubuntu-24.04
container: quay.io/pypa/manylinux_2_28_x86_64@sha256:f854c50adf7b7a325bc4794316f3758d387a41d61f9e2ebca0f26c7dc8f761d4
needs: [create_version]
strategy:
fail-fast: true
matrix:
include:
- python-version: '3.11'
python-abi: cp311-cp311
target-version: cp311
- python-version: '3.12'
python-abi: cp312-cp312
target-version: cp312
- python-version: '3.13'
python-abi: cp313-cp313
target-version: cp313
env:
PYTHON_BIN: /opt/python/${{ matrix.python-abi }}/bin/python
TARGET_PYTHON: ${{ matrix.python-version }}
TARGET_VERSION: ${{ matrix.target-version }}
VERSION: ${{ needs.create_version.outputs.version }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Set up Bazel
uses: bazel-contrib/setup-bazel@c5acdfb288317d0b5c0bbd7a396a3dc868bb0f86 # 0.19.0
with:
bazelisk-version: 1.29.0
bazelisk-cache: true
repository-cache: true
- name: Build, repair, and validate Linux wheel
run: |
export PATH="$(dirname "$PYTHON_BIN"):$PATH"
python _update_bazel_py_version.py "$TARGET_PYTHON"
bazel build --jobs=1 --config=wheel \
--define TARGET_VERSION="$TARGET_VERSION" \
--define VERSION="$VERSION" \
:tesseract_decoder_wheel
mkdir -p wheelhouse
auditwheel repair \
--plat manylinux_2_28_x86_64 \
bazel-bin/*.whl \
--wheel-dir wheelhouse
auditwheel show wheelhouse/*.whl
"$PYTHON_BIN" -m venv /tmp/tesseract-wheel-test
/tmp/tesseract-wheel-test/bin/python -m pip install \
--only-binary=:all: \
wheelhouse/*.whl
(
cd /tmp
/tmp/tesseract-wheel-test/bin/python - <<'PY'
import tesseract_decoder
from tesseract_decoder import demutil
print(tesseract_decoder.__file__)
print("wheel import passed")
PY
)
- name: Upload Linux wheel
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: python-wheels-linux-${{ matrix.python-version }}
path: wheelhouse/*.whl
build_macos_wheels:
name: macOS wheels (${{ matrix.python-version }})
runs-on: macos-14
needs: [create_version]
strategy:
fail-fast: true
matrix:
include:
- python-version: '3.11'
target-version: cp311
- python-version: '3.12'
target-version: cp312
- python-version: '3.13'
target-version: cp313
env:
TARGET_PYTHON: ${{ matrix.python-version }}
TARGET_VERSION: ${{ matrix.target-version }}
VERSION: ${{ needs.create_version.outputs.version }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Set up Python
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
with:
python-version: ${{ matrix.python-version }}
- name: Set up Bazel
uses: bazel-contrib/setup-bazel@c5acdfb288317d0b5c0bbd7a396a3dc868bb0f86 # 0.19.0
with:
bazelisk-cache: true
repository-cache: true
- name: Build and validate macOS wheel
run: |
python _update_bazel_py_version.py "$TARGET_PYTHON"
bazel build --jobs=1 --config=wheel \
--define TARGET_VERSION="$TARGET_VERSION" \
--define VERSION="$VERSION" \
:tesseract_decoder_wheel
mkdir -p wheelhouse
cp bazel-bin/*.whl wheelhouse/
python -m venv /tmp/tesseract-wheel-test
/tmp/tesseract-wheel-test/bin/python -m pip install \
--only-binary=:all: \
wheelhouse/*.whl
(
cd /tmp
/tmp/tesseract-wheel-test/bin/python - <<'PY'
import tesseract_decoder
from tesseract_decoder import demutil
print(tesseract_decoder.__file__)
print("wheel import passed")
PY
)
- name: Upload macOS wheel
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: python-wheels-macos-${{ matrix.python-version }}
path: wheelhouse/*.whl
release-wheels:
name: Publish all wheels
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
needs: [build_linux_wheels, build_macos_wheels]
runs-on: ubuntu-24.04
steps:
- name: Download build artifacts
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
pattern: python-wheels-*
merge-multiple: true
path: wheelhouse/
- name: Publish package to testpypi
uses: pypa/gh-action-pypi-publish@dc37677b2e1c63e2034f94d8a5b11f265b73ba33 # v1.14.2
with:
repository-url: https://test.pypi.org/legacy/
user: __token__
password: ${{ secrets.TEST_PYPI_TOKEN }}
packages-dir: wheelhouse/
verbose: true
- name: Publish package to pypi
uses: pypa/gh-action-pypi-publish@dc37677b2e1c63e2034f94d8a5b11f265b73ba33 # v1.14.2
with:
user: __token__
password: ${{ secrets.PYPI_TOKEN }}
packages-dir: wheelhouse/