Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CI for unit tests, flake8, wheels/sdist. #2

Merged
merged 16 commits into from
May 30, 2024
35 changes: 35 additions & 0 deletions .github/actions/boost-cache/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Cache Boost
description: Caches Boost for an OS and a Boost minor version
inputs:
boost_minor:
required: true
os:
required: true
outputs:
cache-hit:
description: "Indicates if caching was successful"
value: ${{ steps.cache-boost.outputs.cache-hit }}
location:
description: "The path where Boost ends up"
value: "${{ github.workspace }}/boost"

runs:
using: "composite"
steps:
- name: Cache Boost
uses: actions/cache@v3
id: cache-boost
env:
cache-name: cache-boost
with:
path: ${{ github.workspace }}/boost
key: ${{ inputs.os }}-boost-${{ inputs.boost_minor }}

- name: Install Boost
if: steps.cache-boost.outputs.cache-hit != 'true'
shell: bash
run: |
wget -qO- https://boostorg.jfrog.io/artifactory/main/release/1.${{ inputs.boost_minor }}.0/source/boost_1_${{ inputs.boost_minor }}_0.tar.bz2 | tar xjf -
cd boost_1_${{ inputs.boost_minor }}_0
./bootstrap.sh
./b2 --prefix=../boost --with-serialization --with-filesystem --with-test install
14 changes: 14 additions & 0 deletions .github/actions/mpi-setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Set up MPI
description: Allows to use MPI in Github Actions by configuring oversubscription

runs:
using: "composite"
steps:
- name: Set up MPI for Github Actions
shell: bash
run: |
mkdir -p "$HOME/.openmpi"
cat <<EOF > "$HOME/.openmpi/mca-params.conf"
rmaps_base_oversubscribe = true
rmaps_default_mapping_policy = :oversubscribe
EOF
45 changes: 45 additions & 0 deletions .github/workflows/ctest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Run C++ tests

on:
workflow_call:

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: ["ubuntu-latest", "macos-14"]
boost_minor: [85]

steps:
- uses: actions/checkout@v3
with:
submodules: true

- name: Install Ubuntu system dependencies
if: startsWith(matrix.os, 'ubuntu-')
run: |
sudo apt-get update
sudo apt-get install ninja-build libopenmpi-dev

- name: Install MacOs system dependencies
if: startsWith(matrix.os, 'macos-')
run: |
brew install ninja openmpi

- uses: ./.github/actions/boost-cache
id: cache-boost
with:
os: ${{ matrix.os }}
boost_minor: ${{ matrix.boost_minor }}

- name: Configure and build
run: |
cmake -B build -G Ninja -DCMAKE_PREFIX_PATH=${{ steps.cache-boost.outputs.location }} .
cmake --build build

- uses: ./.github/actions/mpi-setup

- name: Run CTest
run: |
ctest --test-dir build --output-on-failure
39 changes: 39 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Run all tests

on:
push:
branches: ['main']
tags: ['v?[0-9]+.[0-9]+.[0-9]+']
pull_request:

jobs:
cache_boost:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: ["ubuntu-latest", "macos-14"]
boost_minor: [85]

steps:
- uses: actions/checkout@v4

- uses: ./.github/actions/boost-cache
id: cache-boost
with:
os: ${{ matrix.os }}
boost_minor: ${{ matrix.boost_minor }}

test_cxx:
uses: ./.github/workflows/ctest.yml
secrets: inherit
needs: [cache_boost]

test_python:
uses: ./.github/workflows/test.yml
secrets: inherit
needs: [cache_boost]

publish:
uses: ./.github/workflows/publish.yml
secrets: inherit
needs: [cache_boost]
142 changes: 142 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
name: Publish wheels and sdist tarball to PyPi

on:
workflow_call:

jobs:
build_sdist:
name: Build source distribution
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: true
fetch-depth: 0

- name: Set up Python 3.12
uses: actions/setup-python@v4
with:
python-version: 3.12

- name: Build a source tarball
run: |
python -m pip install build
python -m build -s

- name: Store sdist as artifact
uses: actions/upload-artifact@v3
with:
name: dist
path: dist/*.tar.gz

test_sdist:
name: Test source distribution

runs-on: ubuntu-latest
needs: [build_sdist]

steps:
- uses: actions/checkout@v3
with:
submodules: true

- name: Set up Python 3.12
uses: actions/setup-python@v4
with:
python-version: 3.12

- name: Download artifacts produced during the build_wheels and build_sdist jobs
uses: actions/download-artifact@v3
with:
name: dist
path: dist/

- uses: ./.github/actions/boost-cache
id: cache-boost
with:
os: ubuntu-latest
boost_minor: 85

- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y libopenmpi-dev

- uses: ./.github/actions/mpi-setup

- name: Install package, clean local directory
run: |
export CMAKE_PREFIX_PATH=${{ steps.cache-boost.outputs.location }}
export SKBUILD_CMAKE_DEFINE="CMAKE_INSTALL_RPATH_USE_LINK_PATH=ON"
python -m pip install dist/*
python -m pip install mock mpi4py pytest pytest-mpi pytest-xdist

- name: Run tests
run: |
pytest -n 3 tests

build_wheels:
name: Build wheels on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]

steps:
- uses: actions/checkout@v4
with:
submodules: true
fetch-depth: 0

# Used to host cibuildwheel
- uses: actions/setup-python@v5

- name: Install cibuildwheel
run: python -m pip install cibuildwheel==2.18.1

- name: Build wheels
run: python -m cibuildwheel --output-dir dist
env:
CIBW_TEST_COMMAND: "pytest {project}/tests"

- uses: actions/upload-artifact@v4
with:
name: cibw-wheels-${{ matrix.os }}-${{ strategy.job-index }}
path: ./dist/*.whl

publish:
name: Publish package to PyPI
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')

runs-on: ubuntu-latest
needs: [build_wheels, build_sdist, test_sdist]

environment:
name: publish_pypi
url: https://pypi.org/p/brain-indexer

permissions:
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing

steps:
- name: Download artifacts produced by the build_sdist job
uses: actions/download-artifact@v3
with:
name: dist
path: dist/

- name: Download artifacts produced by the build_wheels job
uses: actions/download-artifact@v3
with:
pattern: cibw-wheels-*
path: dist/
merge-multiple: true

- name: Display structure of downloaded files
run: ls -R
working-directory: dist

- name: Publish source distribution package to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages_dir: dist/
56 changes: 56 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Run Python tests and lint

on:
workflow_call:

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: ["ubuntu-latest", "macos-14"]
boost_minor: [85]
python-version: ['3.11', '3.12']
toxenv: ['py3']
include:
- os: 'ubuntu-latest'
python-version: '3.12'
toxenv: 'flake8'

steps:
- uses: actions/checkout@v3
with:
submodules: true

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

- name: Install Ubuntu system dependencies
if: startsWith(matrix.os, 'ubuntu-')
run: |
sudo apt-get update
sudo apt-get install libopenmpi-dev

- name: Install MacOs system dependencies
if: startsWith(matrix.os, 'macos-')
run: |
brew install openmpi

- uses: ./.github/actions/boost-cache
id: cache-boost
with:
os: ${{ matrix.os }}
boost_minor: ${{ matrix.boost_minor }}

- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
python -m pip install tox

- name: Test with tox
run: |
export CMAKE_PREFIX_PATH=${{ steps.cache-boost.outputs.location }}
export SKBUILD_CMAKE_DEFINE="CMAKE_INSTALL_RPATH_USE_LINK_PATH=ON"
tox -e ${{ matrix.toxenv }}
17 changes: 15 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "brain-indexer"
description = "A spatial index implementation for spheres, morphologies and synapses"
authors = [{ name="Blue Brain Project", email = "bbp-ou-hpc@epfl.ch" } ]
license = {text = "Blue Brain Project Licence"}
license = {"file" = "LICENSE.txt"}
# maintainer is the field chosen for docs `contributors`
maintainers = [{name="Fernando Pereira"}, {name="Antonio Bellotta"}, {name="Luc Dominic Grosheintz-Laval"}]
dynamic = ["version"]
Expand Down Expand Up @@ -68,14 +68,27 @@ SI_UNIT_TESTS="OFF"
[tool.setuptools_scm]

[tool.cibuildwheel]
skip = ["pp*", "*-win32", "*-manylinux_i686", "*-musllinux_i686", "*-musllinux_x86_64", "*-musllinux_aarch64"]
skip = ["cp3{6,7,8,9}-*", "pp*", "*-win32", "*-manylinux_i686", "*-musllinux_i686", "*-musllinux_x86_64", "*-musllinux_aarch64"]
test-requires = ["pytest", "pytest-mpi"]
test-command = ["python -m pytest {project}/tests"]

[tool.cibuildwheel.config-settings]
# for redistributable wheels, MPI support should not be enabled (until MPI settles on a standard ABI: https://github.com/mpi-forum/mpi-issues/issues/751)
"cmake.define.SI_MPI"="OFF"

[tool.cibuildwheel.linux]
before-all = """
yum install -y wget
wget -qO- https://boostorg.jfrog.io/artifactory/main/release/1.85.0/source/boost_1_85_0.tar.bz2 | tar xjf -
cd boost_1_85_0
./bootstrap.sh
./b2 --prefix=/opt/boost --with-serialization --with-filesystem --with-test install
"""

[tool.cibuildwheel.linux.environment]
CMAKE_PREFIX_PATH = "/opt/boost"
SKBUILD_CMAKE_DEFINE = "CMAKE_INSTALL_RPATH_USE_LINK_PATH=ON"

[tool.cibuildwheel.macos]
environment = { MACOSX_DEPLOYMENT_TARGET = "10.15" }

Expand Down
Loading
Loading