Skip to content

v1.3.4

v1.3.4 #33

Workflow file for this run

name: Build and Publish to PyPI
on:
release:
types: [published]
workflow_dispatch: # Allow manual trigger for testing
inputs:
skip_macos:
description: 'Skip macOS builds (useful when macOS builds are failing due to infrastructure issues)'
required: false
default: false
type: boolean
env:
GIT_LFS_SKIP_SMUDGE: 1 # Skip LFS to avoid bandwidth quota issues
jobs:
# Build and publish Linux wheels independently
build_and_publish_linux:
name: Build and Publish Linux wheels
runs-on: ubuntu-22.04
environment:
name: pypi
url: https://pypi.org/p/pyopenmagnetics
permissions:
id-token: write # Required for trusted publishing
if: github.event_name == 'release' || github.event_name == 'workflow_dispatch'
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Cache cibuildwheel
uses: actions/cache@v4
with:
path: ~/.cache/cibuildwheel
key: cibuildwheel-linux-${{ hashFiles('**/pyproject.toml') }}
restore-keys: |
cibuildwheel-linux-
- name: Cache npm
uses: actions/cache@v4
with:
path: ~/.npm
key: linux-npm-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
linux-npm-
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "18"
- name: Install quicktype
shell: bash
run: |
for i in {1..5}; do
npm install -g quicktype && break
if [ $i -lt 5 ]; then
echo "Retry $i failed, waiting 60s..."
sleep 60
fi
done
- name: Install cibuildwheel
run: python -m pip install cibuildwheel==2.21.3
- name: Pre-download virtualenv
shell: bash
run: |
CACHE_DIR="$HOME/.cache/cibuildwheel"
mkdir -p "$CACHE_DIR"
VENV_VERSION="20.26.6"
VENV_FILE="$CACHE_DIR/virtualenv-$VENV_VERSION.pyz"
VENV_URL="https://github.com/pypa/get-virtualenv/blob/$VENV_VERSION/public/virtualenv.pyz?raw=true"
if [[ ! -f "$VENV_FILE" ]]; then
echo "Downloading virtualenv.pyz..."
for i in {1..10}; do
if curl -fsSL --max-time 30 "$VENV_URL" -o "$VENV_FILE"; then
echo "Downloaded successfully"
break
fi
echo "Download attempt $i failed, waiting 60s..."
sleep 60
done
fi
- name: Build wheels
run: python -m cibuildwheel --output-dir wheelhouse
env:
CIBW_BUILD: cp310-* cp311-* cp312-* cp313-*
CIBW_SKIP: "*-win32 *-manylinux_i686 *musllinux* pp*"
CIBW_MANYLINUX_X86_64_IMAGE: manylinux_2_28
CIBW_BEFORE_ALL_LINUX: |
for i in {1..3}; do
(dnf install -y gcc-toolset-13 eigen3-devel && \
source /opt/rh/gcc-toolset-13/enable && \
curl -fsSL --max-time 10 https://rpm.nodesource.com/setup_18.x | bash - && \
dnf install -y nodejs && \
npm install -g quicktype) && break
if [ $i -lt 3 ]; then sleep 60; fi
done
CIBW_ENVIRONMENT_LINUX: PATH=/opt/rh/gcc-toolset-13/root/usr/bin:$PATH LD_LIBRARY_PATH=/opt/rh/gcc-toolset-13/root/usr/lib64:$LD_LIBRARY_PATH
CIBW_BEFORE_BUILD: pip install --default-timeout=60 --retries 5 scikit-build-core cmake ninja pybind11
CIBW_TEST_COMMAND: python -c "import PyOpenMagnetics; print(f'PyOpenMagnetics loaded successfully with {len(dir(PyOpenMagnetics))} functions')"
- name: Publish Linux wheels to PyPI
if: github.event_name == 'release'
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
packages-dir: wheelhouse/
- name: Publish Linux wheels to TestPyPI
if: github.event_name == 'workflow_dispatch'
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
packages-dir: wheelhouse/
# Build and publish Windows wheels independently
build_and_publish_windows:
name: Build and Publish Windows wheels
runs-on: windows-2022
environment:
name: pypi
url: https://pypi.org/p/pyopenmagnetics
permissions:
id-token: write # Required for trusted publishing
if: github.event_name == 'release' || github.event_name == 'workflow_dispatch'
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Cache cibuildwheel
uses: actions/cache@v4
with:
path: C:\Users\runneradmin\AppData\Local\pypa\cibuildwheel\Cache
key: cibuildwheel-windows-${{ hashFiles('**/pyproject.toml') }}
restore-keys: |
cibuildwheel-windows-
- name: Cache npm
uses: actions/cache@v4
with:
path: ~/.npm
key: windows-npm-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
windows-npm-
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "18"
- name: Install quicktype
run: npm install -g quicktype
- name: Install cibuildwheel
run: python -m pip install cibuildwheel==2.21.3
- name: Build wheels
run: python -m cibuildwheel --output-dir wheelhouse
env:
CIBW_BUILD: cp310-* cp311-* cp312-* cp313-*
CIBW_SKIP: "*-win32 *-manylinux_i686 *musllinux* pp*"
CIBW_BEFORE_ALL_WINDOWS: npm install -g quicktype
CIBW_BEFORE_BUILD: pip install --default-timeout=60 --retries 5 scikit-build-core cmake ninja pybind11
CIBW_TEST_COMMAND: python -c "import PyOpenMagnetics; print(f'PyOpenMagnetics loaded successfully with {len(dir(PyOpenMagnetics))} functions')"
- name: Publish Windows wheels to PyPI
if: github.event_name == 'release'
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
packages-dir: wheelhouse/
- name: Publish Windows wheels to TestPyPI
if: github.event_name == 'workflow_dispatch'
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
packages-dir: wheelhouse/
# Build and publish macOS wheels independently
build_and_publish_macos:
name: Build and Publish macOS wheels
runs-on: macos-15
continue-on-error: true # Allow macOS to fail without blocking
environment:
name: pypi
url: https://pypi.org/p/pyopenmagnetics
permissions:
id-token: write # Required for trusted publishing
if: (github.event_name == 'release' || github.event_name == 'workflow_dispatch') && (github.event_name != 'workflow_dispatch' || !inputs.skip_macos)
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Cache cibuildwheel
uses: actions/cache@v4
with:
path: ~/Library/Caches/cibuildwheel
key: cibuildwheel-macos-${{ hashFiles('**/pyproject.toml') }}
restore-keys: |
cibuildwheel-macos-
- name: Cache npm
uses: actions/cache@v4
with:
path: ~/.npm
key: macos-npm-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
macos-npm-
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "18"
- name: Install quicktype
shell: bash
run: |
for i in {1..5}; do
npm install -g quicktype && break
if [ $i -lt 5 ]; then sleep 60; fi
done
- name: Install cibuildwheel
run: python -m pip install cibuildwheel==2.21.3
- name: Build wheels
run: python -m cibuildwheel --output-dir wheelhouse
env:
CIBW_BUILD: cp310-* cp311-* cp312-* cp313-*
CIBW_SKIP: "*-win32 *-manylinux_i686 *musllinux* pp*"
CIBW_BEFORE_ALL_MACOS: |
for i in {1..5}; do
npm install -g quicktype && break
if [ $i -lt 5 ]; then sleep 60; fi
done
CIBW_ENVIRONMENT_MACOS: MACOSX_DEPLOYMENT_TARGET=15.0
CIBW_BEFORE_BUILD: pip install --default-timeout=60 --retries 5 scikit-build-core cmake ninja pybind11
CIBW_TEST_COMMAND: python -c "import PyOpenMagnetics; print(f'PyOpenMagnetics loaded successfully with {len(dir(PyOpenMagnetics))} functions')"
- name: Publish macOS wheels to PyPI
if: github.event_name == 'release'
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
packages-dir: wheelhouse/
- name: Publish macOS wheels to TestPyPI
if: github.event_name == 'workflow_dispatch'
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
packages-dir: wheelhouse/
# Build and publish source distribution independently
build_and_publish_sdist:
name: Build and Publish source distribution
runs-on: ubuntu-22.04
environment:
name: pypi
url: https://pypi.org/p/pyopenmagnetics
permissions:
id-token: write # Required for trusted publishing
if: github.event_name == 'release' || github.event_name == 'workflow_dispatch'
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Cache npm
uses: actions/cache@v4
with:
path: ~/.npm
key: linux-npm-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
linux-npm-
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "18"
- name: Install quicktype
shell: bash
run: |
for i in {1..5}; do
npm install -g quicktype && break
if [ $i -lt 5 ]; then
echo "Retry $i failed, waiting 60s..."
sleep 60
fi
done
- name: Install build
run: python -m pip install build
- name: Build sdist
run: python -m build --sdist
- name: Publish sdist to PyPI
if: github.event_name == 'release'
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
packages-dir: dist/
- name: Publish sdist to TestPyPI
if: github.event_name == 'workflow_dispatch'
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
packages-dir: dist/