Use cargo-dist to release the Rust CLI (#1107) #710
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Python - build package | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- "main" | |
pull_request: | |
paths: | |
- "python/**" | |
- "rust/**" | |
- "tests_data/**" | |
- ".github/workflows/python-*" | |
schedule: | |
- cron: "12 3 * * 4" # Run everything once per week. | |
- cron: "12 3 * * 1" # Refresh the cache an additional time. | |
release: | |
types: [created] | |
permissions: | |
contents: read | |
jobs: | |
build-wheels: | |
runs-on: ${{ matrix.platform.runner }} | |
strategy: | |
matrix: | |
platform: | |
- runner: ubuntu-latest | |
target: x86_64 | |
- runner: windows-latest | |
target: x64 | |
- runner: macos-14 | |
target: aarch64 | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Setup Python | |
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # pin@v5 | |
with: | |
python-version: "3.12" | |
- name: Install uv | |
run: curl -LsSf https://astral.sh/uv/0.5.22/install.sh | sh | |
- if: matrix.platform.runner == 'ubuntu-latest' | |
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3 | |
with: | |
path: rust/onnx/runtime/build/Linux | |
key: maturin-${{ matrix.platform.target }}-${{ hashFiles('rust/onnx/build.sh') }} | |
- run: python3 ./python/scripts/fix_package_version.py | |
- if: matrix.platform.runner == 'ubuntu-latest' | |
name: Build wheels | |
uses: PyO3/maturin-action@v1 | |
with: | |
target: ${{ matrix.platform.target }} | |
args: --release --out=../dist | |
before-script-linux: "${{ github.workspace }}/rust/onnx/maturin.sh" | |
manylinux: 2_28 | |
working-directory: python | |
- if: matrix.platform.runner != 'ubuntu-latest' | |
name: Build wheels | |
uses: PyO3/maturin-action@v1 | |
with: | |
target: ${{ matrix.platform.target }} | |
args: --release --out=../dist | |
working-directory: python | |
- name: Upload wheels | |
uses: actions/upload-artifact@v4 | |
with: | |
name: wheel-${{ matrix.platform.runner }}-${{ matrix.platform.target }} | |
path: dist | |
# Download, install, and test the wheels with different versions of python | |
test-wheels: | |
needs: [build-wheels] | |
runs-on: ${{ matrix.platform.runner }} | |
if: github.event.schedule != '12 3 * * 1' | |
strategy: | |
# We want to know in which exact situation the tests fail | |
fail-fast: false | |
matrix: | |
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"] | |
platform: | |
- runner: ubuntu-latest | |
target: x86_64 | |
- runner: windows-latest | |
target: x64 | |
- runner: macos-14 | |
target: aarch64 | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/download-artifact@v4 | |
with: | |
name: wheel-${{ matrix.platform.runner }}-${{ matrix.platform.target }} | |
path: dist | |
- name: Setup Python | |
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # pin@v5 | |
with: | |
python-version: "${{ matrix.python-version }}" | |
- name: Install uv | |
run: curl -LsSf https://astral.sh/uv/0.5.22/install.sh | sh | |
- if: matrix.platform.runner != 'windows-latest' | |
name: Check that `uv add magika.whl` works | |
run: | | |
mkdir /tmp/test-uv | |
cp -vR dist/*.whl /tmp/test-uv | |
cd /tmp/test-uv | |
uv init | |
uv add ./$(\ls -1 *.whl | head -n 1) | |
- if: matrix.platform.runner == 'windows-latest' | |
name: Check that `uv add magika.whl` works | |
shell: pwsh | |
run: | | |
mkdir C:\test-uv | |
Copy-Item -Path dist\*.whl -Destination C:\test-uv | |
cd C:\test-uv | |
$env:PATH += ";$HOME/.local/bin" | |
uv init | |
$wheel = Get-ChildItem -Filter *.whl | Select-Object -ExpandProperty Name | |
uv add ".\$wheel" | |
- name: Install the wheel | |
run: python3 -m pip install $(python -c "import glob; print(glob.glob('dist/*.whl')[0])") | |
- run: magika --version | |
- run: "python3 -c 'import magika; m = magika.Magika(); print(m)'" | |
- run: magika -r tests_data/basic | |
- run: python3 ./python/scripts/run_quick_test_magika_cli.py | |
- run: python3 ./python/scripts/run_quick_test_magika_module.py | |
build-pure-python-wheel-and-sdist: | |
runs-on: ubuntu-latest | |
if: github.event.schedule != '12 3 * * 1' | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Install uv | |
run: curl -LsSf https://astral.sh/uv/0.5.22/install.sh | sh | |
- run: uv run ./scripts/prepare_pyproject_for_pure_python_wheel.py | |
working-directory: python | |
- name: Build pure python wheel and source distribution | |
run: uv build --out-dir ../dist | |
working-directory: python | |
- name: Upload pure python wheel | |
uses: actions/upload-artifact@v4 | |
with: | |
name: wheel-pure-python | |
path: dist/*.whl | |
- name: Upload sdist | |
uses: actions/upload-artifact@v4 | |
with: | |
name: sdist | |
path: dist/*.tar.gz | |
# Download, install, and test the pure python wheel on multiple platforms | |
test-pure-python-wheel: | |
needs: [build-pure-python-wheel-and-sdist] | |
runs-on: ${{ matrix.platform.runner }} | |
if: github.event.schedule != '12 3 * * 1' | |
strategy: | |
# We want to know in which exact situation the tests fail | |
fail-fast: false | |
matrix: | |
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"] | |
platform: | |
- runner: ubuntu-latest | |
target: x86_64 | |
- runner: windows-latest | |
target: x64 | |
- runner: macos-14 | |
target: aarch64 | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/download-artifact@v4 | |
with: | |
name: wheel-pure-python | |
path: dist | |
- name: Setup Python | |
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # pin@v5 | |
with: | |
python-version: "${{ matrix.python-version }}" | |
- name: Install uv | |
run: curl -LsSf https://astral.sh/uv/0.5.22/install.sh | sh | |
- if: matrix.platform.runner != 'windows-latest' | |
name: Check that `uv add magika.whl` works | |
run: | | |
mkdir /tmp/test-uv | |
cp -vR dist/*.whl /tmp/test-uv | |
cd /tmp/test-uv | |
uv init | |
uv add ./$(\ls -1 *.whl | head -n 1) | |
- if: matrix.platform.runner == 'windows-latest' | |
name: Check that `uv add magika.whl` works | |
shell: pwsh | |
run: | | |
mkdir C:\test-uv | |
Copy-Item -Path dist\*.whl -Destination C:\test-uv | |
cd C:\test-uv | |
$env:PATH += ";$HOME/.local/bin" | |
uv init | |
$wheel = Get-ChildItem -Filter *.whl | Select-Object -ExpandProperty Name | |
uv add ".\$wheel" | |
- name: Install the wheel | |
run: python3 -m pip install $(python -c "import glob; print(glob.glob('dist/*.whl')[0])") | |
# Check that the magika script points to the placeholder raising a warning | |
- run: magika --version | grep -C10 WARNING | grep -C10 magika-python-client | |
# Check that the fallback magika's python client can be run | |
- run: magika-python-client -r tests_data/basic | |
# Check that the results of the python's client are correct | |
- run: python3 ./python/scripts/run_quick_test_magika_cli.py --client-path magika-python-client | |
# Test the python module | |
- run: "python3 -c 'import magika; m = magika.Magika(); print(m)'" | |
- run: python3 ./python/scripts/run_quick_test_magika_module.py | |
test-sdist: | |
needs: [build-pure-python-wheel-and-sdist] | |
runs-on: ${{ matrix.platform.runner }} | |
if: github.event.schedule != '12 3 * * 1' | |
strategy: | |
# We want to know in which exact situation the tests fail | |
fail-fast: false | |
matrix: | |
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"] | |
platform: | |
- runner: ubuntu-latest | |
target: x86_64 | |
- runner: windows-latest | |
target: x64 | |
- runner: macos-14 | |
target: aarch64 | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/download-artifact@v4 | |
with: | |
name: sdist | |
path: dist | |
- name: Setup Python | |
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # pin@v5 | |
with: | |
python-version: "${{ matrix.python-version }}" | |
- name: Install uv | |
run: curl -LsSf https://astral.sh/uv/0.5.22/install.sh | sh | |
- if: matrix.platform.runner != 'windows-latest' | |
name: Check that `uv add magika.tar.gz` works | |
run: | | |
mkdir /tmp/test-uv | |
cp -vR dist/*.tar.gz /tmp/test-uv | |
cd /tmp/test-uv | |
uv init | |
uv add ./$(\ls -1 *.tar.gz | head -n 1) | |
- if: matrix.platform.runner == 'windows-latest' | |
name: Check that `uv add magika.tar.gz` works | |
shell: pwsh | |
run: | | |
mkdir C:\test-uv | |
Copy-Item -Path dist\*.tar.gz -Destination C:\test-uv | |
cd C:\test-uv | |
$env:PATH += ";$HOME\.local\bin" | |
uv init | |
$sdist = Get-ChildItem -Filter *.tar.gz | Select-Object -ExpandProperty Name | |
uv add ".\$sdist" | |
- name: Install the sdist | |
run: python3 -m pip install $(python -c "import glob; print(glob.glob('dist/*.tar.gz')[0])") | |
# Check that the magika script points to the placeholder raising a warning | |
- run: magika --version | grep -C10 WARNING | grep -C10 magika-python-client | |
# Check that the fallback magika's python client can be run | |
- run: magika-python-client -r tests_data/basic | |
# Check that the results of the python's client are correct | |
- run: python3 ./python/scripts/run_quick_test_magika_cli.py --client-path magika-python-client | |
# Test the python module | |
- run: "python3 -c 'import magika; m = magika.Magika(); print(m)'" | |
- run: python3 ./python/scripts/run_quick_test_magika_module.py |