Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
226 changes: 12 additions & 214 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,230 +1,28 @@
name: Build

on:
workflow_dispatch:
push:
branches:
- develop/*
pull_request:
branches:
- master
release:
types: [ published ]

env:
PYTHON_VERSIONS: "3.10,3.11,3.12,3.13,3.14"

concurrency:
cancel-in-progress: false
# This creates different concurrency groups depending on the trigger
# For PRs: uses the PR number (e.g., "build-pr-123")
# For branch pushes: uses the branch name (e.g., "build-develop/feature-x")
# For releases: uses the release tag plus a unique run ID so each release runs independently
# For manual dispatches: uses a unique run ID so each dispatch runs independently
group: ${{ github.event_name == 'pull_request' && format('build-pr-{0}', github.event.pull_request.number) || github.event_name == 'push' && format('build-{0}', github.ref) || github.event_name == 'release' && format('build-release-{0}-{1}', github.event.release.tag_name, github.run_id) || format('build-dispatch-{0}', github.run_id) }}

defaults:
run:
shell: bash
# PRs get one group per PR number; releases get one group per tag, so a release
# build never queues behind or cancels an unrelated PR build.
group: ${{ github.event_name == 'pull_request' && format('build-pr-{0}', github.event.pull_request.number) || format('build-release-{0}', github.event.release.tag_name) }}

jobs:
setup:
runs-on: ubuntu-latest
outputs:
python-versions: ${{ steps.set-matrix.outputs.python-versions }}
cibw-build: ${{ steps.set-matrix.outputs.cibw-build }}
steps:
- id: set-matrix
run: |
# Convert "3.10,3.11,3.12" to ["3.10","3.11","3.12"]
python_array=$(echo '["${{ env.PYTHON_VERSIONS }}"]' | sed 's/,/","/g')
echo "python-versions=$python_array" >> $GITHUB_OUTPUT

# Convert "3.10,3.11,3.12" to "cp310-* cp311-* cp312-*"
cibw=$(echo "${{ env.PYTHON_VERSIONS }}" | sed 's/\.//g; s/,/ /g; s/\([0-9]*\)/cp\1-*/g')
echo "cibw-build=$cibw" >> $GITHUB_OUTPUT

build_wheels_windows:
name: Build wheels on Windows
needs: setup
runs-on: windows-latest
strategy:
fail-fast: False
matrix:
python-version: ${{ fromJSON(needs.setup.outputs.python-versions) }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: true

- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Build wheels
run: |
python -m pip install -U pip numpy swig wheel setuptools
python setup.py bdist_wheel -d dist
ls -al ./dist

- name: Place wheels in artifacts folder
uses: actions/upload-artifact@v4
with:
name: windows-${{ matrix.python-version }}
path: ./dist/*.whl

build_wheels_unix:
name: Build wheels on ${{ matrix.os }}
needs: setup
runs-on: ${{ matrix.os }}
strategy:
fail-fast: False
matrix:
os: [ ubuntu-latest, ubuntu-24.04-arm, macos-latest, macos-14 ]
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: true

- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: '3.11'

- name: Build wheels
env:
# only build CPython-3.10+ and skip 32-bit builds
CIBW_BUILD: ${{ needs.setup.outputs.cibw-build }}
CIBW_SKIP: "*-manylinux_i686 *-musllinux*"
# use latest build; manylinux_2_28 ships gcc>=12 (manylinux2014's
# gcc 10.2 is too old for numpy>=2.5 source builds)
CIBW_MANYLINUX_X86_64_IMAGE: quay.io/pypa/manylinux_2_28_x86_64
CIBW_MANYLINUX_AARCH64_IMAGE: quay.io/pypa/manylinux_2_28_aarch64
CIBW_BEFORE_ALL_MACOS: brew install swig
CIBW_BEFORE_BUILD: pip install numpy swig
run: |
python -m pip install -U pip cibuildwheel
python -m cibuildwheel --output-dir dist
ls -R dist

- name: Place wheels in artifacts folder
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.os }}
path: ./dist/*.whl

test-wheels:
name: Test wheels
needs: [ setup, build_wheels_windows, build_wheels_unix ]
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ windows-latest, ubuntu-latest, ubuntu-24.04-arm, macos-latest, macos-14 ]
python-version: ${{ fromJSON(needs.setup.outputs.python-versions) }}

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: true
- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Retrieve packages
uses: actions/download-artifact@v4
with:
path: dist

- name: List items
run: |
ls -alR dist

- name: Test Package Installation
run: |
python -m pip install --upgrade pip

# list all files in the dist folder
ls -R dist

# finds path to the right wheel or source file to install later
os=$(echo ${{ runner.os }} | awk '{print tolower($0)}' | head -c3)

# version refers to the python version. So 3.8 -> 38
version=$(echo ${{ matrix.python-version }} | sed 's/\.//g')

if [[ "${{ matrix.os }}" == "windows-latest" ]]; then
chunk="windows-*"
else
chunk="${{matrix.os}}"
fi

echo "Runner OS: ${{ runner.os }}"
echo "os : ${os}"
echo "version : ${version}"
echo "chunk : ${chunk}"

# this finds files like
# nlopt-2.6.2-cp36-cp36m-win_amd64.whl
# nlopt-2.6.2-cp36-cp36m-manylinux10_amd64.whl
# nlopt-2.7.1-cp310-cp310-win_amd64.whl
file=$(find dist/${chunk} -name "nlopt-*${version}*${os}*.whl" -type f);

echo "Installing file: ${file}"

pip install ${file}
python extern/nlopt/test/t_python.py

deploy:
name: Deploy packages
runs-on: ubuntu-latest
needs: test-wheels
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
build:
name: Build & test wheels
uses: ./.github/workflows/wc-build.yml
permissions:
id-token: write
contents: read

steps:
- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Retrieve packages
uses: actions/download-artifact@v4
with:
path: dist

- name: Install twine
run: |
pip install twine
pip install -U packaging

- name: Move files to top level directory
run: |
ls -ltR dist
python - << EOF
from pathlib import Path
import shutil

d = Path('dist')
for f in d.rglob('*.whl'):
shutil.move(f, d / f.name)

for f in d.iterdir():
if f.is_dir():
shutil.rmtree(f)

EOF

- name: Upload packages to testpypi
if: ${{ !startsWith(github.ref, 'refs/tags/') }}
run: python -m twine upload --skip-existing --repository testpypi dist/* --verbose

- name: Upload packages to pypi
if: startsWith(github.ref, 'refs/tags/')
run: python -m twine upload --skip-existing dist/* --verbose
with:
os: "windows-latest,ubuntu-latest,ubuntu-24.04-arm,macos-latest,macos-14"
python-versions: "3.10,3.11,3.12,3.13,3.14"
# PRs just build/test wheels, no publish; a published release goes to prod pypi.
# A testpypi dry-run publish is available on demand via manual-deploy.yml.
target: ${{ github.event_name == 'release' && 'pypi' || 'none' }}
123 changes: 123 additions & 0 deletions .github/workflows/manual-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
name: Manual Deploy

on:
workflow_dispatch:
inputs:
target:
description: "Where to publish"
type: choice
options:
- testpypi
- pypi
- none
default: testpypi
version-suffix:
description: "Optional version suffix, e.g. 'dev123' or 'rc1' -> 2.11.0.dev123. Leave blank to auto-generate one for testpypi."
type: string
default: ""
os_windows-latest:
description: "OS: windows-latest"
type: boolean
default: false
os_ubuntu-latest:
description: "OS: ubuntu-latest"
type: boolean
default: false
os_ubuntu-24.04-arm:
description: "OS: ubuntu-24.04-arm"
type: boolean
default: false
os_macos-latest:
description: "OS: macos-latest"
type: boolean
default: false
os_macos-14:
description: "OS: macos-14"
type: boolean
default: false
py3.10:
description: "Python 3.10"
type: boolean
default: false
py3.11:
description: "Python 3.11"
type: boolean
default: false
py3.12:
description: "Python 3.12"
type: boolean
default: false
py3.13:
description: "Python 3.13"
type: boolean
default: false
py3.14:
description: "Python 3.14"
type: boolean
default: false

concurrency:
cancel-in-progress: false
group: manual-deploy

jobs:
package-args:
name: Package dispatch inputs
runs-on: ubuntu-latest
outputs:
os: ${{ steps.pack.outputs.os }}
python-versions: ${{ steps.pack.outputs.python-versions }}
steps:
- id: pack
env:
OS_WINDOWS_LATEST: ${{ inputs['os_windows-latest'] }}
OS_UBUNTU_LATEST: ${{ inputs['os_ubuntu-latest'] }}
OS_UBUNTU_ARM: ${{ inputs['os_ubuntu-24.04-arm'] }}
OS_MACOS_LATEST: ${{ inputs['os_macos-latest'] }}
OS_MACOS_14: ${{ inputs['os_macos-14'] }}
PY_310: ${{ inputs['py3.10'] }}
PY_311: ${{ inputs['py3.11'] }}
PY_312: ${{ inputs['py3.12'] }}
PY_313: ${{ inputs['py3.13'] }}
PY_314: ${{ inputs['py3.14'] }}
run: |
os_list=""
[[ "$OS_WINDOWS_LATEST" == "true" ]] && os_list="$os_list,windows-latest"
[[ "$OS_UBUNTU_LATEST" == "true" ]] && os_list="$os_list,ubuntu-latest"
[[ "$OS_UBUNTU_ARM" == "true" ]] && os_list="$os_list,ubuntu-24.04-arm"
[[ "$OS_MACOS_LATEST" == "true" ]] && os_list="$os_list,macos-latest"
[[ "$OS_MACOS_14" == "true" ]] && os_list="$os_list,macos-14"
os_list="${os_list#,}"

py_list=""
[[ "$PY_310" == "true" ]] && py_list="$py_list,3.10"
[[ "$PY_311" == "true" ]] && py_list="$py_list,3.11"
[[ "$PY_312" == "true" ]] && py_list="$py_list,3.12"
[[ "$PY_313" == "true" ]] && py_list="$py_list,3.13"
[[ "$PY_314" == "true" ]] && py_list="$py_list,3.14"
py_list="${py_list#,}"

if [[ -z "$os_list" ]]; then
echo "::error::Select at least one OS checkbox before dispatching."
exit 1
fi
if [[ -z "$py_list" ]]; then
echo "::error::Select at least one Python version checkbox before dispatching."
exit 1
fi

echo "os=$os_list" >> $GITHUB_OUTPUT
echo "python-versions=$py_list" >> $GITHUB_OUTPUT

deploy:
name: Build, test, and deploy
needs: package-args
uses: ./.github/workflows/wc-build.yml
permissions:
id-token: write
contents: read
with:
os: ${{ needs.package-args.outputs.os }}
python-versions: ${{ needs.package-args.outputs.python-versions }}
target: ${{ inputs.target }}
version-suffix: ${{ inputs['version-suffix'] }}
Loading
Loading