From 70a1552e5174b0078d6655fbc055994235bc5c09 Mon Sep 17 00:00:00 2001 From: Alexander Temerev Date: Tue, 6 Feb 2024 16:14:08 +0100 Subject: [PATCH] GH forkflow for building a wheel --- .github/workflows/publish_wheels.yml | 145 +++++++++++++++++++++++++++ 1 file changed, 145 insertions(+) create mode 100644 .github/workflows/publish_wheels.yml diff --git a/.github/workflows/publish_wheels.yml b/.github/workflows/publish_wheels.yml new file mode 100644 index 00000000..79072585 --- /dev/null +++ b/.github/workflows/publish_wheels.yml @@ -0,0 +1,145 @@ +name: Publish sdist and wheels for macos, and manylinux, publish to pypi if a release +on: [pull_request, push] + +env: + apt_options: -o Acquire::Retries=3 + + CIBW_BUILD_VERBOSITY: 3 + CIBW_BUILD: 'cp*' + CIBW_SKIP: 'cp35-* cp36-* cp37-* *-musllinux_* *-manylinux_i686' + CIBW_TEST_COMMAND: ( cd {project}/python/tests; python -m unittest -v ) + +jobs: + build_wheels: + name: Build wheels on ${{ matrix.os }} + + if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository + + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-22.04, macos-latest] + + steps: + - uses: actions/checkout@v3 + with: + submodules: 'true' + + - uses: actions/setup-python@v4 + name: Install Python + with: + python-version: '3.11' + + - name: Install cibuildwheel + run: | + python -m pip install cibuildwheel + + - name: Cache HDF5 On Linux/macOS + if: runner.os == 'Linux' || runner.os == 'macOS' + uses: actions/cache@v3 + id: cache-hdf5-posix + env: + cache-name: cache-hdf5-posix + with: + path: src-cache/ + key: ${{ runner.os }}-build-${{ env.cache-name }} + + + - name: Build wheels on Linux + if: runner.os == 'Linux' + run: | + # note: config is stored in pyproject.toml now + CIBW_MANYLINUX_X86_64_IMAGE=manylinux2014 python -m cibuildwheel --output-dir dist + CIBW_MANYLINUX_X86_64_IMAGE=manylinux_2_28 python -m cibuildwheel --output-dir dist + + - name: Build wheels Mac OS + if: runner.os == 'macOS' + + env: + CIBW_ENVIRONMENT_PASS: "HDF5_ROOT CMAKE_OSX_ARCHITECTURES MACOSX_DEPLOYMENT_TARGET" + CIBW_BEFORE_BUILD: | + # CMake complains if the dependencies come from within the same tree + # as the source, so we'll just pretend they are elsewhere + mkdir -p $PWD/src-cache + ln -s $PWD/src-cache /Users/runner/work/src-cache + bash ci/hdf5-build.sh /Users/runner/work/src-cache + UNIXY_AEC_VERSION: 1.0.4 + UNIXY_HDF5_VERSION: 1.14.2 + run: | + # x86_64 macOS allows for cross compilation; first we do arm64, + # only for the 11.0 target; and store in the cache the compiled code... + export CIBW_ARCHS_MACOS="arm64" + export CMAKE_OSX_ARCHITECTURES="arm64" + export MACOSX_DEPLOYMENT_TARGET="11.0" + export HDF5_ROOT=/Users/runner/work/src-cache/install-$CIBW_ARCHS_MACOS + python -m cibuildwheel --output-dir dist + + # ...and now we do both targets for x86_64 + export CIBW_ARCHS_MACOS="x86_64" + export CMAKE_OSX_ARCHITECTURES="x86_64" + unset MACOSX_DEPLOYMENT_TARGET + export HDF5_ROOT=/Users/runner/work/src-cache/install-$CIBW_ARCHS_MACOS + python -m cibuildwheel --output-dir dist + + - name: Store wheel as artifact + uses: actions/upload-artifact@v3 + with: + name: dist + path: dist/*.whl + + build_sdist: + name: Build sdist + if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository + + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + submodules: 'true' + + - name: Set up Python 3.11 + uses: actions/setup-python@v4 + with: + python-version: 3.11 + + - name: Install packages + run: | + sudo apt-get ${{env.apt_options}} update -y + sudo apt-get ${{env.apt_options}} install -y libhdf5-dev + pip install neuron + pip install libsonata + + - name: Build a source tarball, check it installs + run: + ./ci/python_build_sdist.sh + + - name: Store sdist as artifact + uses: actions/upload-artifact@v3 + with: + name: dist + path: dist/*.tar.gz + +# upload_artifacts: +# name: Upload wheels to PyPI +# if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') +# +# runs-on: ubuntu-latest +# needs: [build_wheels, build_sdist] +# +# steps: +# - name: Download artifacts produced during the build_wheels and build_sdist jobs +# uses: actions/download-artifact@v3 +# with: +# name: dist +# path: dist/ +# +# - name: Display structure of downloaded files +# run: ls -R +# working-directory: dist +# +# - name: Publish package to PyPI +# uses: pypa/gh-action-pypi-publish@master +# with: +# user: __token__ +# password: ${{ secrets.PYPI_PASSWORD }} +# packages_dir: dist/