Skip to content

Wheels

Wheels #388

Workflow file for this run

name: Wheels
on:
workflow_dispatch:
schedule:
- cron: "0 4 * * *" # every day at 4am UTC
release:
types:
- published
env:
GEANT4_VERSION: 11.2.2
XERCES_VERSION: 3.2.5
CPP_STANDARD: 17
Geant4_DIR: ${{ github.workspace }}/geant4
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
jobs:
sdist:
name: Source distribution
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: 3.12
- name: Build sdist
run: |
python -m pip install build
python -m build --sdist .
- name: Upload sdist
uses: actions/upload-artifact@v4
with:
name: dist
path: dist/*.tar.gz
wheels:
name:
Build wheel for cp${{ matrix.python }} ${{ matrix.platform_id }} ${{
matrix.manylinux_image }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
python: 38
platform_id: manylinux_x86_64
manylinux_image: manylinux2014
- os: ubuntu-latest
python: 39
platform_id: manylinux_x86_64
manylinux_image: manylinux2014
- os: ubuntu-latest
python: 310
platform_id: manylinux_x86_64
manylinux_image: manylinux2014
- os: ubuntu-latest
python: 311
platform_id: manylinux_x86_64
manylinux_image: manylinux2014
- os: ubuntu-latest
python: 312
platform_id: manylinux_x86_64
manylinux_image: manylinux2014
- os: macos-latest
python: 38
platform_id: macosx_x86_64
- os: macos-latest
python: 39
platform_id: macosx_x86_64
- os: macos-latest
python: 310
platform_id: macosx_x86_64
- os: macos-latest
python: 311
platform_id: macosx_x86_64
- os: macos-latest
python: 312
platform_id: macosx_x86_64
- os: macos-latest
python: 38
platform_id: macosx_arm64
- os: macos-latest
python: 39
platform_id: macosx_arm64
- os: macos-latest
python: 310
platform_id: macosx_arm64
- os: macos-latest
python: 311
platform_id: macosx_arm64
- os: macos-latest
python: 312
platform_id: macosx_arm64
- os: windows-latest
python: 38
platform_id: win_amd64
- os: windows-latest
python: 39
platform_id: win_amd64
- os: windows-latest
python: 310
platform_id: win_amd64
- os: windows-latest
python: 311
platform_id: win_amd64
- os: windows-latest
python: 312
platform_id: win_amd64
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup CMake
uses: lukka/get-cmake@v3.30.3
- name: Setup Windows environment variables
if: matrix.os == 'windows-latest'
shell: bash
run: |
echo "CMAKE_ARGS=-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded" >> $GITHUB_ENV
- name: Setup MacOS environment variables
if: matrix.os == 'macos-latest'
run: |
echo "CMAKE_ARGS=-DCMAKE_OSX_ARCHITECTURES=${{ matrix.platform_id == 'macosx_x86_64' && 'x86_64' || 'arm64' }}" >> $GITHUB_ENV
- name: Cache Xerces-C Installation
if: matrix.os != 'ubuntu-latest'
id: cache-xerces
uses: actions/cache@v4
with:
path: ${{ github.workspace }}/xerces
key:
xerces-v${{ env.XERCES_VERSION }}-cpp${{ env.CPP_STANDARD }}-${{
matrix.platform_id }}
- name: Build and Install Xerces-C
if:
steps.cache-xerces.outputs.cache-hit != 'true' && matrix.os !=
'ubuntu-latest'
run: |
git clone https://github.com/apache/xerces-c.git xerces-source
git -C xerces-source checkout tags/v${{ env.XERCES_VERSION }}
cmake -B xerces-build -S xerces-source ${{ env.CMAKE_ARGS }} -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=${{ github.workspace }}/xerces -DCMAKE_CXX_STANDARD=${{ env.CPP_STANDARD }} -DBUILD_SHARED_LIBS=OFF ${{ matrix.os == 'windows-latest' && '-DCMAKE_CXX_FLAGS_RELEASE="/MT"' || '-G Ninja -DCMAKE_CXX_FLAGS=-fPIC -DCMAKE_C_FLAGS=-fPIC -Dnetwork-accessor=socket -Dtranscoder=iconv' }}
cmake --build xerces-build --parallel $(nproc) --config Release --target install
- name: Cache Geant4 Installation
if: matrix.os != 'ubuntu-latest'
id: cache-geant4
uses: actions/cache@v4
with:
path: ${{ env.Geant4_DIR }}
key:
geant4-v${{ env.GEANT4_VERSION }}-cpp${{ env.CPP_STANDARD }}-${{
matrix.platform_id }}
- name: Build and Install Geant4 (without datasets)
if:
steps.cache-geant4.outputs.cache-hit != 'true' && matrix.os !=
'ubuntu-latest'
run: |
git clone https://github.com/Geant4/geant4.git ${{ github.workspace }}/geant4-source --depth 1 --branch v${{ env.GEANT4_VERSION }}
cmake -B geant4-build -S geant4-source ${{ env.CMAKE_ARGS }} -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=${{ env.Geant4_DIR }} -DXERCESC_ROOT_DIR=${{ github.workspace }}/xerces -DCMAKE_CXX_STANDARD=${{ env.CPP_STANDARD }} -DGEANT4_USE_GDML=ON -DGEANT4_INSTALL_EXAMPLES=OFF -DGEANT4_INSTALL_DATA=OFF -DGEANT4_BUILD_TLS_MODEL=global-dynamic -DBUILD_STATIC_LIBS=ON -DBUILD_SHARED_LIBS=OFF ${{ matrix.os == 'windows-latest' && '-DCMAKE_CXX_FLAGS_RELEASE="/MT"' || '-G Ninja -DCMAKE_CXX_FLAGS=-fPIC -DCMAKE_C_FLAGS=-fPIC -DGEANT4_USE_SYSTEM_EXPAT=OFF' }}
cmake --build geant4-build --parallel $(nproc) --config Release --target install
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: 3.12
- name: Build wheel
uses: pypa/cibuildwheel@v2.21.2
env:
CIBW_TEST_COMMAND:
python -m pytest {project}/tests -vv --reruns 10 --reruns-delay 30
--only-rerun "(?i)http|timeout|connection|socket|resolve"
CIBW_ENVIRONMENT: >
SKLEARN_SKIP_NETWORK_TESTS=1 SKLEARN_BUILD_PARALLEL=3
CIBW_BUILD: cp${{ matrix.python }}-${{ matrix.platform_id }}
CIBW_ARCHS: all
CIBW_MANYLINUX_X86_64_IMAGE: ${{ matrix.manylinux_image }}
CIBW_MANYLINUX_I686_IMAGE: ${{ matrix.manylinux_image }}
CIBW_TEST_SKIP: "*-macosx_arm64" # test on arm64 is not supported yet
CIBW_BEFORE_ALL_LINUX: |
python3 -m pip install cmake ninja
git clone https://github.com/apache/xerces-c.git /tmp/xerces
git -C /tmp/xerces checkout tags/v${{ env.XERCES_VERSION }}
cmake -G Ninja -B /tmp/xerces/build -S /tmp/xerces -DCMAKE_CXX_STANDARD=${{ env.CPP_STANDARD }} -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -Dnetwork-accessor=socket -Dtranscoder=iconv -DCMAKE_CXX_FLAGS=-fPIC -DCMAKE_C_FLAGS=-fPIC
cmake --build /tmp/xerces/build --parallel $(nproc) --target install > /dev/null 2>&1
rm -rf /tmp/xerces
git clone https://github.com/Geant4/geant4.git /tmp/geant4 --branch=v${{ env.GEANT4_VERSION }} --depth=1
cmake -G Ninja -B /tmp/geant4/build -S /tmp/geant4 -DCMAKE_CXX_STANDARD=${{ env.CPP_STANDARD }} -DCMAKE_BUILD_TYPE=Release -DGEANT4_USE_GDML=ON -DGEANT4_INSTALL_EXAMPLES=OFF -DGEANT4_INSTALL_DATA=OFF -DGEANT4_BUILD_TLS_MODEL=global-dynamic -DCMAKE_CXX_FLAGS=-fPIC -DCMAKE_C_FLAGS=-fPIC -DGEANT4_USE_SYSTEM_EXPAT=OFF -DBUILD_STATIC_LIBS=ON -DBUILD_SHARED_LIBS=OFF
cmake --build /tmp/geant4/build --parallel $(nproc) --target install > /dev/null 2>&1
rm -rf /tmp/geant4
CIBW_ENVIRONMENT_MACOS: >
MACOSX_DEPLOYMENT_TARGET=11.0 ${{ matrix.platform_id ==
'macosx_arm64' && 'SKIP_PYBIND11_STUBGEN=1' || '' }}
- name: Upload wheel
uses: actions/upload-artifact@v4
with:
name: cibw-wheels-${{ matrix.os }}-${{ strategy.job-index }}
path: wheelhouse/*.whl
check-wheels-size:
name: Check wheels size
needs: wheels
runs-on: ubuntu-latest
steps:
- name: Download wheels
uses: actions/download-artifact@v4
with:
path: dist
merge-multiple: true
- name: Check wheel size
shell: bash
run: |
ls -lh dist
for file in dist/*.whl
do
size=$(du -m "$file" | cut -f1)
if [ "$size" -le 2 ]; then
echo "Error: $file is smaller than 2MB"
exit 1
else
echo "$file is larger than 2MB"
fi
done
upload-pypi:
name: Upload wheels to PyPI
needs: [sdist, wheels, check-wheels-size]
runs-on: ubuntu-latest
if: github.event_name == 'release' && github.event.action == 'published'
steps:
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: 3.12
- name: Download wheels
uses: actions/download-artifact@v4
with:
path: dist
merge-multiple: true
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@v1.10.2
with:
password: ${{ secrets.PYPI_API_TOKEN }}
publish-docker:
name: Publish Docker image
needs: [upload-pypi]
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- name: Log in to the GitHub Container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.CONTAINER_REGISTRY_GITHUB_TOKEN }}
- name: Build Docker image
uses: docker/build-push-action@v6
with:
context: .
push: false
tags: |
ghcr.io/lobis/geant4-python-application:latest
ghcr.io/lobis/geant4-python-application:${{ github.event.release.tag_name }}
labels: |
maintainer.name=Luis Antonio Obis Aparicio
maintainer.email=luis.antonio.obis@gmail.com
org.opencontainers.image.source=${{ github.repository }}
- name: Test image
run: |
docker run --rm ghcr.io/lobis/geant4-python-application:latest -c 'import geant4_python_application; app = geant4_python_application.Application()'
- name: Publish
run: |
docker push ghcr.io/lobis/geant4-python-application:latest