blob: 8ed5a342dc72dcec3480cdac4e8e189cc592ca71 [file]
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you 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
#
# http://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.
# Publish the mosaic-format Python package to PyPI.
#
# Trigger: push a version tag (e.g. v0.1.0, v0.1.0-rc1).
# Pre-release tags (containing '-') publish to TestPyPI; release tags publish to PyPI.
#
# Token auth: add secrets PYPI_API_TOKEN / TEST_PYPI_API_TOKEN for publishing.
name: Release Python
on:
push:
tags:
- "v[0-9]+.[0-9]+.[0-9]+"
- "v[0-9]+.[0-9]+.[0-9]+-rc[0-9]+"
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }}
cancel-in-progress: true
permissions:
contents: read
jobs:
wheels-linux:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
arch: x86_64
- os: ubuntu-24.04-arm
arch: aarch64
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Build wheels via cibuildwheel
uses: pypa/cibuildwheel@v2.23
with:
package-dir: python
output-dir: wheelhouse
env:
CIBW_BUILD: "cp39-manylinux_${{ matrix.arch }}"
CIBW_MANYLINUX_X86_64_IMAGE: manylinux_2_28
CIBW_MANYLINUX_AARCH64_IMAGE: manylinux_2_28
CIBW_BEFORE_ALL_LINUX: >
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y &&
source $HOME/.cargo/env &&
cargo build --release -p mosaic-ffi &&
cp target/release/libmosaic_ffi.so {package}/mosaic/
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-linux-${{ matrix.arch }}
path: wheelhouse/*.whl
wheels-macos:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: macos-13
target: x86_64-apple-darwin
lib_name: libmosaic_ffi.dylib
- os: macos-latest
target: aarch64-apple-darwin
lib_name: libmosaic_ffi.dylib
steps:
- uses: actions/checkout@v4
- name: Setup Rust toolchain
run: |
rustup update stable
rustup default stable
- name: Build native library
run: cargo build --release -p mosaic-ffi
- name: Copy native library into package
run: cp target/release/${{ matrix.lib_name }} python/mosaic/
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install build tools
run: pip install build wheel setuptools delocate
- name: Build wheel
working-directory: python
run: python -m build --wheel
- name: Repair wheel
run: |
delocate-wheel -w python/dist/repaired python/dist/*.whl
rm python/dist/*.whl
mv python/dist/repaired/*.whl python/dist/
- name: Upload wheel
uses: actions/upload-artifact@v4
with:
name: wheels-${{ matrix.os }}-${{ matrix.target }}
path: python/dist/*.whl
wheels-windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- name: Setup Rust toolchain
run: |
rustup update stable
rustup default stable
- name: Build native library
run: cargo build --release -p mosaic-ffi
- name: Copy native library into package
shell: bash
run: cp target/release/mosaic_ffi.dll python/mosaic/
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install build tools
run: pip install build wheel setuptools
- name: Build wheel
working-directory: python
run: python -m build --wheel
- name: Upload wheel
uses: actions/upload-artifact@v4
with:
name: wheels-windows-x86_64
path: python/dist/*.whl
release:
name: Publish to PyPI
runs-on: ubuntu-latest
permissions:
contents: read
needs: [wheels-linux, wheels-macos, wheels-windows]
if: startsWith(github.ref, 'refs/tags/')
steps:
- uses: actions/download-artifact@v4
with:
pattern: wheels-*
merge-multiple: true
path: dist
- name: Publish to TestPyPI
if: contains(github.ref, '-')
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
skip-existing: true
packages-dir: dist
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
- name: Publish to PyPI
if: ${{ !contains(github.ref, '-') }}
uses: pypa/gh-action-pypi-publish@release/v1
with:
skip-existing: true
packages-dir: dist
password: ${{ secrets.PYPI_API_TOKEN }}