Skip to content

Merge pull request #195 from demml/add-default #243

Merge pull request #195 from demml/add-default

Merge pull request #195 from demml/add-default #243

Workflow file for this run

name: Build and Release PyPi and Rust Packages
on:
push:
branches:
- main
release:
types: [published]
permissions:
contents: read
env:
PACKAGE_NAME: scouter
RUSTFLAGS: -C debuginfo=0
PYTHON_VERSION: "3.12"
CARGO_INCREMENTAL: 0
CARGO_NET_RETRY: 10
CARGO_TERM_COLOR: always
PROTOC_VERSION: "33.2"
jobs:
build-sdist:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Protocol Buffers Compiler
uses: arduino/setup-protoc@v3
with:
version: "33.2"
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Build sdist
uses: PyO3/maturin-action@v1
with:
command: sdist
args: --out dist
maturin-version: 1.8.3
rust-toolchain: stable
working-directory: ./py-scouter
- name: Upload sdist
uses: actions/upload-artifact@v4
with:
name: pypi_sdist
path: ./py-scouter/dist
retention-days: 1
build-linux:
name: build - ${{ matrix.runner-type }} - ${{ matrix.manylinux }} - ${{ matrix.target }}
strategy:
fail-fast: false
matrix:
include:
- target: x86_64-unknown-linux-gnu
manylinux: auto
runner-type: ubuntu-latest
runner: ubuntu-latest
docker-options: "-e CI"
- target: aarch64-unknown-linux-gnu
manylinux: "2_28"
runner-type: ubuntu-24.04-arm
runner: ubuntu-24.04-arm
docker-options: "-e CI -e SIMSIMD_DISABLE_SVE=1 -e SIMSIMD_TARGET_SVE=0 -e SIMSIMD_TARGET_SVE2=0"
runs-on: ${{ matrix.runner }}
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- run: pip install -U "twine>=6.1.0" "packaging>=24.2"
- name: Set OPENSSL_DIR environment variable
run: echo "OPENSSL_DIR=/usr" >> $GITHUB_ENV
- name: Build wheel
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.target }}
manylinux: ${{ matrix.manylinux }}
args: --release --out dist
rust-toolchain: stable
docker-options: ${{ matrix.docker-options }}
working-directory: ./py-scouter
before-script-linux: |
# Install required packages
if command -v yum &> /dev/null; then
yum update -y && yum install -y perl-core openssl openssl-devel pkgconfig libatomic
# If we're running on i686 we need to symlink libatomic
# in order to build openssl with -latomic flag.
if [[ ! -d "/usr/lib64" ]]; then
ln -s /usr/lib/libatomic.so.1 /usr/lib/libatomic.so
fi
else
# If we're running on debian-based system.
apt update -y && apt-get install -y libssl-dev openssl pkg-config
fi
# Determine architecture and install CMake
ARCH=$(uname -m)
echo "Detected architecture: $ARCH"
# Install Protocol Buffers Compiler (protoc)
PROTOC_VERSION="33.2"
if [[ "$ARCH" == "x86_64" ]]; then
PROTOC_ARCH="linux-x86_64"
elif [[ "$ARCH" == "aarch64" ]]; then
PROTOC_ARCH="linux-aarch_64"
else
echo "Unsupported architecture for protoc: $ARCH"
exit 1
fi
echo "Installing protoc ${PROTOC_VERSION} for ${PROTOC_ARCH}"
curl -LO "https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-${PROTOC_ARCH}.zip"
unzip "protoc-${PROTOC_VERSION}-${PROTOC_ARCH}.zip" -d /usr/local
rm "protoc-${PROTOC_VERSION}-${PROTOC_ARCH}.zip"
chmod +x /usr/local/bin/protoc
protoc --version
# Install bindgen CLI
cargo install --force --locked bindgen-cli
if [[ "$ARCH" == "x86_64" ]]; then
echo "Downloading CMake for x86_64 architecture"
curl -L https://github.com/Kitware/CMake/releases/download/v3.26.4/cmake-3.26.4-linux-x86_64.sh -o cmake.sh
chmod +x cmake.sh
./cmake.sh --skip-license --prefix=/usr/local
elif [[ "$ARCH" == "aarch64" ]]; then
echo "Downloading CMake for aarch64 architecture"
curl -L https://github.com/Kitware/CMake/releases/download/v3.26.4/cmake-3.26.4-linux-aarch64.sh -o cmake.sh
chmod +x cmake.sh
./cmake.sh --skip-license --prefix=/usr/local
elif [[ "$ARCH" == "i686" ]]; then
echo "Downloading CMake for x86 architecture"
curl -L https://github.com/Kitware/CMake/releases/download/v3.26.4/cmake-3.26.4.tar.gz -o cmake.tar.gz
tar -xzf cmake.tar.gz
cd cmake-3.26.4
./bootstrap --prefix=/usr/local
make -j$(nproc)
make install
cd ..
else
echo "Unsupported architecture: $ARCH"
exit 1
fi
cmake --version
# Set ARM64-specific environment variables for simsimd
if [[ "$ARCH" == "aarch64" ]]; then
echo "Setting up ARM64 build environment"
export SIMSIMD_DISABLE_SVE=1
export SIMSIMD_TARGET_SVE=0
export SIMSIMD_TARGET_SVE2=0
export SIMSIMD_TARGET_SVE_F16=0
export SIMSIMD_TARGET_SVE_BF16=0
export SIMSIMD_TARGET_SVE_I8=0
export CFLAGS="-march=armv8-a"
export CXXFLAGS="-march=armv8-a"
fi
- name: Check dist
working-directory: ./py-scouter
run: ls -lh dist/
- name: Check wheel
working-directory: ./py-scouter
run: twine check --strict dist/*
- uses: actions/upload-artifact@v4
with:
name: pypi_files_ubuntu_${{ matrix.target }}
path: ./py-scouter/dist
retention-days: 1
build-macos:
name: build - macos - (${{ matrix.os}} - ${{ matrix.architecture}})
strategy:
fail-fast: false
matrix:
include:
- os: macos-15-intel
architecture: x86-64
target: x86_64-apple-darwin
- os: macos-15
architecture: aarch64
target: aarch64-apple-darwin
runs-on: ${{ matrix.os}}
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install Protocol Buffers Compiler
uses: arduino/setup-protoc@v3
with:
version: "33.2"
repo-token: ${{ secrets.GITHUB_TOKEN }}
- run: pip install -U "twine>=6.1.0" "packaging>=24.2"
- name: Build wheel
uses: PyO3/maturin-action@v1
with:
command: build
target: ${{ matrix.target }}
args: --release --out dist
rust-toolchain: stable
working-directory: ./py-scouter
- name: Check dist
working-directory: ./py-scouter
run: ls -lh dist/
- name: Check wheel
working-directory: ./py-scouter
run: twine check --strict dist/*
- uses: actions/upload-artifact@v4
with:
name: pypi_files_macos_${{ matrix.target }}
path: ./py-scouter/dist
retention-days: 1
build-windows:
name: build - windows - (${{ matrix.os}} - ${{ matrix.architecture}})
strategy:
fail-fast: false
matrix:
include:
- os: windows-latest
architecture: x86-64
target: x86_64-pc-windows-msvc
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Set up Python
if: matrix.os != 'windows-11-arm'
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install Protocol Buffers Compiler
uses: arduino/setup-protoc@v3
with:
version: "33.2"
repo-token: ${{ secrets.GITHUB_TOKEN }}
- run: pip install -U "twine>=6.1.0" "packaging>=24.2"
- name: Build wheel
uses: PyO3/maturin-action@v1
with:
command: build
target: ${{ matrix.target }}
args: --release --out dist
rust-toolchain: stable
working-directory: ./py-scouter
- name: Check dist
working-directory: ./py-scouter
run: dir dist/
- name: Check wheel
working-directory: ./py-scouter
run: twine check --strict dist/*
- uses: actions/upload-artifact@v4
with:
name: pypi_files_windows_${{ matrix.target }}
path: ./py-scouter/dist
retention-days: 1
inspect-pypi-assets:
needs: [build-linux, build-macos, build-windows, build-sdist]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: get dist artifacts
uses: actions/download-artifact@v4
with:
pattern: pypi_files_*
merge-multiple: true
path: dist
- name: list dist files
run: |
ls -lh dist/
ls -l dist/
echo "`ls dist | wc -l` files"
test-builds-os:
name: test build on ${{ matrix.os }}
needs: [build-linux, build-macos, build-windows, build-sdist]
strategy:
fail-fast: false
matrix:
os: [ubuntu, macos, windows]
runs-on: ${{ matrix.os }}-latest
steps:
- uses: actions/checkout@v4
- name: set up python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Create virtual environment
working-directory: ./py-scouter
run: |
python -m venv .venv
echo "$GITHUB_WORKSPACE/scouter/.venv/bin" >> $GITHUB_PATH
- name: get dist artifacts
uses: actions/download-artifact@v4
with:
pattern: pypi_files_${{ matrix.os }}_*
merge-multiple: true
path: py-scouter/dist
- name: install scouter-ml
working-directory: ./py-scouter
run: |
python3 -m pip install scouter-ml --no-deps --no-index --force-reinstall --find-links dist
pip install -r tests/requirements.txt
pytest --ignore tests/integration --benchmark-skip
python-release:
if: github.event_name == 'release'
name: Release-Python
environment: release
runs-on: ubuntu-latest
needs: [test-builds-os]
steps:
- uses: actions/checkout@v4
- name: install rust stable
uses: dtolnay/rust-toolchain@stable
- name: Check version
working-directory: ./py-scouter
run: |
export VERSION=$(cargo pkgid | cut -d "#" -f2)
echo "version: $VERSION"
echo "tag: $GITHUB_REF_NAME"
test "v$VERSION" "=" "$GITHUB_REF_NAME"
- name: set up python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- run: pip install -U "twine>=6.1.0" "packaging>=24.2"
- name: get dist artifacts
uses: actions/download-artifact@v4
with:
pattern: pypi_files_*
merge-multiple: true
path: dist
- run: twine check --strict dist/*
- name: upload to pypi
run: twine upload dist/*
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
rust-release:
if: github.event_name == 'release'
environment: release
name: Release-Rust
runs-on: ubuntu-latest
needs: [test-builds-os]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: dtolnay/rust-toolchain@stable
- name: cache rust
id: cargo_release_cache
uses: Swatinem/rust-cache@v2
with:
key: ${{ runner.os }}-cargo-release
- name: Switch to main branch
run: git checkout main
- name: Run release-plz
uses: MarcoIeni/[email protected]
with:
command: release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CARGO_REGISTRY_TOKEN: ${{ secrets.CRATES_REGISTRY_TOKEN }}