name: Python tests
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
release:
types: [published]
workflow_dispatch:
jobs:
test:
name: Test on ${{ matrix.os }} / Python ${{ matrix.python-version }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: [ "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Create environment
run: |
python -m pip install --upgrade pip
python -m pip install virtualenv
python -m virtualenv venv
- name: Install system dependencies (Linux)
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y libssl-dev pkg-config
- name: Install dependencies (Windows)
if: runner.os == 'Windows'
run: |
venv\Scripts\activate.ps1
python -m pip install pytest maturin numpy
maturin develop --features pyo3
- name: Install dependencies (Unix)
if: runner.os != 'Windows'
shell: bash
run: |
source venv/bin/activate
python -m pip install pytest maturin numpy
maturin develop --features pyo3
- name: Run tests (Windows)
if: runner.os == 'Windows'
run: |
venv\Scripts\activate.ps1
pytest
- name: Run tests (Unix)
if: runner.os != 'Windows'
shell: bash
run: |
source venv/bin/activate
pytest
- name: Run example scripts (Windows)
if: runner.os == 'Windows'
run: |
venv\Scripts\activate.ps1
python examples/python/material_example.py
python examples/python/materials_example.py
python examples/python/nuclide_example.py
python examples/python/use_in_python.py
- name: Run example scripts (Unix)
if: runner.os != 'Windows'
shell: bash
run: |
source venv/bin/activate
python examples/python/material_example.py
python examples/python/materials_example.py
python examples/python/nuclide_example.py
python examples/python/use_in_python.py
build_wheels:
name: Build wheels on ${{ matrix.os }} - Python ${{ matrix.python-version }}
runs-on: ${{ matrix.os }}
needs: test
if: ${{ startsWith(github.ref, 'refs/tags/') }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
steps:
- uses: actions/checkout@v4
- name: Install system dependencies (Linux for wheel build)
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y libssl-dev pkg-config
- name: Set up Python ${{ matrix.python-version }} (non-Linux only)
if: runner.os != 'Linux'
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install build dependencies (non-Linux)
if: runner.os != 'Linux'
run: |
python -m pip install --upgrade pip
python -m pip install maturin
- name: Build wheel (Linux manylinux 2_17 via action)
if: runner.os == 'Linux'
uses: PyO3/maturin-action@v1
with:
manylinux: 2_17
args: --release --features pyo3 -i python${{ matrix.python-version }} --out wheelhouse
before-script-linux: |
yum update -y
yum install -y openssl-devel
- name: Build wheel (non-Linux)
if: runner.os != 'Linux'
run: |
maturin build --release --features pyo3 -i python${{ matrix.python-version }} --out wheelhouse
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-${{ matrix.os }}-${{ matrix.python-version }}
path: ./wheelhouse/*.whl
publish_to_pypi:
name: Publish to PyPI
needs: [build_wheels]
runs-on: ubuntu-latest
if: ${{ startsWith(github.ref, 'refs/tags/') }}
environment:
name: pypi
url: https://pypi.org/p/materials-for-mc
permissions:
id-token: write
steps:
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
pattern: "wheels-*"
path: dist
merge-multiple: true
- name: List wheels
run: ls -1 dist
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: dist/