Skip to content

Commit

Permalink
feat: enable continuous deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
wu-vincent committed Nov 23, 2023
1 parent 6a947aa commit e80788d
Show file tree
Hide file tree
Showing 9 changed files with 141 additions and 111 deletions.
128 changes: 39 additions & 89 deletions .github/workflows/cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,117 +8,67 @@ on:
- '*'
workflow_dispatch:

permissions:
contents: write

jobs:
build:
build_wheels:
name: Build wheel for ${{ matrix.python }}-${{ matrix.machine.platform }} on ${{ matrix.machine.os }}
strategy:
fail-fast: false
matrix:
# this should be kept in sync with ci.yaml
python-version: ["3.8", "3.9", "3.10", "3.11"]
include:
- python-version: "3.8"
boost-version: "1.75.0"
platform-version: manylinux_2_27_x86_64
image-version: conanio/gcc7:latest
- python-version: "3.9"
boost-version: "1.75.0"
platform-version: manylinux_2_27_x86_64
image-version: conanio/gcc7:latest
- python-version: "3.10"
boost-version: "1.81.0"
platform-version: manylinux_2_31_x86_64
image-version: conanio/gcc10:latest
- python-version: "3.11"
boost-version: "1.81.0"
platform-version: manylinux_2_31_x86_64
image-version: conanio/gcc10:latest
runs-on: ubuntu-latest
machine:
- { os: 'windows-latest', platform: 'win_amd64' }
- { os: 'ubuntu-latest', platform: 'manylinux_x86_64' }
- { os: 'macos-latest', platform: 'macosx_x86_64' }
python: [ "cp39", "cp310", "cp311", "cp312" ]
runs-on: ${{ matrix.machine.os }}
steps:
- name: Setup docker buildx
id: buildx
uses: docker/setup-buildx-action@v2

- name: Create build container
uses: docker/build-push-action@v3
with:
builder: ${{ steps.buildx.outputs.name }}
file: .github/conan_dockerfile/Dockerfile
tags: lanelet2_conan_with_pip_wheel
load: true
target: lanelet2_conan_with_pip_wheel
build-args: |
FROM=${{ matrix.image-version }}
PY_VERSION=${{ matrix.python-version }}
PLATFORM=${{ matrix.platform-version }}
CONAN_ARGS=--require-override=boost/${{ matrix.boost-version }}
- name: Checkout Code
uses: actions/checkout@v4

- name: Create output directory
run: mkdir -p ${{ github.workspace }}/output
- name: Build wheels
uses: pypa/cibuildwheel@v2.16.2
env:
CIBW_BUILD: ${{ matrix.python }}-${{ matrix.machine.platform }}

- name: Package lanelet2 in build container
uses: addnab/docker-run-action@v3
with:
image: lanelet2_conan_with_pip_wheel
shell: bash
options: -v ${{ github.workspace }}/dist:/dist
run: |
set -e
# set env variables
export HOME=/home/conan
# copy wheel to dist directory
sudo cp -r $HOME/dist/* /dist
- name: Store wheel
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: dist
path: dist/
path: ./wheelhouse/*.whl

test:
needs: build
strategy:
matrix:
# test only on currently supported version
python-version: ["3.8", "3.9", "3.10", "3.11"]
os: ["ubuntu-22.04", "ubuntu-20.04"]
runs-on: ${{ matrix.os }}
build_sdist:
name: Build source distribution
runs-on: ubuntu-latest
steps:
- name: Restore wheel
uses: actions/download-artifact@v3
with:
name: dist
path: dist/
- name: Setup Python
uses: actions/setup-python@v4
- name: Checkout Code
uses: actions/checkout@v4

- name: Build sdist
run: pipx run build --sdist

- uses: actions/upload-artifact@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install wheel
# use dist/ directory as package source instead of pypi.org
run: pip install lanelet2 --no-index --find-links dist/
- name: Test wheel
run: python -c "import lanelet2; assert lanelet2.core.Point2d(0, 0, 0) is not None"
path: dist/*.tar.gz

publish:
name: Publish
if: contains(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
needs: [build, test]
needs: [ build_wheels, build_sdist ]
environment: pypi
permissions:
id-token: write
contents: write

steps:
- name: Restore wheel
- name: Restore artifacts
uses: actions/download-artifact@v3
with:
name: dist
path: dist/
name: artifact
path: dist

- name: Release
uses: softprops/action-gh-release@v1
with:
files: dist/*

- name: Publish package to PyPI
if: github.repository == 'fzi-forschungszentrum-informatik/Lanelet2'
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
uses: pypa/gh-action-pypi-publish@release/v1
2 changes: 0 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,6 @@ jobs:
conan profile detect --force
conan install . --output-folder=build --build=missing
- uses: ilammy/msvc-dev-cmd@v1 # NOTE: this is needed to use cl.exe with the Ninja generator on Windows

- name: Build with CMake on Windows
if: runner.os == 'Windows'
run: |
Expand Down
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ if (LANELET2_ENABLE_TESTING)
enable_testing()
endif ()

add_subdirectory(lanelet2_maps)
add_subdirectory(lanelet2_core)
add_subdirectory(lanelet2_io)
add_subdirectory(lanelet2_projection)
add_subdirectory(lanelet2_traffic_rules)
add_subdirectory(lanelet2_routing)
add_subdirectory(lanelet2_validation)
#add_subdirectory(lanelet2_examples)
add_subdirectory(lanelet2_python)
add_subdirectory(lanelet2_maps)
add_subdirectory(lanelet2_matching)
add_subdirectory(lanelet2_python)
#add_subdirectory(lanelet2_examples)
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
# Lanelet2

[![CI](https://github.com/fzi-forschungszentrum-informatik/lanelet2/actions/workflows/ci.yaml/badge.svg)](
https://github.com/wu-vincent/lanelet2/actions/workflows/ci.yaml)
[![CI](https://github.com/wu-vincent/lanelet2x/actions/workflows/ci.yaml/badge.svg)](
https://github.com/wu-vincent/lanelet2x/actions/workflows/ci.yaml)
[![CD](https://github.com/wu-vincent/lanelet2x/actions/workflows/cd.yaml/badge.svg)](
https://github.com/wu-vincent/lanelet2x/actions/workflows/cd.yaml)
[![PyPI - Version](https://img.shields.io/pypi/v/lanelet2x)](
https://pypi.org/project/lanelet2x)
[![PyPI - Downloads](https://img.shields.io/pypi/dm/lanelet2x)](
https://pypi.org/project/lanelet2x)
![PyPI - Python Version](
https://img.shields.io/pypi/pyversions/lanelet2x?logo=python&logoColor=white)

## Overview

Expand Down
28 changes: 28 additions & 0 deletions conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,34 @@ class Lanelet2Conan(ConanFile):
"boost/*:shared": True,
"boost/*:without_python": False,
}
without_boost_components = [
"chrono",
"container",
"context",
"contract",
"coroutine",
"date_time",
"exception",
"fiber",
"graph",
"iostreams",
"json",
"locale",
"log",
"math",
"mpi",
"nowide",
"random",
"regex",
"stacktrace",
"test",
"thread",
"timer",
"type_erasure",
"url",
"wave",
]
default_options.update((f"boost/*:without_{component}", True) for component in without_boost_components)

proj_list = [
"lanelet2_core",
Expand Down
1 change: 0 additions & 1 deletion lanelet2_matching/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ add_library(${PROJECT_NAME} SHARED ${PROJECT_SOURCE_FILES_SRC})
target_include_directories(${PROJECT_NAME} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")
target_link_libraries(${PROJECT_NAME} PUBLIC lanelet2_core lanelet2_io lanelet2_projection lanelet2_traffic_rules)


#############
## Install ##
#############
Expand Down
27 changes: 16 additions & 11 deletions lanelet2_python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,27 @@ project(lanelet2_python)
find_package(Boost REQUIRED COMPONENTS python)
find_package(Python REQUIRED COMPONENTS Interpreter Development.Module REQUIRED)

########################
##########################
## Build python modules ##
########################
##########################
set(PROJECT_PYTHON_TARGETS)
file(GLOB PROJECT_PYTHON_SOURCE_FILES_SRC "${CMAKE_CURRENT_SOURCE_DIR}/python_api/*.cpp")
foreach (PROJECT_PYTHON_SOURCE_FILE ${PROJECT_PYTHON_SOURCE_FILES_SRC})
get_filename_component(PYTHON_MODULE_NAME ${PROJECT_PYTHON_SOURCE_FILE} NAME_WE)
python_add_library(${PYTHON_MODULE_NAME} MODULE ${PROJECT_PYTHON_SOURCE_FILE} WITH_SOABI)
list(APPEND PROJECT_PYTHON_TARGETS ${PYTHON_MODULE_NAME})

target_compile_definitions(${PYTHON_MODULE_NAME} PRIVATE -DPYTHON_API_MODULE_NAME=${PYTHON_MODULE_NAME})
target_include_directories(${PYTHON_MODULE_NAME} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")
target_include_directories(${PYTHON_MODULE_NAME} PRIVATE ${Python3_INCLUDE_DIRS})
target_link_libraries(${PYTHON_MODULE_NAME} PUBLIC Boost::python lanelet2_core lanelet2_io lanelet2_projection lanelet2_traffic_rules lanelet2_routing lanelet2_matching)
list(APPEND PROJECT_PYTHON_TARGETS ${PYTHON_MODULE_NAME})

if (DEFINED SKBUILD AND NOT WIN32)
set_target_properties(${PYTHON_MODULE_NAME} PROPERTIES
BUILD_WITH_INSTALL_RPATH TRUE
INSTALL_RPATH_USE_LINK_PATH TRUE
INSTALL_RPATH "${CMAKE_SOURCE_DIR}/build/lib")
endif ()
endforeach ()

#############
Expand All @@ -29,15 +37,12 @@ endforeach ()
if (DEFINED SKBUILD)
install(TARGETS ${PROJECT_PYTHON_TARGETS} DESTINATION "lanelet2")
if (WIN32)
# Bundle runtime dlls with the wheel on windows
# Bundle shared library dependencies on Windows
foreach (PROJECT_PYTHON_TARGET ${PROJECT_PYTHON_TARGETS})
install(FILES "$<TARGET_RUNTIME_DLLS:${PROJECT_PYTHON_TARGET}>" DESTINATION "lanelet2/bin")
install(FILES "$<TARGET_RUNTIME_DLLS:${PROJECT_PYTHON_TARGET}>" DESTINATION "bin")
endforeach ()
else ()
# Save shared library dependencies to RPATH on Unix
install(TARGETS lanelet2_core lanelet2_io lanelet2_projection lanelet2_traffic_rules lanelet2_routing lanelet2_matching DESTINATION "${CMAKE_SOURCE_DIR}/build/lib")
endif ()
endif ()

#############
## Testing ##
#############
# Add test targets for cpp and python tests
# TODO:
2 changes: 1 addition & 1 deletion lanelet2_python/src/lanelet2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
bin_dir = None

try:
bin_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), "bin"))
bin_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "bin"))
try:
os.add_dll_directory(bin_dir)
except (Exception,):
Expand Down
46 changes: 44 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,60 @@ classifiers = [
"Operating System :: POSIX :: Linux",
]

[project.optional-dependencies]
pytest = ["pytest"]

[tool.scikit-build]
build-dir = "build/{wheel_tag}"
cmake.args = ["--preset conan-release"]
cmake.args = ["-G Ninja", "--preset conan-release"]
cmake.define = { LANELET2_ENABLE_TESTING = "OFF" }
cmake.build-type = "Release"
wheel.packages = ["lanelet2_python/src/lanelet2"]
wheel.license-files = ["LICENSE", "CODEOWNERS"]
logging.level = "DEBUG"
cmake.verbose = true

[tool.scikit-build.metadata.version]
provider = "scikit_build_core.metadata.regex"
input = "lanelet2_python/src/lanelet2/__init__.py"

[[tool.scikit-build.overrides]]
if.platform-system = "win32"
cmake.args = ["--preset conan-default"]
cmake.args = ["--preset conan-default"] # override for multi-configuration generator (i.e. MSVC) on Windows

[tool.cibuildwheel]
skip = ["*-win32", "*-musllinux_x86_64", "*_i686"]
test-requires = "pytest"
test-command = "pytest {project}/lanelet2_python/test"

[tool.cibuildwheel.windows]
before-build = [
"python -m pip install --upgrade pip",
"pip install -r requirements.txt",
"conan profile detect --force",
"conan install . --output-folder=build --build=*"
]

[tool.cibuildwheel.linux]
before-build = [
# here, we restore libpython*.a - otherwise conan will fail when adding boost::python
# see https://github.com/pypa/manylinux/blob/main/docker/build_scripts/finalize-python.sh
"pushd /opt/_internal",
"tar -xJf static-libs-for-embedding-only.tar.xz",
"popd",
"python -m pip install --upgrade pip",
"pip install -r requirements.txt",
"conan profile detect --force",
# we force the build of everything from source - prebuilt b2 does not work in manylinux
# also set the generator to use ninja because scikit-build-core will default to ninja
"conan install . --output-folder=build --build=* -c tools.cmake.cmaketoolchain:generator=Ninja"
]

[tool.cibuildwheel.macos]
before-build = [
"python -m pip install --upgrade pip",
"pip install -r requirements.txt",
"conan profile detect --force",
# set the generator to use ninja because scikit-build-core will default to ninja
"conan install . --output-folder=build --build=* -c tools.cmake.cmaketoolchain:generator=Ninja"
]

0 comments on commit e80788d

Please sign in to comment.